From bd6bde7aa385fee6b82124fce5b46473936a0737 Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 7 Apr 2020 22:22:33 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20token=E5=A2=9E=E5=8A=A0postId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/auth/service/BladeUserDetails.java | 7 ++++++- .../auth/service/BladeUserDetailsServiceImpl.java | 2 +- .../springblade/auth/support/BladeJwtTokenEnhancer.java | 1 + .../main/java/org/springblade/auth/utils/TokenUtil.java | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java index 55bba92b..c5107c31 100644 --- a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java +++ b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetails.java @@ -54,6 +54,10 @@ public class BladeUserDetails extends User { * 部门id */ private String deptId; + /** + * 岗位id + */ + private String postId; /** * 角色id */ @@ -67,7 +71,7 @@ public class BladeUserDetails extends User { */ private String avatar; - 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 authorities) { + public BladeUserDetails(Long userId, String tenantId, String name, String realName, String deptId, String postId, String roleId, String roleName, String avatar, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); this.userId = userId; this.tenantId = tenantId; @@ -75,6 +79,7 @@ public class BladeUserDetails extends User { this.realName = realName; this.account = username; this.deptId = deptId; + this.postId = postId; this.roleId = roleId; this.roleName = roleName; this.avatar = avatar; diff --git a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java index 797c9dd5..02e47804 100644 --- a/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java +++ b/blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java @@ -98,7 +98,7 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService { throw new UserDeniedAuthorizationException(TokenUtil.USER_HAS_NO_ROLE); } return new BladeUserDetails(user.getId(), - user.getTenantId(), user.getName(), user.getRealName(), 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.getPostId(),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 { diff --git a/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java b/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java index 2eaa88ff..0ab8b4a8 100644 --- a/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java +++ b/blade-auth/src/main/java/org/springblade/auth/support/BladeJwtTokenEnhancer.java @@ -40,6 +40,7 @@ public class BladeJwtTokenEnhancer implements TokenEnhancer { info.put(TokenUtil.CLIENT_ID, TokenUtil.getClientIdFromHeader()); info.put(TokenUtil.USER_ID, Func.toStr(principal.getUserId())); info.put(TokenUtil.DEPT_ID, Func.toStr(principal.getDeptId())); + info.put(TokenUtil.POST_ID, Func.toStr(principal.getPostId())); info.put(TokenUtil.ROLE_ID, Func.toStr(principal.getRoleId())); info.put(TokenUtil.TENANT_ID, principal.getTenantId()); info.put(TokenUtil.ACCOUNT, principal.getAccount()); diff --git a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java index c53541fc..b9a89340 100644 --- a/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java +++ b/blade-auth/src/main/java/org/springblade/auth/utils/TokenUtil.java @@ -43,6 +43,7 @@ public class TokenUtil { 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 POST_ID = TokenConstant.POST_ID; public final static String ROLE_ID = TokenConstant.ROLE_ID; public final static String ROLE_NAME = TokenConstant.ROLE_NAME; public final static String TENANT_ID = TokenConstant.TENANT_ID;