use of com.hccake.ballcat.system.model.vo.SysUserInfo in project ballcat by ballcat-projects.
the class CustomTokenEnhancer method enhance.
/**
* 处理 token 增强
* @param accessToken token信息
* @param authentication 鉴权信息
* @return OAuth2AccessToken 增强后的token
*/
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
Authentication userAuthentication = authentication.getUserAuthentication();
if (userAuthentication == null) {
return accessToken;
}
Object principal = userAuthentication.getPrincipal();
if (principal instanceof User) {
User user = (User) principal;
// token 附属信息
Map<String, Object> additionalInfo = new HashMap<>(8);
// 用户基本信息
SysUserInfo sysUserInfo = getSysUserInfo(user);
additionalInfo.put(TokenAttributeNameConstants.INFO, sysUserInfo);
// 默认在登陆时只把角色和权限的信息返回
Map<String, Object> resultAttributes = new HashMap<>(2);
Map<String, Object> attributes = user.getAttributes();
resultAttributes.put(UserAttributeNameConstants.ROLE_CODES, attributes.get(UserAttributeNameConstants.ROLE_CODES));
resultAttributes.put(UserAttributeNameConstants.PERMISSIONS, attributes.get(UserAttributeNameConstants.PERMISSIONS));
additionalInfo.put(TokenAttributeNameConstants.ATTRIBUTES, resultAttributes);
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
}
return accessToken;
}
use of com.hccake.ballcat.system.model.vo.SysUserInfo in project ballcat by ballcat-projects.
the class SysUserController method getSysUserInfo.
/**
* 获取指定用户的基本信息
* @param userId 用户ID
* @return SysUserInfo
*/
@GetMapping("/{userId}")
@PreAuthorize("@per.hasPermission('system:user:read')")
@Operation(summary = "获取指定用户的基本信息")
public R<SysUserInfo> getSysUserInfo(@PathVariable("userId") Integer userId) {
SysUser sysUser = sysUserService.getById(userId);
if (sysUser == null) {
return R.ok();
}
SysUserInfo sysUserInfo = SysUserConverter.INSTANCE.poToInfo(sysUser);
return R.ok(sysUserInfo);
}
use of com.hccake.ballcat.system.model.vo.SysUserInfo in project ballcat by ballcat-projects.
the class CustomTokenEnhancer method getSysUserInfo.
/**
* 根据 User 对象获取 SysUserInfo
* @param user User
* @return SysUserInfo
*/
public SysUserInfo getSysUserInfo(User user) {
SysUserInfo sysUserInfo = new SysUserInfo();
sysUserInfo.setUserId(user.getUserId());
sysUserInfo.setUsername(user.getUsername());
sysUserInfo.setNickname(user.getNickname());
sysUserInfo.setAvatar(user.getAvatar());
sysUserInfo.setOrganizationId(user.getOrganizationId());
sysUserInfo.setType(user.getType());
return sysUserInfo;
}
Aggregations