diff --git a/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java b/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java index 322b787b2a4fc3017a7a902840e50b10b880659e..adaa8190043ca0f3e9b20cfba7ef1650ffe98720 100644 --- a/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java +++ b/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java @@ -28,10 +28,7 @@ import neatlogic.framework.common.config.Config; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.util.ModuleUtil; import neatlogic.framework.dao.mapper.UserMapper; -import neatlogic.framework.dto.AuthVo; -import neatlogic.framework.dto.UserAuthVo; -import neatlogic.framework.dto.UserDataVo; -import neatlogic.framework.dto.UserVo; +import neatlogic.framework.dto.*; import neatlogic.framework.dto.module.ModuleGroupVo; import neatlogic.framework.exception.user.UserNotFoundException; import neatlogic.framework.restful.annotation.*; @@ -112,7 +109,9 @@ public class AuthModuleGetApi extends PrivateApiComponentBase { if (Config.ENABLE_MAINTENANCE() && Config.MAINTENANCE().equals(UserContext.get().getUserId())) { userAuthList = MaintenanceMode.getMaintenanceUser().getUserAuthList(); } else { - userAuthList = userMapper.searchUserAllAuthByUserAuth(new UserAuthVo(UserContext.get().getUserUuid())); + AuthenticationInfoVo authenticationInfoVo = UserContext.get().getAuthenticationInfoVo(); + String env = UserContext.get().getEnv(); + userAuthList = userMapper.searchUserAllAuthByUserAuth(authenticationInfoVo, env); AuthActionChecker.getAuthList(userAuthList); } for (UserAuthVo userAuth : userAuthList) { diff --git a/src/main/java/neatlogic/module/tenant/api/role/RoleSaveApi.java b/src/main/java/neatlogic/module/tenant/api/role/RoleSaveApi.java index 75b336861f9f20be8b839c2b41a81383ec1160f9..d99c4113e58180183c68d04e61c4e9b6f3856ac5 100644 --- a/src/main/java/neatlogic/module/tenant/api/role/RoleSaveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/role/RoleSaveApi.java @@ -64,6 +64,9 @@ public class RoleSaveApi extends PrivateApiComponentBase { @Param(name = "description", type = ApiParamType.STRING, desc = "角色描述", xss = true), + @Param(name = "env", + type = ApiParamType.STRING, + desc = "环境。登录认证的请求需要携带Key为Env的Header,如果Env Header值等于当前值或当前值为空则该角色生效,否则不生效", xss = true), @Param(name = "userUuidList", type = ApiParamType.JSONARRAY, desc = "用户uuid集合"), @@ -83,6 +86,7 @@ public class RoleSaveApi extends PrivateApiComponentBase { RoleVo roleVo = new RoleVo(); roleVo.setName(jsonObj.getString("name")); roleVo.setDescription(jsonObj.getString("description")); + roleVo.setEnv(jsonObj.getString("env")); String uuid = jsonObj.getString("uuid"); if (StringUtils.isNotBlank(uuid)) { if (roleMapper.checkRoleIsExists(uuid) == 0) { diff --git a/src/main/java/neatlogic/module/tenant/api/test/TestUserSessionApi.java b/src/main/java/neatlogic/module/tenant/api/test/TestUserSessionApi.java index e993b00862bdb632d574d1d2cda198bf48310e56..5775a3b055e93e4ec07f8345d78f449feb0d8ed1 100644 --- a/src/main/java/neatlogic/module/tenant/api/test/TestUserSessionApi.java +++ b/src/main/java/neatlogic/module/tenant/api/test/TestUserSessionApi.java @@ -52,7 +52,7 @@ public class TestUserSessionApi extends PrivateApiComponentBase { protected void execute() { long s = System.currentTimeMillis(); for (int k = 0; k < 200; k++) { - userSessionMapper.getUserSessionByUserUuid(Integer.toString(k)); + userSessionMapper.getUserSessionByTokenHash(Integer.toString(k)); userSessionMapper.updateUserSession(Integer.toString(k)); } diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserActiveUpdateApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserActiveUpdateApi.java index f600005d63765695d15e29371e1fc7b338f9205a..15a90f4a897c76a2363f8f84caf49297f4c8cddc 100755 --- a/src/main/java/neatlogic/module/tenant/api/user/UserActiveUpdateApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserActiveUpdateApi.java @@ -1,6 +1,7 @@ package neatlogic.module.tenant.api.user; import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.AUTHORITY_MODIFY; import neatlogic.framework.common.constvalue.ApiParamType; @@ -68,8 +69,8 @@ public class UserActiveUpdateApi extends PrivateApiComponentBase { userVo.setUuid(userUuid); userMapper.updateUserActive(userVo); //禁用用户时删除userSession - UserSessionCache.removeItem(tenantUuid, userUuid); - userSessionMapper.deleteUserSessionByUserUuid(userUuid); + UserSessionCache.removeItem(UserContext.get().getTokenHash()); + userSessionMapper.deleteUserSessionByTokenHash(userUuid); // if(isActive == 0){ // userMapper.deleteUserAuth(new UserAuthVo(userUuid)); // userMapper.deleteUserRoleByUserUuid(userUuid); diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserAvatarUploadApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserAvatarUploadApi.java index 6d5103b41cea75514fb91259aa77400b8e2389d0..9e5ff5a334b4f19230ca74817e6c4e366fcafb98 100644 --- a/src/main/java/neatlogic/module/tenant/api/user/UserAvatarUploadApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserAvatarUploadApi.java @@ -50,86 +50,86 @@ import javax.servlet.http.HttpServletResponse; @OperationType(type = OperationTypeEnum.OPERATE) public class UserAvatarUploadApi extends PrivateBinaryStreamApiComponentBase { - static Logger logger = LoggerFactory.getLogger(UserAvatarUploadApi.class); + static Logger logger = LoggerFactory.getLogger(UserAvatarUploadApi.class); - @Autowired - private UserMapper userMapper; - @Autowired - private FileMapper fileMapper; + @Autowired + private UserMapper userMapper; + @Autowired + private FileMapper fileMapper; - @Override - public String getToken() { - return "user/avatar/upload"; - } + @Override + public String getToken() { + return "user/avatar/upload"; + } - @Override - public String getName() { - return "用户头像上传"; - } + @Override + public String getName() { + return "用户头像上传"; + } - @Override - public String getConfig() { - return null; - } + @Override + public String getConfig() { + return null; + } - @Override - public boolean isRaw() { - return true; - } + @Override + public boolean isRaw() { + return true; + } - @Output({@Param(explode = FileVo.class)}) - @Description(desc = "用户头像上传") - @Override - public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { - String tenantUuid = TenantContext.get().getTenantUuid(); - if (StringUtils.isBlank(tenantUuid)) { - throw new NoTenantException(); - } - String userUuid = UserContext.get().getUserUuid(true); - UserVo user = userMapper.getUserByUuid(userUuid); - MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; - String paramName = "upload"; - JSONObject returnObj = new JSONObject(); - try { - MultipartFile multipartFile = multipartRequest.getFile(paramName); - if (multipartFile != null && multipartFile.getName() != null && multipartFile.getContentType().startsWith("image")) { - String oldFileName = multipartFile.getOriginalFilename(); - Long size = multipartFile.getSize(); + @Output({@Param(explode = FileVo.class)}) + @Description(desc = "用户头像上传") + @Override + public Object myDoService(JSONObject paramObj, HttpServletRequest request, HttpServletResponse response) throws Exception { + String tenantUuid = TenantContext.get().getTenantUuid(); + if (StringUtils.isBlank(tenantUuid)) { + throw new NoTenantException(); + } + String userUuid = UserContext.get().getUserUuid(true); + UserVo user = userMapper.getUserByUuidAndEnv(userUuid, UserContext.get().getEnv()); + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + String paramName = "upload"; + JSONObject returnObj = new JSONObject(); + try { + MultipartFile multipartFile = multipartRequest.getFile(paramName); + if (multipartFile != null && multipartFile.getName() != null && multipartFile.getContentType().startsWith("image")) { + String oldFileName = multipartFile.getOriginalFilename(); + Long size = multipartFile.getSize(); - FileVo fileVo = new FileVo(); - fileVo.setName(oldFileName); - fileVo.setSize(size); - fileVo.setUserUuid(userUuid); - fileVo.setType("image"); - fileVo.setContentType(multipartFile.getContentType()); - String filePath = null; - try { - filePath = FileUtil.saveData(MinioFileSystemHandler.NAME,tenantUuid,multipartFile.getInputStream(),fileVo.getId().toString(),fileVo.getContentType(),fileVo.getType()); - } catch (Exception ex) { - //如果minio出现异常,则上传到本地 - logger.error(ex.getMessage(),ex); - filePath = FileUtil.saveData(LocalFileSystemHandler.NAME,tenantUuid,multipartFile.getInputStream(),fileVo.getId().toString(),fileVo.getContentType(),fileVo.getType()); - } - fileVo.setPath(filePath); - fileMapper.insertFile(fileVo); - Long fileId = fileVo.getId(); - /** 保存头像数据 */ - JSONObject userInfo = new JSONObject(); - userInfo.put("avatar","api/binary/image/download?id=" + fileId); - user.setUserInfo(userInfo.toJSONString()); - userMapper.updateUserInfo(user); - returnObj.put("uploaded", true); - returnObj.put("url", "api/binary/image/download?id=" + fileId); + FileVo fileVo = new FileVo(); + fileVo.setName(oldFileName); + fileVo.setSize(size); + fileVo.setUserUuid(userUuid); + fileVo.setType("image"); + fileVo.setContentType(multipartFile.getContentType()); + String filePath = null; + try { + filePath = FileUtil.saveData(MinioFileSystemHandler.NAME, tenantUuid, multipartFile.getInputStream(), fileVo.getId().toString(), fileVo.getContentType(), fileVo.getType()); + } catch (Exception ex) { + //如果minio出现异常,则上传到本地 + logger.error(ex.getMessage(), ex); + filePath = FileUtil.saveData(LocalFileSystemHandler.NAME, tenantUuid, multipartFile.getInputStream(), fileVo.getId().toString(), fileVo.getContentType(), fileVo.getType()); + } + fileVo.setPath(filePath); + fileMapper.insertFile(fileVo); + Long fileId = fileVo.getId(); + /** 保存头像数据 */ + JSONObject userInfo = new JSONObject(); + userInfo.put("avatar", "api/binary/image/download?id=" + fileId); + user.setUserInfo(userInfo.toJSONString()); + userMapper.updateUserInfo(user); + returnObj.put("uploaded", true); + returnObj.put("url", "api/binary/image/download?id=" + fileId); - } else { - returnObj.put("uploaded", false); - returnObj.put("error", "请选择图片文件"); - } - } catch (Exception ex) { - returnObj.put("uploaded", false); - returnObj.put("error", ex.getMessage()); - } - return returnObj; + } else { + returnObj.put("uploaded", false); + returnObj.put("error", "请选择图片文件"); + } + } catch (Exception ex) { + returnObj.put("uploaded", false); + returnObj.put("error", ex.getMessage()); + } + return returnObj; - } + } } diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserDeleteApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserDeleteApi.java index b033bd29fc661549960c9d932642839dd3e31577..373ac175b51fb766e8508f63b79192e111aeffc0 100755 --- a/src/main/java/neatlogic/module/tenant/api/user/UserDeleteApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserDeleteApi.java @@ -1,7 +1,8 @@ package neatlogic.module.tenant.api.user; import com.alibaba.fastjson.JSONArray; -import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.USER_MODIFY; import neatlogic.framework.common.constvalue.ApiParamType; @@ -11,7 +12,6 @@ import neatlogic.framework.dao.mapper.UserSessionMapper; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import com.alibaba.fastjson.JSONObject; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,8 +57,8 @@ public class UserDeleteApi extends PrivateApiComponentBase{ List userUuidList = userUuidArray.toJavaList(String.class); for (String userUuid : userUuidList) { userMapper.updateUserIsDeletedByUuid(userUuid); - userSessionMapper.deleteUserSessionByUserUuid(userUuid); - UserSessionCache.removeItem(TenantContext.get().getTenantUuid(), userUuid); + userSessionMapper.deleteUserSessionByTokenHash(UserContext.get().getTokenHash()); + UserSessionCache.removeItem(UserContext.get().getTokenHash()); } return null; } diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserGetApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserGetApi.java index bc6357f2084f6d463e0872bdd9edf4e0db449b89..b38ff3f13fb07c2f363ff28392f2acbbc140a9e4 100644 --- a/src/main/java/neatlogic/module/tenant/api/user/UserGetApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserGetApi.java @@ -16,6 +16,7 @@ package neatlogic.module.tenant.api.user; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.auth.core.AuthActionChecker; @@ -29,16 +30,12 @@ import neatlogic.framework.common.constvalue.SystemUser; import neatlogic.framework.dao.mapper.RoleMapper; import neatlogic.framework.dao.mapper.TeamMapper; import neatlogic.framework.dao.mapper.UserMapper; -import neatlogic.framework.dto.RoleVo; -import neatlogic.framework.dto.TeamVo; -import neatlogic.framework.dto.UserAuthVo; -import neatlogic.framework.dto.UserVo; +import neatlogic.framework.dto.*; import neatlogic.framework.dto.module.ModuleGroupVo; import neatlogic.framework.exception.user.UserNotFoundException; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -94,7 +91,7 @@ public class UserGetApi extends PrivateApiComponentBase { } else if (Objects.equals(SystemUser.SYSTEM.getUserUuid(), userUuid)) { userVo = SystemUser.SYSTEM.getUserVo(); } else { - userVo = userMapper.getUserByUuid(userUuid); + userVo = userMapper.getUserByUuidAndEnv(userUuid, UserContext.get().getEnv()); if (userVo == null) { throw new UserNotFoundException(userUuid); } @@ -107,17 +104,19 @@ public class UserGetApi extends PrivateApiComponentBase { } userVo.setUserAuthList(userAuthVos); } else { - List userAuthVoList = userMapper.searchUserAllAuthByUserAuth(new UserAuthVo(userUuid)); + AuthenticationInfoVo authenticationInfoVo = UserContext.get().getAuthenticationInfoVo(); + String env = UserContext.get().getEnv(); + List userAuthVoList = userMapper.searchUserAllAuthByUserAuth(authenticationInfoVo, env); List filteredUserAuthVoList = new ArrayList<>(); if (CollectionUtils.isNotEmpty(userAuthVoList)) { - userAuthVoList.forEach(auth->{ + userAuthVoList.forEach(auth -> { //过滤反射后不存在非法auth AuthBase authBase = AuthFactory.getAuthInstance(auth.getAuth()); - if(authBase != null){ + if (authBase != null) { List moduleGroupVos = TenantContext.get().getActiveModuleGroupList(); List activeModuleGroupList = moduleGroupVos.stream().map(ModuleGroupVo::getGroup).collect(Collectors.toList()); //过滤该租户没有tenantGroup对应的auth - if (CollectionUtils.isNotEmpty(moduleGroupVos)&& activeModuleGroupList.contains(auth.getAuthGroup())) { + if (CollectionUtils.isNotEmpty(moduleGroupVos) && activeModuleGroupList.contains(auth.getAuthGroup())) { filteredUserAuthVoList.add(auth); } } @@ -170,26 +169,5 @@ public class UserGetApi extends PrivateApiComponentBase { } } return userVo; -// JSONObject userJson = (JSONObject) JSON.toJSON(userVo);// 防止修改cache vo -// if (CollectionUtils.isNotEmpty(userJson.getJSONArray("teamUuidList"))) { -// List teamUuidList = new ArrayList<>(); -// for (Object teamUuid : userJson.getJSONArray("teamUuidList")) { -// teamUuidList.add(GroupSearch.TEAM.getValuePlugin() + teamUuid); -// } -// userJson.put("teamUuidList", teamUuidList); -// } -// if (CollectionUtils.isNotEmpty(userJson.getJSONArray("roleUuidList"))) { -// List roleUuidList = new ArrayList<>(); -// for (Object roleUuid : userJson.getJSONArray("roleUuidList")) { -// roleUuidList.add(GroupSearch.ROLE.getValuePlugin() + roleUuid); -// } -// userJson.put("roleUuidList", roleUuidList); -// } - //告诉前端是否为维护模式 -// userJson.put("isMaintenanceMode", 0); -// if (Config.ENABLE_SUPERADMIN()) { -// userJson.put("isMaintenanceMode", 1); -// } -// return userJson; } } diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserGetListApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserGetListApi.java index 8a01ccba7d70933e22769eb63dab691259e23b79..1fcc340fd066b108d9e4da6e1d884f743f5132f9 100644 --- a/src/main/java/neatlogic/module/tenant/api/user/UserGetListApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserGetListApi.java @@ -16,20 +16,19 @@ package neatlogic.module.tenant.api.user; -import neatlogic.framework.auth.core.AuthAction; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.dao.mapper.UserMapper; import neatlogic.framework.dto.UserVo; import neatlogic.framework.exception.user.UserNotFoundException; -import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.annotation.Input; import neatlogic.framework.restful.annotation.OperationType; import neatlogic.framework.restful.annotation.Output; import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -76,7 +75,7 @@ public class UserGetListApi extends PrivateApiComponentBase { List userUuidList = JSON.parseArray(jsonObj.getString("userUuidList"), String.class); List userList = new ArrayList<>(); for (String userUuid : userUuidList){ - UserVo userVo = userMapper.getUserByUuid(userUuid); + UserVo userVo = userMapper.getUserByUuidAndEnv(userUuid, UserContext.get().getEnv()); if(userVo == null) { throw new UserNotFoundException(userUuid); }else {