mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 20:49:00 +08:00
📝 close #3410 common-test 单元测试模块 文档及代码更新
♻️ close #3394 【用户信息】扩展用户基本信息增加部分扩展字段 ♻️ close #3394 【用户信息】扩展用户基本信息增加部分扩展字段 ♻️ close #3394 【用户信息】扩展用户基本信息增加部分扩展字段
This commit is contained in:
1 parent
072bafe72a
commit
b9e5baaf4d
12 files changed
+169
-36
No files matched your search
+4
-1
@@ -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;
|
||||
|
||||
-- ----------------------------
|
||||
|
||||
+15
@@ -200,6 +200,21 @@ public interface SecurityConstants {
|
||||
*/
|
||||
String DETAILS_AVATAR = "avatar";
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
String NICKNAME = "nickname";
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
String NAME = "name";
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
String EMAIL = "email";
|
||||
|
||||
/**
|
||||
* 用户部门字段
|
||||
*/
|
||||
|
||||
+16
-3
@@ -45,6 +45,14 @@ import java.util.Optional;
|
||||
* @date 2019-03-07
|
||||
* <p>
|
||||
* 根据checktoken 的结果转化用户信息
|
||||
* <p>
|
||||
* 问题分析: 认证服务器check-token 返回的全部信息 资源服务器在根据返回信息组装用户信息的时候,只是用了username 如果设置了
|
||||
* userDetailsService 的实现则去调用 loadUserByUsername 再去查询一次用户信息
|
||||
* <p>
|
||||
* 造成问题现象 如果设置了userDetailsService 即可在spring security 上下文获取用户的全部信息,不设置则只能得到用户名。
|
||||
* 增加了一次查询逻辑,对性能产生不必要的影响
|
||||
* <p>
|
||||
* 解决问题 扩展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);
|
||||
Map<String, ?> map = MapUtil.get(responseMap, SecurityConstants.DETAILS_USER, Map.class);
|
||||
validateTenantId(map);
|
||||
String name = MapUtil.getStr(map, SecurityConstants.NAME);
|
||||
String email = MapUtil.getStr(map, SecurityConstants.EMAIL);
|
||||
String nickname = MapUtil.getStr(map, SecurityConstants.NICKNAME);
|
||||
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);
|
||||
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);
|
||||
PigxUser user = new PigxUser(nickname, name, email, id, deptId, phone, avatar, tenantId, username, N_A,
|
||||
true, true, true, true, authorities);
|
||||
return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
|
||||
}
|
||||
return null;
|
||||
@@ -111,7 +124,7 @@ public class PigxUserAuthenticationConverter implements UserAuthenticationConver
|
||||
log.warn("请求头中的租户ID({})和用户的租户ID({})不一致", headerValue, userValue);
|
||||
// TODO: 不要提示租户ID不对,可能被穷举
|
||||
throw new PigxAuth2Exception(PigxSecurityMessageSourceUtil.getAccessor().getMessage(
|
||||
"AbstractUserDetailsAuthenticationProvider.badTenantId", new Object[] { headerValue },
|
||||
"AbstractUserDetailsAuthenticationProvider.badTenantId", new Object[]{headerValue},
|
||||
"Bad tenant ID"));
|
||||
}
|
||||
}
|
||||
|
||||
+26
-2
@@ -65,13 +65,33 @@ public class PigxUser extends User {
|
||||
@Getter
|
||||
private Integer tenantId;
|
||||
|
||||
/**
|
||||
* 拓展字段:昵称
|
||||
*/
|
||||
@Getter
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 拓展字段:姓名
|
||||
*/
|
||||
@Getter
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 拓展字段:邮箱
|
||||
*/
|
||||
@Getter
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* Construct the <code>User</code> 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
|
||||
* <code>DaoAuthenticationProvider</code>
|
||||
* @param password the password that should be presented to the
|
||||
* <code>DaoAuthenticationProvider</code>
|
||||
@@ -86,7 +106,8 @@ public class PigxUser extends User {
|
||||
* a parameter or as an element in the <code>GrantedAuthority</code> 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;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
+18
@@ -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;
|
||||
|
||||
}
|
||||
+21
@@ -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;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
|
||||
@@ -137,4 +137,22 @@ public class UserVO implements Serializable {
|
||||
@ApiModelProperty(value = "拥有的角色列表")
|
||||
private List<SysRole> roleList;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ApiModelProperty(value = "昵称")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ApiModelProperty(value = "姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@ApiModelProperty(value = "邮箱")
|
||||
private String email;
|
||||
|
||||
}
|
||||
+6
@@ -172,6 +172,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
sysUser.setPhone(userDto.getPhone());
|
||||
sysUser.setUserId(userVO.getUserId());
|
||||
sysUser.setAvatar(userDto.getAvatar());
|
||||
sysUser.setNickname(userDto.getNickname());
|
||||
sysUser.setName(userDto.getName());
|
||||
sysUser.setEmail(userDto.getEmail());
|
||||
return R.ok(this.updateById(sysUser));
|
||||
}
|
||||
|
||||
@@ -307,6 +310,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
UserDTO userDTO = new UserDTO();
|
||||
userDTO.setUsername(excel.getUsername());
|
||||
userDTO.setPhone(excel.getPhone());
|
||||
userDTO.setNickname(excel.getNickname());
|
||||
userDTO.setName(excel.getName());
|
||||
userDTO.setEmail(excel.getEmail());
|
||||
// 批量导入初始密码为手机号
|
||||
userDTO.setPassword(userDTO.getPhone());
|
||||
// 根据部门名称查询部门ID
|
||||
|
||||
Binary file not shown.
@@ -37,6 +37,9 @@
|
||||
<result column="dept_id" property="deptId"/>
|
||||
<result column="tenant_id" property="tenantId"/>
|
||||
<result column="dept_name" property="deptName"/>
|
||||
<result column="nickname" property="nickname"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="email" property="email"/>
|
||||
<collection property="roleList" ofType="com.pig4cloud.pigx.admin.api.entity.SysRole"
|
||||
select="com.pig4cloud.pigx.admin.mapper.SysRoleMapper.listRolesByUserId" column="user_id">
|
||||
</collection>
|
||||
@@ -93,7 +96,10 @@
|
||||
</sql>
|
||||
|
||||
<sql id="userRoleDeptSql">
|
||||
u.user_id,
|
||||
u
|
||||
.
|
||||
user_id
|
||||
,
|
||||
u.username,
|
||||
u.password,
|
||||
u.salt,
|
||||
@@ -114,29 +120,29 @@
|
||||
r.update_time rupdate_time,
|
||||
d.name dept_name,
|
||||
d.dept_id
|
||||
</sql>
|
||||
</sql>
|
||||
|
||||
<select id="getUserVoByUsername" resultMap="userVoResultMap">
|
||||
SELECT
|
||||
<include refid="userRoleSql"/>
|
||||
<include refid="userRoleSql"/>
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_user_role ur ON ur.user_id = u.user_id
|
||||
LEFT JOIN sys_role r ON r.role_id = ur.role_id
|
||||
WHERE u.username = #{username}
|
||||
sys_user u
|
||||
LEFT JOIN sys_user_role ur ON ur.user_id = u.user_id
|
||||
LEFT JOIN sys_role r ON r.role_id = ur.role_id
|
||||
WHERE u.username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="getUserVoById" resultMap="userVoResultMap">
|
||||
SELECT
|
||||
<include refid="userRoleDeptSql"/>
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_user_role ur ON ur.user_id = u.user_id
|
||||
LEFT JOIN sys_role r ON r.role_id = ur.role_id
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
WHERE
|
||||
u.user_id = #{id}
|
||||
</select>
|
||||
SELECT
|
||||
<include refid="userRoleDeptSql"/>
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_user_role ur ON ur.user_id = u.user_id
|
||||
LEFT JOIN sys_role r ON r.role_id = ur.role_id
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
WHERE
|
||||
u.user_id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getUserVosPage" resultMap="baseResultMap">
|
||||
SELECT
|
||||
@@ -149,15 +155,18 @@
|
||||
u.wx_openid,
|
||||
u.qq_openid,
|
||||
u.dept_id,
|
||||
u.create_time ucreate_time,
|
||||
u.update_time uupdate_time,
|
||||
u.create_time ucreate_time,
|
||||
u.update_time uupdate_time,
|
||||
u.del_flag,
|
||||
u.lock_flag,
|
||||
u.tenant_id,
|
||||
d.name dept_name
|
||||
u.nickname,
|
||||
u.name,
|
||||
u.email,
|
||||
d.name dept_name
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
sys_user u
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
<where>
|
||||
u.del_flag = '0'
|
||||
<if test="query.username != null and query.username != ''">
|
||||
@@ -181,15 +190,18 @@
|
||||
u.wx_openid,
|
||||
u.qq_openid,
|
||||
u.dept_id,
|
||||
u.create_time ucreate_time,
|
||||
u.update_time uupdate_time,
|
||||
u.create_time ucreate_time,
|
||||
u.update_time uupdate_time,
|
||||
u.del_flag,
|
||||
u.lock_flag,
|
||||
u.tenant_id,
|
||||
d.name dept_name
|
||||
u.nickname,
|
||||
u.name,
|
||||
u.email,
|
||||
d.name dept_name
|
||||
FROM
|
||||
sys_user u
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
sys_user u
|
||||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
<where>
|
||||
u.del_flag = '0'
|
||||
<if test="query.username != null and query.username != ''">
|
||||
|
||||
Reference in new issue
Block a user