diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/convert/UserInfoConvertor.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/convert/UserInfoConvertor.java
new file mode 100644
index 0000000..7fa0e38
--- /dev/null
+++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/convert/UserInfoConvertor.java
@@ -0,0 +1,38 @@
+package com.ningdatech.pmapi.user.convert;
+
+import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO;
+import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails;
+
+/**
+ *
+ * UserInfoConvertor
+ *
+ *
+ * @author WendyYang
+ * @since 2023/5/5
+ **/
+public class UserInfoConvertor {
+
+ private UserInfoConvertor() {
+
+ }
+
+ public static UserInfoDetails toUserInfoDetails(UserFullInfoDTO userFullInfo) {
+ UserInfoDetails userInfoDetails = new UserInfoDetails();
+ userInfoDetails.setUserId(userFullInfo.getUserId());
+ userInfoDetails.setUsername(userFullInfo.getUsername());
+ userInfoDetails.setRealName(userFullInfo.getRealName());
+ userInfoDetails.setUserRoleList(userFullInfo.getUserRoleList());
+ userInfoDetails.setRegionCode(userFullInfo.getRegionCode());
+ userInfoDetails.setRegionLevel(userFullInfo.getRegionLevel());
+ userInfoDetails.setIdentifier(userFullInfo.getIdentifier());
+ userInfoDetails.setPassword(userFullInfo.getCredential());
+ userInfoDetails.setEmployeeCode(userFullInfo.getEmployeeCode());
+ userInfoDetails.setOrganizationCode(userFullInfo.getOrganizationCode());
+ userInfoDetails.setOrganizationName(userFullInfo.getOrganizationName());
+ userInfoDetails.setEmpPosUnitCode(userFullInfo.getEmpPosUnitCode());
+ userInfoDetails.setEmpPosUnitName(userFullInfo.getEmpPosUnitName());
+ return userInfoDetails;
+ }
+
+}
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 50a4ce3..66d94d3 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
@@ -43,8 +43,8 @@ public class UserAuthLoginManage {
/**
* 根据用户id 获取用户全量信息
*
- * @param userId
- * @return
+ * @param userId /
+ * @return /
*/
public UserFullInfoDTO getUserFullInfo(Long userId) {
UserInfo userInfo = iUserInfoService.getById(userId);
@@ -53,15 +53,15 @@ public class UserAuthLoginManage {
}
// 返回用户全量信息
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO();
- userFullInfoDTOAssembler(userInfo, userFullInfoDTO);
+ userFullInfoAssembler(userInfo, userFullInfoDTO);
return userFullInfoDTO;
}
/**
* 根据用户名获取
*
- * @param username
- * @return
+ * @param username /
+ * @return /
*/
public UserFullInfoDTO queryUserInfoInPasswordAuth(String username) {
// TODO 目前账号密码登陆测试使用 强制用户登录 userId 1L
@@ -71,15 +71,15 @@ public class UserAuthLoginManage {
}
// 返回用户全量信息
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO();
- userFullInfoDTOAssembler(userInfo, userFullInfoDTO);
+ userFullInfoAssembler(userInfo, userFullInfoDTO);
return userFullInfoDTO;
}
/**
* 根据手机号获取
*
- * @param phoneNo
- * @return
+ * @param phoneNo /
+ * @return /
*/
public UserFullInfoDTO queryUserInfoInPhoneNoAuth(String phoneNo) {
UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class)
@@ -89,15 +89,15 @@ public class UserAuthLoginManage {
}
// 返回用户全量信息
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO();
- userFullInfoDTOAssembler(userInfo, userFullInfoDTO);
+ userFullInfoAssembler(userInfo, userFullInfoDTO);
return userFullInfoDTO;
}
/**
* 根据accountId(浙政钉扫码登陆)
*
- * @param accountId
- * @return
+ * @param accountId /
+ * @return /
*/
public UserFullInfoDTO queryUserInfoInAccountIdAuth(String accountId) {
@@ -109,12 +109,12 @@ public class UserAuthLoginManage {
}
// 返回用户全量信息
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO();
- userFullInfoDTOAssembler(userInfo, userFullInfoDTO);
+ userFullInfoAssembler(userInfo, userFullInfoDTO);
return userFullInfoDTO;
}
- private void userFullInfoDTOAssembler(UserInfo userInfo, UserFullInfoDTO userFullInfoDTO) {
+ private void userFullInfoAssembler(UserInfo userInfo, UserFullInfoDTO userFullInfoDTO) {
// 获取浙政钉雇员信息 组织信息
String employeeCode = userInfo.getEmployeeCode();
if (StringUtils.isNotBlank(employeeCode)) {
@@ -128,9 +128,7 @@ public class UserAuthLoginManage {
// 装配用户任职所在单位
String empPosUnitCode = dingEmployeeInfo.getEmpPosUnitCode();
if (StringUtils.isNotBlank(empPosUnitCode)) {
- DingOrganization dingOrganization = iDingOrganizationService
- .getOne(Wrappers.lambdaQuery(DingOrganization.class)
- .eq(DingOrganization::getOrganizationCode, empPosUnitCode));
+ DingOrganization dingOrganization = iDingOrganizationService.getByOrgCode(empPosUnitCode);
if (Objects.nonNull(dingOrganization)) {
userFullInfoDTO.setEmpPosUnitCode(empPosUnitCode);
userFullInfoDTO.setEmpPosUnitName(dingOrganization.getOrganizationName());
@@ -139,9 +137,9 @@ public class UserAuthLoginManage {
// 装配用户所在orgCode
String organizationCode = dingEmployeeInfo.getOrganizationCode();
- List dingOrganizationList = iDingOrganizationService
- .list(Wrappers.lambdaQuery(DingOrganization.class)
- .eq(DingOrganization::getOrganizationCode, organizationCode));
+ List dingOrganizationList = iDingOrganizationService.list(Wrappers
+ .lambdaQuery(DingOrganization.class)
+ .eq(DingOrganization::getOrganizationCode, organizationCode));
if (CollectionUtil.isNotEmpty(dingOrganizationList)) {
DingOrganization dingOrganization = dingOrganizationList.get(0);
userFullInfoDTO.setOrganizationCode(dingOrganization.getOrganizationCode());
@@ -174,7 +172,7 @@ public class UserAuthLoginManage {
userFullInfoDTO.setEmployeeCode(employeeCode);
userFullInfoDTO.setUsername(userInfo.getRealName());
userFullInfoDTO.setMobile(userInfo.getMobile());
-
+ userFullInfoDTO.setAccountId(userInfo.getAccountId());
}
public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) {
@@ -185,7 +183,7 @@ public class UserAuthLoginManage {
}
// 返回用户全量信息
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO();
- userFullInfoDTOAssembler(userInfo, userFullInfoDTO);
+ userFullInfoAssembler(userInfo, userFullInfoDTO);
return userFullInfoDTO;
}
}
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 fb052a2..2d26866 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,6 +10,7 @@ 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;
@@ -19,6 +20,7 @@ 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;
@@ -27,11 +29,17 @@ 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;
@@ -53,8 +61,9 @@ 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;
public PageVo list(ReqUserInfoListPO req) {
PageVo pageVo = new PageVo<>();
@@ -206,7 +215,7 @@ public class UserInfoManage {
return new ArrayList<>();
}
return iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class)
- .in(UserInfo::getId, compliantUserIdList))
+ .in(UserInfo::getId, compliantUserIdList))
.stream().map(UserInfo::getId).collect(Collectors.toList());
}
@@ -331,6 +340,8 @@ public class UserInfoManage {
}).collect(Collectors.toList());
iUserRoleService.saveBatch(userRoleList);
}
+ // 刷新用户权限
+ refreshSession(userId);
}
/**
@@ -490,4 +501,26 @@ 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);
+ });
+ }
+
}
diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java
index 854db99..455c0b9 100644
--- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java
+++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/credential/CredentialLoginUserDetailService.java
@@ -2,6 +2,7 @@ package com.ningdatech.pmapi.user.security.auth.credential;
import com.ningdatech.pmapi.user.constant.LoginTypeEnum;
+import com.ningdatech.pmapi.user.convert.UserInfoConvertor;
import com.ningdatech.pmapi.user.manage.UserAuthLoginManage;
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant;
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO;
@@ -32,25 +33,25 @@ public class CredentialLoginUserDetailService implements UserDetailsService {
String loginTypeStr = split[1];
LoginTypeEnum loginTypeEnum = LoginTypeEnum.valueOf(loginTypeStr);
- UserFullInfoDTO userFullInfoDTO = null;
+ UserFullInfoDTO userFullInfo;
switch (loginTypeEnum) {
case PHONE_VERIFICATION_CODE_LOGIN: {
- userFullInfoDTO = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username);
- if (Objects.isNull(userFullInfoDTO)) {
+ userFullInfo = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username);
+ if (Objects.isNull(userFullInfo)) {
throw new CommonLoginException("改手机号未绑定用户");
}
}
break;
case USERNAME_PASSWORD_LOGIN: {
- userFullInfoDTO = userAuthLoginManage.queryUserInfoInPasswordAuth(username);
- if (Objects.isNull(userFullInfoDTO)) {
+ userFullInfo = userAuthLoginManage.queryUserInfoInPasswordAuth(username);
+ if (Objects.isNull(userFullInfo)) {
throw new UsernameNotFoundException(String.format("%s user not exist", username));
}
}
break;
case DING_QR_LOGIN: {
- userFullInfoDTO = userAuthLoginManage.queryUserInfoInAccountIdAuth(username);
- if (Objects.isNull(userFullInfoDTO)) {
+ userFullInfo = userAuthLoginManage.queryUserInfoInAccountIdAuth(username);
+ if (Objects.isNull(userFullInfo)) {
throw new CommonLoginException("浙政钉账号无法登陆");
}
}
@@ -59,21 +60,6 @@ public class CredentialLoginUserDetailService implements UserDetailsService {
throw new UsernameNotFoundException(String.format("%s user not exist", username));
}
}
-
- UserInfoDetails userInfoDetails = new UserInfoDetails();
- userInfoDetails.setUserId(userFullInfoDTO.getUserId());
- userInfoDetails.setUsername(userFullInfoDTO.getUsername());
- userInfoDetails.setRealName(userFullInfoDTO.getRealName());
- userInfoDetails.setUserRoleList(userFullInfoDTO.getUserRoleList());
- userInfoDetails.setRegionCode(userFullInfoDTO.getRegionCode());
- userInfoDetails.setRegionLevel(userFullInfoDTO.getRegionLevel());
- userInfoDetails.setIdentifier(userFullInfoDTO.getIdentifier());
- userInfoDetails.setPassword(userFullInfoDTO.getCredential());
- userInfoDetails.setEmployeeCode(userFullInfoDTO.getEmployeeCode());
- userInfoDetails.setOrganizationCode(userFullInfoDTO.getOrganizationCode());
- userInfoDetails.setOrganizationName(userFullInfoDTO.getOrganizationName());
- userInfoDetails.setEmpPosUnitCode(userFullInfoDTO.getEmpPosUnitCode());
- userInfoDetails.setEmpPosUnitName(userFullInfoDTO.getEmpPosUnitName());
- return userInfoDetails;
+ return UserInfoConvertor.toUserInfoDetails(userFullInfo);
}
}
diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserFullInfoDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserFullInfoDTO.java
index 5482f45..f4291be 100644
--- a/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserFullInfoDTO.java
+++ b/pmapi/src/main/java/com/ningdatech/pmapi/user/security/auth/model/UserFullInfoDTO.java
@@ -71,6 +71,8 @@ public class UserFullInfoDTO {
*/
private List userRoleList;
+ private Long accountId;
+
/**
* 取最高的权限
*