初始化用户时增加数据源管理权,给用户授权后改为无需重新登录即可拥有新的权限

This commit is contained in:
暮光:城中城
2023-02-13 20:27:53 +08:00
parent 1ae0e92c10
commit f8efca5ee0
9 changed files with 33 additions and 40 deletions

View File

@@ -16,7 +16,7 @@ public class DocUserDetails {
private String username;
private String password;
private boolean enabled;
private List<UserAuthVo> userAuthList;
private List<UserAuthInfo> userAuthList;
public DocUserDetails(Long userId, String username) {
this.userId = userId;
@@ -31,7 +31,7 @@ public class DocUserDetails {
this.enabled = enabled;
}
public DocUserDetails(Long userId, String username, String password, boolean enabled, List<UserAuthVo> userAuthList) {
public DocUserDetails(Long userId, String username, String password, boolean enabled, List<UserAuthInfo> userAuthList) {
super();
this.userId = userId;
this.username = username;

View File

@@ -40,7 +40,7 @@ public class DocUserUtil {
if (currentUser == null) {
return false;
}
Set<String> authCodeSet = currentUser.getUserAuthList().stream().map(UserAuthVo::getAuthCode).collect(Collectors.toSet());
Set<String> authCodeSet = currentUser.getUserAuthList().stream().map(UserAuthInfo::getAuthCode).collect(Collectors.toSet());
for (String authName : authNames) {
if (!authCodeSet.contains(authName)) {
return false;
@@ -77,7 +77,7 @@ public class DocUserUtil {
/**
* 设置当前用户权限
*/
public static void setUserAuth(Long userId, List<UserAuthVo> userAuthList) {
public static void setUserAuth(Long userId, List<UserAuthInfo> userAuthList) {
String userToken = CacheUtil.get(CachePrefix.LOGIN_USER_ID_TOKEN + userId);
if (userToken != null) {
DocUserDetails docUser = CacheUtil.get(userToken);

View File

@@ -18,11 +18,11 @@ import java.io.Serializable;
*/
@Data
@NoArgsConstructor
public class UserAuthVo implements Serializable {
public class UserAuthInfo implements Serializable {
private static final long serialVersionUID = 1L;
public UserAuthVo(UserAuth userAuth) {
public UserAuthInfo(UserAuth userAuth) {
this.authId = userAuth.getAuthId();
this.sysType = userAuth.getSysType();
this.sysModuleType = userAuth.getSysModuleType();

View File

@@ -1,7 +1,7 @@
package com.zyplayer.doc.data.service.manage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zyplayer.doc.data.config.security.UserAuthVo;
import com.zyplayer.doc.data.config.security.UserAuthInfo;
import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
import java.util.List;
@@ -16,7 +16,7 @@ import java.util.List;
*/
public interface UserAuthService extends IService<UserAuth> {
List<UserAuthVo> getUserAuthSet(Long userId);
List<UserAuthInfo> getUserAuthSet(Long userId);
List<UserAuth> getModuleAuthList(Integer sysType, Integer sysModuleType, Long sysModuleId);

View File

@@ -2,14 +2,10 @@ package com.zyplayer.doc.data.service.manage.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyplayer.doc.core.exception.ConfirmException;
import com.zyplayer.doc.data.config.security.UserAuthVo;
import com.zyplayer.doc.data.config.security.UserAuthInfo;
import com.zyplayer.doc.data.repository.manage.entity.AuthInfo;
import com.zyplayer.doc.data.repository.manage.entity.UserAuth;
import com.zyplayer.doc.data.repository.manage.mapper.UserAuthMapper;
import com.zyplayer.doc.data.repository.support.consts.DocAuthConst;
import com.zyplayer.doc.data.repository.support.consts.DocSysModuleType;
import com.zyplayer.doc.data.repository.support.consts.DocSysType;
import com.zyplayer.doc.data.service.manage.AuthInfoService;
import com.zyplayer.doc.data.service.manage.UserAuthService;
import org.apache.commons.collections.CollectionUtils;
@@ -34,7 +30,7 @@ public class UserAuthServiceImpl extends ServiceImpl<UserAuthMapper, UserAuth> i
AuthInfoService authInfoService;
@Override
public List<UserAuthVo> getUserAuthSet(Long userId) {
public List<UserAuthInfo> getUserAuthSet(Long userId) {
QueryWrapper<UserAuth> authWrapper = new QueryWrapper<>();
authWrapper.eq("user_id", userId).eq("del_flag", "0");
List<UserAuth> userAuthList = this.list(authWrapper);
@@ -45,8 +41,8 @@ public class UserAuthServiceImpl extends ServiceImpl<UserAuthMapper, UserAuth> i
Collection<AuthInfo> authInfoList = authInfoService.listByIds(authIdList);
Map<Long, String> authNameMap = authInfoList.stream().collect(Collectors.toMap(AuthInfo::getId, AuthInfo::getAuthName));
// 组装
List<UserAuthVo> userAuthVoList = userAuthList.stream().map(UserAuthVo::new).collect(Collectors.toList());
for (UserAuthVo userAuthVo : userAuthVoList) {
List<UserAuthInfo> userAuthVoList = userAuthList.stream().map(UserAuthInfo::new).collect(Collectors.toList());
for (UserAuthInfo userAuthVo : userAuthVoList) {
userAuthVo.setAuthCode(authNameMap.get(userAuthVo.getAuthId()));
}
return userAuthVoList;