Browse Source

token增加realName

test
smallchill 6 years ago
parent
commit
042cb364e7
  1. 7
      blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java
  2. 5
      blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java
  3. 1
      blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java
  4. 3
      blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java

7
blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java

@ -42,6 +42,10 @@ public class BladeUserDetails extends User {
* 昵称
*/
private String name;
/**
* 真名
*/
private String realName;
/**
* 账号
*/
@ -63,11 +67,12 @@ public class BladeUserDetails extends User {
*/
private String avatar;
public BladeUserDetails(Long userId, String tenantId, String name, String deptId, String roleId, String roleName, String avatar, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
public BladeUserDetails(Long userId, String tenantId, String name, String realName, String deptId, String roleId, String roleName, String avatar, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
this.userId = userId;
this.tenantId = tenantId;
this.name = name;
this.realName = realName;
this.account = username;
this.deptId = deptId;
this.roleId = roleId;

5
blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java

@ -28,7 +28,6 @@ import org.springblade.system.user.entity.User;
import org.springblade.system.user.entity.UserInfo;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException;
@ -49,7 +48,7 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService {
@Override
@SneakyThrows
public UserDetails loadUserByUsername(String username) {
public BladeUserDetails loadUserByUsername(String username) {
HttpServletRequest request = WebUtil.getRequest();
// 获取租户
String tenantId = Func.toStr(request.getHeader(TokenUtil.TENANT_HEADER_KEY), TokenUtil.DEFAULT_TENANT_ID);
@ -78,7 +77,7 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService {
throw new UsernameNotFoundException(TokenUtil.USER_NOT_FOUND);
}
return new BladeUserDetails(user.getId(),
user.getTenantId(), user.getName(), user.getDeptId(), user.getRoleId(), Func.join(result.getData().getRoles()), Func.toStr(user.getAvatar(), TokenUtil.DEFAULT_AVATAR),
user.getTenantId(), user.getName(), user.getRealName(), user.getDeptId(), user.getRoleId(), Func.join(result.getData().getRoles()), Func.toStr(user.getAvatar(), TokenUtil.DEFAULT_AVATAR),
username, AuthConstant.ENCRYPT + user.getPassword(), true, true, true, true,
AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles())));
} else {

1
blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java

@ -45,6 +45,7 @@ public class BladeJwtTokenEnhancer implements TokenEnhancer {
info.put(TokenUtil.ACCOUNT, principal.getAccount());
info.put(TokenUtil.USER_NAME, principal.getUsername());
info.put(TokenUtil.NICK_NAME, principal.getName());
info.put(TokenUtil.REAL_NAME, principal.getRealName());
info.put(TokenUtil.ROLE_NAME, principal.getRoleName());
info.put(TokenUtil.AVATAR, principal.getAvatar());
info.put(TokenUtil.LICENSE, TokenUtil.LICENSE_NAME);

3
blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java

@ -38,6 +38,7 @@ public class TokenUtil {
public final static String ACCOUNT = TokenConstant.ACCOUNT;
public final static String USER_NAME = TokenConstant.USER_NAME;
public final static String NICK_NAME = TokenConstant.NICK_NAME;
public final static String REAL_NAME = TokenConstant.REAL_NAME;
public final static String USER_ID = TokenConstant.USER_ID;
public final static String DEPT_ID = TokenConstant.DEPT_ID;
public final static String ROLE_ID = TokenConstant.ROLE_ID;
@ -56,7 +57,7 @@ public class TokenUtil {
public final static String USER_HAS_NO_ROLE = "未获得用户的角色信息";
public final static String HEADER_KEY = "Authorization";
public final static String HEADER_PREFIX = "Basic ";
public final static String DEFAULT_AVATAR = "https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png";
public final static String DEFAULT_AVATAR = "";
/**
* 解码

Loading…
Cancel
Save