diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java index f9d307532..f8abe6dbe 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java @@ -117,7 +117,9 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService { boolean enabled = StrUtil.equals(user.getLockFlag(), CommonConstants.STATUS_NORMAL); // 构造security用户 - return new PigxUser(user.getUserId(), user.getDeptId(), user.getTenantId(), user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled, - true, true, !CommonConstants.STATUS_LOCK.equals(user.getLockFlag()), authorities); + return new PigxUser(user.getUserId(), user.getDeptId(), user.getPhone(), user.getAvatar(), user.getTenantId() + , user.getUsername(), SecurityConstants.BCRYPT + user.getPassword() + , enabled, true, true + , !CommonConstants.STATUS_LOCK.equals(user.getLockFlag()), authorities); } } diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java index c0adb3867..4c72a9eb2 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -152,22 +152,36 @@ public interface SecurityConstants { /** * 用户ID字段 */ - String DETAILS_USER_ID = "user_id"; + String DETAILS_USER_ID = "id"; /** - * 用户名字段 + * 用户名 */ String DETAILS_USERNAME = "username"; + /** + * 用户基本信息 + */ + String DETAILS_USER = "user_info"; + + /** + * 用户名phone + */ + String DETAILS_PHONE = "phone"; + + /** + * 头像 + */ + String DETAILS_AVATAR = "avatar"; /** * 用户部门字段 */ - String DETAILS_DEPT_ID = "dept_id"; + String DETAILS_DEPT_ID = "deptId"; /** * 租户ID 字段 */ - String DETAILS_TENANT_ID = "tenant_id"; + String DETAILS_TENANT_ID = "tenantId"; /** * 协议字段 diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenEnhancer.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenEnhancer.java index a6f50acf1..c23931c4b 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenEnhancer.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxTokenEnhancer.java @@ -51,10 +51,7 @@ public class PigxTokenEnhancer implements TokenEnhancer { final Map additionalInfo = new HashMap<>(8); PigxUser pigxUser = (PigxUser) authentication.getUserAuthentication().getPrincipal(); - additionalInfo.put(SecurityConstants.DETAILS_USER_ID, pigxUser.getId()); - additionalInfo.put(SecurityConstants.DETAILS_USERNAME, pigxUser.getUsername()); - additionalInfo.put(SecurityConstants.DETAILS_DEPT_ID, pigxUser.getDeptId()); - additionalInfo.put(SecurityConstants.DETAILS_TENANT_ID, pigxUser.getTenantId()); + additionalInfo.put(SecurityConstants.DETAILS_USER, pigxUser); additionalInfo.put(SecurityConstants.DETAILS_LICENSE, SecurityConstants.PIGX_LICENSE); additionalInfo.put(SecurityConstants.ACTIVE, Boolean.TRUE); ((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo); diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java index 382512cf6..96f0de22e 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/component/PigxUserAuthenticationConverter.java @@ -69,19 +69,22 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver /** * Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an Authentication from a map. * - * @param map a map of user information + * @param responseMap a map of user information * @return an Authentication representing the user or null if there is none */ @Override - public Authentication extractAuthentication(Map map) { - if (map.containsKey(USERNAME)) { + public Authentication extractAuthentication(Map responseMap) { + if (responseMap.containsKey(USERNAME)) { + Collection authorities = getAuthorities(responseMap); + Map map = MapUtil.get(responseMap, SecurityConstants.DETAILS_USER, Map.class); validateTenantId(map); - Collection authorities = getAuthorities(map); - String username = MapUtil.getStr(map, USERNAME); + String username = MapUtil.getStr(map, SecurityConstants.DETAILS_USERNAME); Integer id = MapUtil.getInt(map, SecurityConstants.DETAILS_USER_ID); Integer deptId = MapUtil.getInt(map, SecurityConstants.DETAILS_DEPT_ID); Integer tenantId = MapUtil.getInt(map, SecurityConstants.DETAILS_TENANT_ID); - PigxUser user = new PigxUser(id, deptId, tenantId, username, N_A, true + String phone = MapUtil.getStr(map, SecurityConstants.DETAILS_PHONE); + String avatar = MapUtil.getStr(map, SecurityConstants.DETAILS_AVATAR); + PigxUser user = new PigxUser(id, deptId, phone, avatar, tenantId, username, N_A, true , true, true, true, authorities); return new UsernamePasswordAuthenticationToken(user, N_A, authorities); } diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java index cae1f7f50..c23546035 100644 --- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java +++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUser.java @@ -41,12 +41,25 @@ public class PigxUser extends User { @Getter private Integer deptId; + /** + * 手机号 + */ + @Getter + private String phone; + + /** + * 头像 + */ + @Getter + private String avatar; + /** * 租户ID */ @Getter private Integer tenantId; + /** * Construct the User with the details required by * {@link DaoAuthenticationProvider}. @@ -68,10 +81,12 @@ public class PigxUser extends User { * @throws IllegalArgumentException if a null value was passed either as * a parameter or as an element in the GrantedAuthority collection */ - public PigxUser(Integer id, Integer deptId, Integer tenantId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { + public PigxUser(Integer id, Integer deptId, String phone, String avatar, Integer tenantId, String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection authorities) { super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities); this.id = id; this.deptId = deptId; + this.phone = phone; + this.avatar = avatar; this.tenantId = tenantId; } } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysUserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysUserController.java index 52e8c32a5..5bcb769cf 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysUserController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysUserController.java @@ -28,7 +28,6 @@ import com.pig4cloud.pigx.admin.service.SysUserService; import com.pig4cloud.pigx.common.core.util.R; import com.pig4cloud.pigx.common.log.annotation.SysLog; import com.pig4cloud.pigx.common.security.annotation.Inner; -import com.pig4cloud.pigx.common.security.util.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; @@ -49,22 +48,6 @@ import javax.validation.Valid; public class SysUserController { private final SysUserService userService; - /** - * 获取当前用户全部信息 - * - * @return 用户信息 - */ - @GetMapping(value = {"/info"}) - public R info() { - String username = SecurityUtils.getUser().getUsername(); - SysUser user = userService.getOne(Wrappers.query() - .lambda().eq(SysUser::getUsername, username)); - if (user == null) { - return R.failed(null, "获取当前用户信息失败"); - } - return R.ok(userService.findUserInfo(user)); - } - /** * 获取指定用户全部信息 *