use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.
the class SysUserDetailsServiceImpl method getUserDetailsByUserInfo.
/**
* 根据UserInfo 获取 UserDetails
* @param userInfoDTO 用户信息DTO
* @return UserDetails
*/
public UserDetails getUserDetailsByUserInfo(UserInfoDTO userInfoDTO) {
SysUser sysUser = userInfoDTO.getSysUser();
Collection<String> roleCodes = userInfoDTO.getRoleCodes();
Collection<String> permissions = userInfoDTO.getPermissions();
Collection<String> dbAuthsSet = new HashSet<>();
if (CollectionUtil.isNotEmpty(roleCodes)) {
// 获取角色
dbAuthsSet.addAll(roleCodes);
// 获取资源
dbAuthsSet.addAll(permissions);
}
Collection<? extends GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(dbAuthsSet.toArray(new String[0]));
// 默认将角色和权限放入属性中
HashMap<String, Object> attributes = new HashMap<>(8);
attributes.put(UserAttributeNameConstants.ROLE_CODES, roleCodes);
attributes.put(UserAttributeNameConstants.PERMISSIONS, permissions);
// 用户额外属性
userInfoCoordinator.coordinateAttribute(userInfoDTO, attributes);
return new User(sysUser.getUserId(), sysUser.getUsername(), sysUser.getPassword(), sysUser.getNickname(), sysUser.getAvatar(), sysUser.getStatus(), sysUser.getOrganizationId(), sysUser.getType(), authorities, attributes);
}
use of com.hccake.ballcat.system.model.entity.SysUser in project ballcat by ballcat-projects.
the class SysUserDetailsServiceImpl method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
SysUser sysUser = sysUserService.getByUsername(username);
if (sysUser == null) {
log.error("登陆:用户名错误,用户名:{}", username);
throw new UsernameNotFoundException("username error!");
}
UserInfoDTO userInfoDTO = sysUserService.findUserInfo(sysUser);
return getUserDetailsByUserInfo(userInfoDTO);
}
Aggregations