diff --git a/db/2pigxx.sql b/db/2pigxx.sql index 997fac1b7..b1a8b70b8 100644 --- a/db/2pigxx.sql +++ b/db/2pigxx.sql @@ -764,6 +764,9 @@ CREATE TABLE `sys_user` ( `gitee_login` varchar(100) DEFAULT NULL COMMENT '码云 标识', `osc_id` varchar(100) DEFAULT NULL COMMENT '开源中国 标识', `tenant_id` int(11) NOT NULL DEFAULT '0' COMMENT '所属租户', + `nickname` varchar(255) DEFAULT NULL COMMENT '拓展字段:昵称', + `name` varchar(64) DEFAULT NULL COMMENT '拓展字段:姓名', + `email` varchar(255) DEFAULT NULL COMMENT '拓展字段:邮箱', PRIMARY KEY (`user_id`) USING BTREE, KEY `user_wx_openid` (`wx_openid`) USING BTREE, KEY `user_qq_openid` (`qq_openid`) USING BTREE, @@ -774,7 +777,7 @@ CREATE TABLE `sys_user` ( -- Records of sys_user -- ---------------------------- BEGIN; -INSERT INTO `sys_user` VALUES (1, 'admin', '$2a$10$IVzj1Wd.ZQdOIWdb1htQjexU94uoNeuk1crlQ9ExVupPi0Iy1uv.C', '', '17034642888', '/admin/sys-file/lengleng/c5a85e0770cd4fe78bc14b63b3bd05ae.jpg', 1, '2018-04-20 07:15:18', '2019-11-02 22:12:11', '0', '0', 'o_0FT0uyg_H1vVy2H0JpSwlVGhWQ', 'oBxPy5E-v82xWGsfzZVzkD3wEX64', NULL, 'log4j', '2303656', 1); +INSERT INTO `sys_user` VALUES (1, 'admin', '$2a$10$IVzj1Wd.ZQdOIWdb1htQjexU94uoNeuk1crlQ9ExVupPi0Iy1uv.C', '', '17034642888', '/admin/sys-file/lengleng/c5a85e0770cd4fe78bc14b63b3bd05ae.jpg', 1, '2018-04-20 07:15:18', '2019-11-02 22:12:11', '0', '0', 'o_0FT0uyg_H1vVy2H0JpSwlVGhWQ', 'oBxPy5E-v82xWGsfzZVzkD3wEX64', NULL, 'log4j', '2303656', 1,NULL,NULL,NULL); COMMIT; -- ---------------------------- 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 fe01e2683..05bff8d71 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 @@ -200,6 +200,21 @@ public interface SecurityConstants { */ String DETAILS_AVATAR = "avatar"; + /** + * 昵称 + */ + String NICKNAME = "nickname"; + + /** + * 姓名 + */ + String NAME = "name"; + + /** + * 邮箱 + */ + String EMAIL = "email"; + /** * 用户部门字段 */ 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 4bbbb7018..4a7a9e9e7 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 @@ -45,6 +45,14 @@ import java.util.Optional; * @date 2019-03-07 *
* 根据checktoken 的结果转化用户信息 + *
+ * 问题分析: 认证服务器check-token 返回的全部信息 资源服务器在根据返回信息组装用户信息的时候,只是用了username 如果设置了 + * userDetailsService 的实现则去调用 loadUserByUsername 再去查询一次用户信息 + *
+ * 造成问题现象 如果设置了userDetailsService 即可在spring security 上下文获取用户的全部信息,不设置则只能得到用户名。 + * 增加了一次查询逻辑,对性能产生不必要的影响 + *
+ * 解决问题 扩展UserAuthenticationConverter 的解析过程,把认证服务器返回的信息全部组装到spring security的上下文对象中
*/
@Slf4j
public class PigxUserAuthenticationConverter implements UserAuthenticationConverter {
@@ -54,6 +62,7 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
/**
* Extract information about the user to be used in an access token (i.e. for resource
* servers).
+ *
* @param authentication an authentication representing a user
* @return a map of key values representing the unique information about the user
*/
@@ -70,6 +79,7 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
/**
* Inverse of {@link #convertUserAuthentication(Authentication)}. Extracts an
* Authentication from a map.
+ *
* @param responseMap a map of user information
* @return an Authentication representing the user or null if there is none
*/
@@ -79,14 +89,17 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
Collection extends GrantedAuthority> authorities = getAuthorities(responseMap);
MapUser with the details required by
* {@link DaoAuthenticationProvider}.
* @param id 用户ID
* @param deptId 部门ID
* @param tenantId 租户ID
- * @param username the username presented to the
+ * @param nickname 昵称
+ * @param name 姓名
+ * @param email 邮箱 the username presented to the
* DaoAuthenticationProvider
* @param password the password that should be presented to the
* DaoAuthenticationProvider
@@ -86,7 +106,8 @@ public class PigxUser extends User {
* a parameter or as an element in the GrantedAuthority collection
*/
@JsonCreator
- public PigxUser(@JsonProperty("id") Integer id, @JsonProperty("deptId") Integer deptId,
+ public PigxUser(@JsonProperty("nickname") String nickname, @JsonProperty("name") String name,
+ @JsonProperty("email") String email, @JsonProperty("id") Integer id, @JsonProperty("deptId") Integer deptId,
@JsonProperty("phone") String phone, @JsonProperty("avatar") String avatar,
@JsonProperty("tenantId") Integer tenantId, @JsonProperty("username") String username,
@JsonProperty("password") String password, @JsonProperty("enabled") boolean enabled,
@@ -100,6 +121,9 @@ public class PigxUser extends User {
this.phone = phone;
this.avatar = avatar;
this.tenantId = tenantId;
+ this.nickname = nickname;
+ this.name = name;
+ this.email = email;
}
}
diff --git a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java
index 44c417a91..fedcb2b79 100644
--- a/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java
+++ b/pigx-common/pigx-common-security/src/main/java/com/pig4cloud/pigx/common/security/service/PigxUserDetailsServiceImpl.java
@@ -113,8 +113,9 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService {
boolean enabled = StrUtil.equals(user.getLockFlag(), CommonConstants.STATUS_NORMAL);
// 构造security用户
- return new PigxUser(user.getUserId(), user.getDeptId(), user.getPhone(), user.getAvatar(), user.getTenantId(),
- user.getUsername(), SecurityConstants.BCRYPT + user.getPassword(), enabled, true, true,
+ return new PigxUser(user.getNickname(), user.getName(), user.getEmail(), 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-test/src/main/java/com/pig4cloud/pigx/test/kit/OAuthKit.java b/pigx-common/pigx-common-test/src/main/java/com/pig4cloud/pigx/test/kit/OAuthKit.java
index ada75a05a..e39879987 100644
--- a/pigx-common/pigx-common-test/src/main/java/com/pig4cloud/pigx/test/kit/OAuthKit.java
+++ b/pigx-common/pigx-common-test/src/main/java/com/pig4cloud/pigx/test/kit/OAuthKit.java
@@ -3,6 +3,7 @@ package com.pig4cloud.pigx.test.kit;
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
import org.springframework.http.HttpHeaders;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
+import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
/**
@@ -21,7 +22,8 @@ public class OAuthKit {
return mockRequest -> {
OAuth2ClientContext clientContext = SpringContextHolder.getBean(OAuth2ClientContext.class);
String token = clientContext.getAccessToken().getValue();
- mockRequest.addHeader(HttpHeaders.AUTHORIZATION, String.format("Bearer: %s", token));
+ mockRequest.addHeader(HttpHeaders.AUTHORIZATION,
+ String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, token));
return mockRequest;
};
}
diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java
index 6b1f32c17..7353649b5 100644
--- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java
+++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysUser.java
@@ -149,4 +149,22 @@ public class SysUser implements Serializable {
@ApiModelProperty(value = "开源中国唯一标识")
private String oscId;
+ /**
+ * 昵称
+ */
+ @ApiModelProperty(value = "昵称")
+ private String nickname;
+
+ /**
+ * 姓名
+ */
+ @ApiModelProperty(value = "姓名")
+ private String name;
+
+ /**
+ * 邮箱
+ */
+ @ApiModelProperty(value = "邮箱")
+ private String email;
+
}
diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserExcelVO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserExcelVO.java
index 11970fbe0..dcbe2421c 100644
--- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserExcelVO.java
+++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserExcelVO.java
@@ -40,6 +40,27 @@ public class UserExcelVO implements Serializable {
@ExcelProperty("手机号")
private String phone;
+ /**
+ * 手机号
+ */
+ @NotBlank(message = "昵称不能为空")
+ @ExcelProperty("昵称")
+ private String nickname;
+
+ /**
+ * 手机号
+ */
+ @NotBlank(message = "姓名不能为空")
+ @ExcelProperty("姓名")
+ private String name;
+
+ /**
+ * 手机号
+ */
+ @NotBlank(message = "邮箱不能为空")
+ @ExcelProperty("邮箱")
+ private String email;
+
/**
* 部门名称
*/
diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java
index 5215d3b51..771597691 100644
--- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java
+++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/vo/UserVO.java
@@ -137,4 +137,22 @@ public class UserVO implements Serializable {
@ApiModelProperty(value = "拥有的角色列表")
private List