use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.
the class ShiroRealm method doGetAuthorizationInfo.
/**
* 权限认证,为当前登录的Subject授予角色和权限(角色的权限信息集合)
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
// 权限信息对象info,用来存放查出的用户的所有的角色(role)及权限(permission)
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
Long userId = (Long) SecurityUtils.getSubject().getPrincipal();
// 赋予角色
List<Role> roleList = roleService.listRolesByUserId(userId);
if (null != roleList) {
for (Role role : roleList) {
info.addRole(role.getName());
}
}
// 赋予权限
List<Resources> resourcesList = null;
User user = userService.getByPrimaryKey(userId);
if (null == user) {
return info;
}
// ROOT用户默认拥有所有权限
if (UserTypeEnum.ROOT.toString().equalsIgnoreCase(user.getUserType())) {
resourcesList = resourcesService.listAll();
} else {
resourcesList = resourcesService.listByUserId(userId);
}
if (!CollectionUtils.isEmpty(resourcesList)) {
Set<String> permissionSet = new HashSet<>();
for (Resources resources : resourcesList) {
String permission = null;
if (!StringUtils.isEmpty(permission = resources.getPermission())) {
permissionSet.addAll(Arrays.asList(permission.trim().split(",")));
}
}
info.setStringPermissions(permissionSet);
}
return info;
}
use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.
the class ShiroRealm method doGetAuthenticationInfo.
/**
* 提供账户信息返回认证信息(用户的角色信息集合)
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// 获取用户的输入的账号.
String username = (String) token.getPrincipal();
User user = userService.getByUserName(username);
if (user == null) {
throw new UnknownAccountException("账号不存在!");
}
if (user.getStatus() != null && UserStatusEnum.DISABLE.getCode().equals(user.getStatus())) {
throw new LockedAccountException("帐号已被锁定,禁止登录!");
}
// principal参数使用用户Id,方便动态刷新用户权限
return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), ByteSource.Util.bytes(username), getName());
}
use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.
the class RestUserController method add.
@RequiresPermissions("user:add")
@PostMapping(value = "/add")
@BussinessLog("添加用户")
public ResponseVO add(User user) {
User u = userService.getByUserName(user.getUsername());
if (u != null) {
return ResultUtil.error("该用户名[" + user.getUsername() + "]已存在!请更改用户名");
}
try {
user.setPassword(PasswordUtil.encrypt(user.getPassword(), user.getUsername()));
userService.insert(user);
return ResultUtil.success("成功");
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error("error");
}
}
use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.
the class SysUserServiceImpl method getByUserName.
/**
* 根据用户名查找
*
* @param userName
* @return
*/
@Override
public User getByUserName(String userName) {
User user = new User(userName, null);
SysUser sysUser = this.sysUserMapper.selectOne(user.getSysUser());
return null == sysUser ? null : new User(sysUser);
}
use of com.zyd.blog.business.entity.User in project OneBlog by zhangyd-c.
the class SysUserServiceImpl method findPageBreakByCondition.
@Override
public PageInfo<User> findPageBreakByCondition(UserConditionVO vo) {
PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
List<SysUser> sysUsers = sysUserMapper.findPageBreakByCondition(vo);
if (CollectionUtils.isEmpty(sysUsers)) {
return null;
}
List<User> users = new ArrayList<>();
for (SysUser su : sysUsers) {
users.add(new User(su));
}
PageInfo bean = new PageInfo<SysUser>(sysUsers);
bean.setList(users);
return bean;
}
Aggregations