refactor: 获取用户认证凭证优化
This commit is contained in:
@@ -7,7 +7,7 @@ import com.youlai.boot.system.model.entity.User;
|
||||
import com.youlai.boot.system.model.query.UserPageQuery;
|
||||
import com.youlai.boot.system.model.form.UserForm;
|
||||
import com.youlai.boot.common.annotation.DataPermission;
|
||||
import com.youlai.boot.system.model.dto.UserAuthInfo;
|
||||
import com.youlai.boot.core.security.model.AuthCredentials;
|
||||
import com.youlai.boot.system.model.dto.UserExportDTO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@@ -46,7 +46,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* @param username 用户名
|
||||
* @return 认证信息
|
||||
*/
|
||||
UserAuthInfo getUserAuthInfo(String username);
|
||||
AuthCredentials getAuthCredentialsByUsername(String username);
|
||||
|
||||
/**
|
||||
* 根据微信openid获取用户认证信息
|
||||
@@ -54,7 +54,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* @param openid 微信openid
|
||||
* @return 认证信息
|
||||
*/
|
||||
UserAuthInfo getUserAuthInfoByOpenId(String openid);
|
||||
AuthCredentials getAuthCredentialsByOpenId(String openid);
|
||||
|
||||
/**
|
||||
* 根据手机号获取用户认证信息
|
||||
@@ -62,7 +62,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* @param mobile 手机号
|
||||
* @return 认证信息
|
||||
*/
|
||||
UserAuthInfo getUserAuthInfoByMobile(String mobile);
|
||||
AuthCredentials getAuthCredentialsByMobile(String mobile);
|
||||
|
||||
/**
|
||||
* 获取导出用户列表
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.youlai.boot.system.model.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户认证信息
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2022/10/22
|
||||
*/
|
||||
@Data
|
||||
public class UserAuthInfo {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 状态(1:启用;0:禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 用户所属的角色集合
|
||||
*/
|
||||
private Set<String> roles;
|
||||
|
||||
/**
|
||||
* 数据权限范围,用于控制用户可以访问的数据级别
|
||||
*
|
||||
* @see com.youlai.boot.common.enums.DataScopeEnum
|
||||
*/
|
||||
private Integer dataScope;
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.youlai.boot.system.service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.boot.common.model.Option;
|
||||
import com.youlai.boot.system.model.dto.UserAuthInfo;
|
||||
import com.youlai.boot.core.security.model.AuthCredentials;
|
||||
import com.youlai.boot.system.model.dto.UserExportDTO;
|
||||
import com.youlai.boot.system.model.entity.User;
|
||||
import com.youlai.boot.system.model.query.UserPageQuery;
|
||||
@@ -69,10 +69,10 @@ public interface UserService extends IService<User> {
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return {@link UserAuthInfo}
|
||||
* @return {@link AuthCredentials}
|
||||
*/
|
||||
|
||||
UserAuthInfo getUserAuthInfo(String username);
|
||||
AuthCredentials getAuthCredentialsByUsername(String username);
|
||||
|
||||
|
||||
/**
|
||||
@@ -166,10 +166,10 @@ public interface UserService extends IService<User> {
|
||||
* 根据 openid 获取用户认证信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return {@link UserAuthInfo}
|
||||
* @return {@link AuthCredentials}
|
||||
*/
|
||||
|
||||
UserAuthInfo getUserAuthInfoByOpenId(String username);
|
||||
AuthCredentials getAuthCredentialsByOpenId(String username);
|
||||
|
||||
/**
|
||||
* 根据微信 OpenID 注册或绑定用户
|
||||
@@ -182,9 +182,9 @@ public interface UserService extends IService<User> {
|
||||
* 根据手机号获取用户认证信息
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @return {@link UserAuthInfo}
|
||||
* @return {@link AuthCredentials}
|
||||
*/
|
||||
UserAuthInfo getUserAuthInfoByMobile(String mobile);
|
||||
AuthCredentials getAuthCredentialsByMobile(String mobile);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.youlai.boot.system.converter.UserConverter;
|
||||
import com.youlai.boot.system.enums.DictCodeEnum;
|
||||
import com.youlai.boot.system.mapper.UserMapper;
|
||||
import com.youlai.boot.system.model.bo.UserBO;
|
||||
import com.youlai.boot.system.model.dto.UserAuthInfo;
|
||||
import com.youlai.boot.core.security.model.AuthCredentials;
|
||||
import com.youlai.boot.system.model.dto.UserExportDTO;
|
||||
import com.youlai.boot.system.model.entity.DictItem;
|
||||
import com.youlai.boot.system.model.entity.User;
|
||||
@@ -192,54 +192,54 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
* 根据用户名获取认证信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户认证信息 {@link UserAuthInfo}
|
||||
* @return 用户认证信息 {@link AuthCredentials}
|
||||
*/
|
||||
@Override
|
||||
public UserAuthInfo getUserAuthInfo(String username) {
|
||||
UserAuthInfo userAuthInfo = this.baseMapper.getUserAuthInfo(username);
|
||||
if (userAuthInfo != null) {
|
||||
Set<String> roles = userAuthInfo.getRoles();
|
||||
public AuthCredentials getAuthCredentialsByUsername(String username) {
|
||||
AuthCredentials authCredentials = this.baseMapper.getAuthCredentialsByUsername(username);
|
||||
if (authCredentials != null) {
|
||||
Set<String> roles = authCredentials.getRoles();
|
||||
// 获取最大范围的数据权限
|
||||
Integer dataScope = roleService.getMaximumDataScope(roles);
|
||||
userAuthInfo.setDataScope(dataScope);
|
||||
authCredentials.setDataScope(dataScope);
|
||||
}
|
||||
return userAuthInfo;
|
||||
return authCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 openid 获取用户认证信息
|
||||
*
|
||||
* @param openid 微信
|
||||
* @return {@link UserAuthInfo}
|
||||
* @return {@link AuthCredentials}
|
||||
*/
|
||||
@Override
|
||||
public UserAuthInfo getUserAuthInfoByOpenId(String openid) {
|
||||
UserAuthInfo userAuthInfo = this.baseMapper.getUserAuthInfoByOpenId(openid);
|
||||
if (userAuthInfo != null) {
|
||||
Set<String> roles = userAuthInfo.getRoles();
|
||||
public AuthCredentials getAuthCredentialsByOpenId(String openid) {
|
||||
AuthCredentials authCredentials = this.baseMapper.getAuthCredentialsByOpenId(openid);
|
||||
if (authCredentials != null) {
|
||||
Set<String> roles = authCredentials.getRoles();
|
||||
// 获取最大范围的数据权限
|
||||
Integer dataScope = roleService.getMaximumDataScope(roles);
|
||||
userAuthInfo.setDataScope(dataScope);
|
||||
authCredentials.setDataScope(dataScope);
|
||||
}
|
||||
return userAuthInfo;
|
||||
return authCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据手机号获取用户认证信息
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @return {@link UserAuthInfo}
|
||||
* @return {@link AuthCredentials}
|
||||
*/
|
||||
@Override
|
||||
public UserAuthInfo getUserAuthInfoByMobile(String mobile) {
|
||||
UserAuthInfo userAuthInfo = this.baseMapper.getUserAuthInfoByMobile(mobile);
|
||||
if (userAuthInfo != null) {
|
||||
Set<String> roles = userAuthInfo.getRoles();
|
||||
public AuthCredentials getAuthCredentialsByMobile(String mobile) {
|
||||
AuthCredentials authCredentials = this.baseMapper.getAuthCredentialsByMobile(mobile);
|
||||
if (authCredentials != null) {
|
||||
Set<String> roles = authCredentials.getRoles();
|
||||
// 获取最大范围的数据权限
|
||||
Integer dataScope = roleService.getMaximumDataScope(roles);
|
||||
userAuthInfo.setDataScope(dataScope);
|
||||
authCredentials.setDataScope(dataScope);
|
||||
}
|
||||
return userAuthInfo;
|
||||
return authCredentials;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user