初始化用户时增加数据源管理权,给用户授权后改为无需重新登录即可拥有新的权限
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
import com.zyplayer.doc.data.config.security.UserAuthVo;
|
||||
import com.zyplayer.doc.data.config.security.UserAuthInfo;
|
||||
import com.zyplayer.doc.data.repository.manage.entity.UserInfo;
|
||||
import com.zyplayer.doc.data.service.manage.UserAuthService;
|
||||
import com.zyplayer.doc.data.service.manage.UserInfoService;
|
||||
@@ -73,7 +73,7 @@ public class LoginController {
|
||||
return DocResponseJson.warn("用户名或密码错误");
|
||||
}
|
||||
}
|
||||
List<UserAuthVo> userAuthSet = userAuthService.getUserAuthSet(userInfo.getId());
|
||||
List<UserAuthInfo> userAuthSet = userAuthService.getUserAuthSet(userInfo.getId());
|
||||
String accessToken = IdUtil.simpleUUID();
|
||||
DocUserDetails userDetails = new DocUserDetails(userInfo.getId(), userInfo.getUserName(), userInfo.getPassword(), true, userAuthSet);
|
||||
DocUserUtil.setCurrentUser(accessToken, userDetails);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
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.entity.UserInfo;
|
||||
@@ -227,26 +228,22 @@ public class UserInfoController {
|
||||
authIdsList = Arrays.stream(authIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
|
||||
}
|
||||
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||
|
||||
UserAuth userAuthUp = new UserAuth();
|
||||
userAuthUp.setDelFlag(1);
|
||||
userAuthUp.setUpdateTime(new Date());
|
||||
userAuthUp.setUpdateUid(currentUser.getUserId());
|
||||
QueryWrapper<UserAuth> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("user_id", userIdsList);
|
||||
userAuthService.update(userAuthUp, queryWrapper);
|
||||
|
||||
userAuthService.remove(queryWrapper);
|
||||
List<UserAuth> createList = new LinkedList<>();
|
||||
for (int i = 0; i < userIdsList.size(); i++) {
|
||||
for (int j = 0; j < authIdsList.size(); j++) {
|
||||
for (Long userId : userIdsList) {
|
||||
for (Long authId : authIdsList) {
|
||||
UserAuth userAuth = new UserAuth();
|
||||
userAuth.setUserId(userIdsList.get(i));
|
||||
userAuth.setAuthId(authIdsList.get(j));
|
||||
userAuth.setUserId(userId);
|
||||
userAuth.setAuthId(authId);
|
||||
userAuth.setCreateUid(currentUser.getUserId());
|
||||
userAuth.setCreationTime(new Date());
|
||||
userAuth.setDelFlag(0);
|
||||
createList.add(userAuth);
|
||||
}
|
||||
List<UserAuthInfo> userAuthListNew = userAuthService.getUserAuthSet(userId);
|
||||
DocUserUtil.setUserAuth(userId, userAuthListNew);
|
||||
}
|
||||
userAuthService.saveBatch(createList);
|
||||
return DocResponseJson.ok();
|
||||
|
||||
@@ -421,16 +421,16 @@ VALUES (1, 'AUTH_ASSIGN', '权限分配权', 0, 1, '2018-12-01 11:40:42', 1),
|
||||
(8, 'WIKI_PAGE_FILE_DELETE_', '删除wiki文档附件', 0, 1, '2019-06-04 13:01:20', 0),
|
||||
(9, 'WIKI_PAGE_AUTH_MANAGE_', 'wiki权限管理', 0, 1, '2019-06-04 13:01:20', 0),
|
||||
(10, 'DB_DATASOURCE_MANAGE', 'DB数据源管理权', 0, 1, '2019-06-29 13:01:20', 1),
|
||||
(11, 'ES_DATASOURCE_MANAGE', 'ES数据源管理权', 0, 1, '2019-07-27 00:39:20', 1),
|
||||
(12, 'DB_VIEW_', '数据源查看权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(13, 'DB_SELECT_', '数据源查询权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(14, 'DB_UPDATE_', '数据源增删改查权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(15, 'DB_DESC_EDIT_', '表字段注释修改权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(16, 'DB_PROC_EDIT_', '存储过程修改权', 0, 1, '2021-04-24 23:25:17', 0),
|
||||
(17, 'API_DOC_MANAGE', 'api文档管理权', 0, 1, '2021-12-12 23:25:17', 0),
|
||||
(18, 'API_DOC_DEVELOPER', 'api文档编辑权', 0, 1, '2021-12-12 23:25:17', 0);
|
||||
(11, 'DB_VIEW_', '数据源查看权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(12, 'DB_SELECT_', '数据源查询权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(13, 'DB_UPDATE_', '数据源增删改查权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(14, 'DB_DESC_EDIT_', '表字段注释修改权', 0, 1, '2019-08-18 23:25:17', 0),
|
||||
(15, 'DB_PROC_EDIT_', '存储过程修改权', 0, 1, '2021-04-24 23:25:17', 0),
|
||||
(16, 'API_DOC_MANAGE', 'api文档管理权', 0, 1, '2021-12-12 23:25:17', 0),
|
||||
(17, 'API_DOC_DEVELOPER', 'api文档编辑权', 0, 1, '2021-12-12 23:25:17', 0);
|
||||
-- 用户权限
|
||||
INSERT INTO `user_auth` (id, user_id, auth_id, create_uid, update_uid, del_flag, creation_time)
|
||||
VALUES (1, 1, 1, 1, 1, 0, '2018-12-01 11:37:39'),
|
||||
(2, 1, 2, 1, 1, 0, '2018-12-01 11:37:39');
|
||||
(2, 1, 2, 1, 1, 0, '2018-12-01 11:37:39'),
|
||||
(2, 1, 10, 1, 1, 0, '2018-12-01 11:37:39');
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.zyplayer.doc.core.json.DocResponseJson;
|
||||
import com.zyplayer.doc.core.json.ResponseJson;
|
||||
import com.zyplayer.doc.data.config.security.DocUserDetails;
|
||||
import com.zyplayer.doc.data.config.security.DocUserUtil;
|
||||
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.entity.UserInfo;
|
||||
@@ -126,7 +126,7 @@ public class WikiPageAuthController {
|
||||
userMessage.setAffectUserName(userInfo.getUserName());
|
||||
userMessageService.addWikiMessage(userMessage);
|
||||
// 刷新用户权限
|
||||
List<UserAuthVo> userAuthListNew = userAuthService.getUserAuthSet(authVo.getUserId());
|
||||
List<UserAuthInfo> userAuthListNew = userAuthService.getUserAuthSet(authVo.getUserId());
|
||||
DocUserUtil.setUserAuth(authVo.getUserId(), userAuthListNew);
|
||||
}
|
||||
return DocResponseJson.ok();
|
||||
|
||||
Reference in New Issue
Block a user