| | |
| | | import javax.annotation.Resource; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 处理 shiro认证,授权,和数据库交互 |
| | |
| | | |
| | | public User findPasswordAndSlatByUserName(String userName) { |
| | | QueryWrapper<User> queryWrapper = Wrappers.query(); |
| | | queryWrapper.select("id","name","password","salt").eq("name",userName); |
| | | try{ |
| | | return userMapper.selectOne(queryWrapper); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return new User(0,"用户不存在"); |
| | | queryWrapper.select("id", "name", "password", "salt","role_id").eq("name", userName); |
| | | User user = userMapper.selectOne(queryWrapper); |
| | | if (user == null) { |
| | | return new User(0, "用户不存在"); |
| | | } |
| | | return user; |
| | | } |
| | | |
| | | /** |
| | | * TODO 采用caffeineCache重写 |
| | | * |
| | | * @param user |
| | | * @return |
| | | */ |
| | |
| | | System.out.println("=========执行了UserBridgeService.getAuthorization方法=========="); |
| | | SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo(); |
| | | //添加Roles和Permissions |
| | | //本项目主要使用permissions |
| | | List<String> roles = findRolesByUserId(user.getId()); |
| | | List<String> perms = findPermissionsByUserId(user.getId()); |
| | | |
| | |
| | | } |
| | | |
| | | private List<String> findPermissionsByUserId(int userId) { |
| | | List<String> perms = rolePermissionMapper.findPermissionsByUserId(userId); |
| | | List<Permission> permissionList = rolePermissionMapper.getPermissionListByUserId(userId); |
| | | List<String> perms = permissionList.stream().map(Permission::getValue).collect(Collectors.toList()); |
| | | return perms; |
| | | } |
| | | |
| | | private List<String> findRolesByUserId(int userId) { |
| | | List<String> roles =userRoleMapper.findRolesByUserId(userId); |
| | | List<String> roles = userRoleMapper.findRolesByUserId(userId); |
| | | //roles.add("dev"); |
| | | return roles; |
| | | } |