From 91927f542c7efb1e51f4193a6267c8c45b9b3ae8 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Fri, 5 May 2023 16:23:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=BC=96=E8=BE=91=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E3=80=81?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=94=A8=E6=88=B7=E5=88=B7=E6=96=B0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/sys/service/impl/RoleServiceImpl.java | 7 ++- .../pmapi/user/manage/UserAuthLoginManage.java | 55 ++++++++++++++++++++-- .../pmapi/user/manage/UserInfoManage.java | 36 ++------------ 3 files changed, 63 insertions(+), 35 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java index 46e9844..42f3d71 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/service/impl/RoleServiceImpl.java @@ -19,6 +19,7 @@ import com.ningdatech.pmapi.sys.model.dto.RoleUpdateDTO; import com.ningdatech.pmapi.sys.model.entity.*; import com.ningdatech.pmapi.sys.service.*; import com.ningdatech.pmapi.sys.utils.AuthCacheKeyUtils; +import com.ningdatech.pmapi.user.manage.UserAuthLoginManage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -46,6 +47,7 @@ public class RoleServiceImpl extends ServiceImpl implements IR private final CachePlusOps cachePlusOps; private final IRoleMenuService roleMenuService; private final IMenuService menuService; + private final UserAuthLoginManage userAuthLoginManage; /** * 删除角色时,需要级联删除跟角色相关的一切资源: @@ -155,7 +157,10 @@ public class RoleServiceImpl extends ServiceImpl implements IR saveRoleMenu(data.getMenuIds(), role.getId()); saveRoleMenuDatascope(data.getMenuDataScopeList(), role.getId()); List userIdList = userRoleService.listUserIdByRoleId(role.getId()); - userIdList.forEach(w -> cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(w))); + userIdList.forEach(w -> { + cachePlusOps.del(AuthCacheKeyUtils.userResourceCacheKey(w)); + userAuthLoginManage.refreshSession(w); + }); } @Override diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java index 66d94d3..bedf486 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserAuthLoginManage.java @@ -3,6 +3,7 @@ package com.ningdatech.pmapi.user.manage; import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.pmapi.common.util.StrUtils; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; @@ -11,11 +12,17 @@ import com.ningdatech.pmapi.sys.model.entity.Role; import com.ningdatech.pmapi.sys.model.entity.UserRole; import com.ningdatech.pmapi.sys.service.IRoleService; import com.ningdatech.pmapi.sys.service.IUserRoleService; +import com.ningdatech.pmapi.user.convert.UserInfoConvertor; import com.ningdatech.pmapi.user.entity.UserInfo; +import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; -import com.ningdatech.pmapi.user.service.IUserAuthService; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import com.ningdatech.pmapi.user.service.IUserInfoService; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.context.SecurityContextImpl; +import org.springframework.session.Session; +import org.springframework.session.SessionRepository; +import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -32,13 +39,12 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class UserAuthLoginManage { - private final IUserAuthService iUserAuthService; private final IUserInfoService iUserInfoService; private final IRoleService iRoleService; private final IDingOrganizationService iDingOrganizationService; private final IDingEmployeeInfoService iDingEmployeeInfoService; private final IUserRoleService iUserRoleService; - + private final RedisIndexedSessionRepository redisIndexedSessionRepository; /** * 根据用户id 获取用户全量信息 @@ -186,4 +192,47 @@ public class UserAuthLoginManage { userFullInfoAssembler(userInfo, userFullInfoDTO); return userFullInfoDTO; } + + @SuppressWarnings({"rawtypes", "unchecked"}) + public void refreshSession(Long userId) { + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); + List sessionIds = getSessionIds(userFullInfo); + if (sessionIds.isEmpty()) { + return; + } + SessionRepository redisSessionRepository = redisIndexedSessionRepository; + UserInfoDetails details = UserInfoConvertor.toUserInfoDetails(userFullInfo); + CredentialAuthToken cat = new CredentialAuthToken(details, details.getPassword(), details.getAuthorities()); + sessionIds.forEach(sessionId -> { + Session session = redisIndexedSessionRepository.findById(sessionId); + SecurityContextImpl context = session.getAttribute("SPRING_SECURITY_CONTEXT"); + context.setAuthentication(cat); + session.setAttribute("SPRING_SECURITY_CONTEXT", context); + redisSessionRepository.save(session); + }); + } + + private List getSessionIds(UserFullInfoDTO userFullInfo) { + List sessionIds = new ArrayList<>(); + String identifier = userFullInfo.getIdentifier(); + if (StrUtils.isNotBlank(identifier)) { + sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(identifier).keySet()); + } + String mobile = userFullInfo.getMobile(); + if (StrUtils.isNotBlank(mobile)) { + sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(mobile).keySet()); + } + Long accountId = userFullInfo.getAccountId(); + if (accountId != null) { + sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(accountId.toString()).keySet()); + } + return sessionIds; + } + + public void kickOff(Long userId) { + UserFullInfoDTO userFullInfo = getUserFullInfo(userId); + List sessionIds = getSessionIds(userFullInfo); + sessionIds.forEach(redisIndexedSessionRepository::deleteById); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java index 2d26866..0cd3b9f 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.java @@ -10,7 +10,6 @@ import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.common.constant.RegionConst; import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.helper.UserInfoHelper; -import com.ningdatech.pmapi.common.util.BizUtils; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService; @@ -20,7 +19,6 @@ import com.ningdatech.pmapi.sys.model.entity.UserRole; import com.ningdatech.pmapi.sys.service.IRoleService; import com.ningdatech.pmapi.sys.service.IUserRoleService; import com.ningdatech.pmapi.user.constant.UserAvailableEnum; -import com.ningdatech.pmapi.user.convert.UserInfoConvertor; import com.ningdatech.pmapi.user.entity.UserInfo; import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; @@ -29,17 +27,11 @@ import com.ningdatech.pmapi.user.model.po.ReqUserInfoListPO; import com.ningdatech.pmapi.user.model.vo.ResUserDetailVO; import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; import com.ningdatech.pmapi.user.model.vo.UserRoleVO; -import com.ningdatech.pmapi.user.security.auth.credential.CredentialAuthToken; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; -import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import com.ningdatech.pmapi.user.service.IUserInfoService; import com.ningdatech.pmapi.user.util.LoginUserUtil; import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.context.SecurityContextImpl; -import org.springframework.session.Session; -import org.springframework.session.SessionRepository; -import org.springframework.session.data.redis.RedisIndexedSessionRepository; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -61,7 +53,6 @@ public class UserInfoManage { private final IUserRoleService iUserRoleService; private final IRoleService iRoleService; private final UserInfoHelper userInfoHelper; - private final RedisIndexedSessionRepository redisIndexedSessionRepository; private final RegionCacheHelper regionCacheHelper; private final UserAuthLoginManage userAuthLoginManage; @@ -268,6 +259,10 @@ public class UserInfoManage { UserInfo userInfo = iUserInfoService.getById(userId); userInfo.setAvailable(reqUserDisableOrEnablePO.getOperation()); iUserInfoService.updateById(userInfo); + if (userInfo.getAvailable().equals("DISABLE")) { + userAuthLoginManage.kickOff(userId); + } + } public ResUserDetailVO userInfoDetail(ReqUserDetailPO reqUserDetailPO) { @@ -341,7 +336,7 @@ public class UserInfoManage { iUserRoleService.saveBatch(userRoleList); } // 刷新用户权限 - refreshSession(userId); + userAuthLoginManage.refreshSession(userId); } /** @@ -502,25 +497,4 @@ public class UserInfoManage { return processInstanceUserDto; } - public void refreshSession(Long userId) { - UserFullInfoDTO ufi = userAuthLoginManage.getUserFullInfo(userId); - List sessionIds = new ArrayList<>(); - BizUtils.notNull(ufi.getIdentifier(), w -> sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(w).keySet())); - BizUtils.notNull(ufi.getMobile(), w -> sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(w).keySet())); - BizUtils.notNull(ufi.getAccountId(), w -> sessionIds.addAll(redisIndexedSessionRepository.findByPrincipalName(w.toString()).keySet())); - if (sessionIds.isEmpty()) { - return; - } - SessionRepository redisSessionRepository = redisIndexedSessionRepository; - UserInfoDetails details = UserInfoConvertor.toUserInfoDetails(ufi); - CredentialAuthToken cat = new CredentialAuthToken(details, details.getPassword(), details.getAuthorities()); - sessionIds.forEach(sessionId -> { - Session session = redisIndexedSessionRepository.findById(sessionId); - SecurityContextImpl context = session.getAttribute("SPRING_SECURITY_CONTEXT"); - context.setAuthentication(cat); - session.setAttribute("SPRING_SECURITY_CONTEXT", context); - redisSessionRepository.save(session); - }); - } - } From 2c331be5c10be56d887bb601e5596fe2cb8eedc8 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 5 May 2023 16:29:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B7=B2=E5=A4=84=E7=90=86=20=E5=8A=A0task?= =?UTF-8?q?Id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/todocenter/handle/WithDrawHandle.java | 12 +++++++----- .../ningdatech/pmapi/todocenter/manage/TodoCenterManage.java | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java index d0ad64c..d07c051 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/handle/WithDrawHandle.java @@ -72,15 +72,17 @@ public class WithDrawHandle { // 判断当前操作人 是上一个节点的审批人 public Boolean checkUserIsBefore(List currentProgressInfo, ReqProcessHandlerDTO param) { UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId()); - //1.判断出 当前审批人和上一个审批人 - ProgressNode progressNode = currentProgressInfo.get(currentProgressInfo.size() - 1); - ProgressNode beforeProgressNode = null; - ProgressNode currentProgressNode = null; // 先排除掉抄送任务节点 currentProgressInfo = currentProgressInfo.stream() .filter(c -> !NodeTypeEnum.CC.name().equals(c.getNodeType().name())) .collect(Collectors.toList()); + + //1.判断出 当前审批人和上一个审批人 + ProgressNode progressNode = currentProgressInfo.get(currentProgressInfo.size() - 1); + ProgressNode beforeProgressNode = null; + ProgressNode currentProgressNode = null; + if (CollUtil.isEmpty(currentProgressInfo)){ return Boolean.FALSE; } @@ -108,7 +110,7 @@ public class WithDrawHandle { // 判断当前工作流任务前一个审核人的部门和当前登录用户的部门是否是同一个,如果是同一个才可以撤回,否则抛出异常 // 获取当前当前工作流任务当前审核人信息 UserFullInfoDTO currentUserInfo = userInfoHelper.getUserFullInfoByEmployeeCode(currentProgressNode.getUserId()); - if(!currentUserInfo.getEmpPosUnitCode().equals(user.getEmpPosUnitCode())){ + if(Objects.isNull(currentUserInfo) || !currentUserInfo.getEmpPosUnitCode().equals(user.getEmpPosUnitCode())){ return Boolean.FALSE; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java index 696b06c..a56f15d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java @@ -550,6 +550,7 @@ public class TodoCenterManage { res.setProcessStatusName(d.getStatus()); res.setProcessLaunchTime(d.getCreateTime()); res.setProcessHandleTime(d.getTaskEndTime()); + res.setTaskId(d.getTaskId()); return res; }).collect(Collectors.toList()); return PageVo.of(resVos, iDoList.size());