# Conflicts: # pmapi/src/main/java/com/ningdatech/pmapi/user/manage/UserInfoManage.javatags/24080901
@@ -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; | |||||
/** | |||||
* <p> | |||||
* UserInfoConvertor | |||||
* </p> | |||||
* | |||||
* @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; | |||||
} | |||||
} |
@@ -43,8 +43,8 @@ public class UserAuthLoginManage { | |||||
/** | /** | ||||
* 根据用户id 获取用户全量信息 | * 根据用户id 获取用户全量信息 | ||||
* | * | ||||
* @param userId | |||||
* @return | |||||
* @param userId / | |||||
* @return / | |||||
*/ | */ | ||||
public UserFullInfoDTO getUserFullInfo(Long userId) { | public UserFullInfoDTO getUserFullInfo(Long userId) { | ||||
UserInfo userInfo = iUserInfoService.getById(userId); | UserInfo userInfo = iUserInfoService.getById(userId); | ||||
@@ -53,15 +53,15 @@ public class UserAuthLoginManage { | |||||
} | } | ||||
// 返回用户全量信息 | // 返回用户全量信息 | ||||
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | ||||
userFullInfoDTOAssembler(userInfo, userFullInfoDTO); | |||||
userFullInfoAssembler(userInfo, userFullInfoDTO); | |||||
return userFullInfoDTO; | return userFullInfoDTO; | ||||
} | } | ||||
/** | /** | ||||
* 根据用户名获取 | * 根据用户名获取 | ||||
* | * | ||||
* @param username | |||||
* @return | |||||
* @param username / | |||||
* @return / | |||||
*/ | */ | ||||
public UserFullInfoDTO queryUserInfoInPasswordAuth(String username) { | public UserFullInfoDTO queryUserInfoInPasswordAuth(String username) { | ||||
// TODO 目前账号密码登陆测试使用 强制用户登录 userId 1L | // TODO 目前账号密码登陆测试使用 强制用户登录 userId 1L | ||||
@@ -71,15 +71,15 @@ public class UserAuthLoginManage { | |||||
} | } | ||||
// 返回用户全量信息 | // 返回用户全量信息 | ||||
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | ||||
userFullInfoDTOAssembler(userInfo, userFullInfoDTO); | |||||
userFullInfoAssembler(userInfo, userFullInfoDTO); | |||||
return userFullInfoDTO; | return userFullInfoDTO; | ||||
} | } | ||||
/** | /** | ||||
* 根据手机号获取 | * 根据手机号获取 | ||||
* | * | ||||
* @param phoneNo | |||||
* @return | |||||
* @param phoneNo / | |||||
* @return / | |||||
*/ | */ | ||||
public UserFullInfoDTO queryUserInfoInPhoneNoAuth(String phoneNo) { | public UserFullInfoDTO queryUserInfoInPhoneNoAuth(String phoneNo) { | ||||
UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) | UserInfo userInfo = iUserInfoService.getOne(Wrappers.lambdaQuery(UserInfo.class) | ||||
@@ -89,15 +89,15 @@ public class UserAuthLoginManage { | |||||
} | } | ||||
// 返回用户全量信息 | // 返回用户全量信息 | ||||
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | ||||
userFullInfoDTOAssembler(userInfo, userFullInfoDTO); | |||||
userFullInfoAssembler(userInfo, userFullInfoDTO); | |||||
return userFullInfoDTO; | return userFullInfoDTO; | ||||
} | } | ||||
/** | /** | ||||
* 根据accountId(浙政钉扫码登陆) | * 根据accountId(浙政钉扫码登陆) | ||||
* | * | ||||
* @param accountId | |||||
* @return | |||||
* @param accountId / | |||||
* @return / | |||||
*/ | */ | ||||
public UserFullInfoDTO queryUserInfoInAccountIdAuth(String accountId) { | public UserFullInfoDTO queryUserInfoInAccountIdAuth(String accountId) { | ||||
@@ -109,12 +109,12 @@ public class UserAuthLoginManage { | |||||
} | } | ||||
// 返回用户全量信息 | // 返回用户全量信息 | ||||
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | ||||
userFullInfoDTOAssembler(userInfo, userFullInfoDTO); | |||||
userFullInfoAssembler(userInfo, userFullInfoDTO); | |||||
return userFullInfoDTO; | return userFullInfoDTO; | ||||
} | } | ||||
private void userFullInfoDTOAssembler(UserInfo userInfo, UserFullInfoDTO userFullInfoDTO) { | |||||
private void userFullInfoAssembler(UserInfo userInfo, UserFullInfoDTO userFullInfoDTO) { | |||||
// 获取浙政钉雇员信息 组织信息 | // 获取浙政钉雇员信息 组织信息 | ||||
String employeeCode = userInfo.getEmployeeCode(); | String employeeCode = userInfo.getEmployeeCode(); | ||||
if (StringUtils.isNotBlank(employeeCode)) { | if (StringUtils.isNotBlank(employeeCode)) { | ||||
@@ -128,9 +128,7 @@ public class UserAuthLoginManage { | |||||
// 装配用户任职所在单位 | // 装配用户任职所在单位 | ||||
String empPosUnitCode = dingEmployeeInfo.getEmpPosUnitCode(); | String empPosUnitCode = dingEmployeeInfo.getEmpPosUnitCode(); | ||||
if (StringUtils.isNotBlank(empPosUnitCode)) { | 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)) { | if (Objects.nonNull(dingOrganization)) { | ||||
userFullInfoDTO.setEmpPosUnitCode(empPosUnitCode); | userFullInfoDTO.setEmpPosUnitCode(empPosUnitCode); | ||||
userFullInfoDTO.setEmpPosUnitName(dingOrganization.getOrganizationName()); | userFullInfoDTO.setEmpPosUnitName(dingOrganization.getOrganizationName()); | ||||
@@ -139,9 +137,9 @@ public class UserAuthLoginManage { | |||||
// 装配用户所在orgCode | // 装配用户所在orgCode | ||||
String organizationCode = dingEmployeeInfo.getOrganizationCode(); | String organizationCode = dingEmployeeInfo.getOrganizationCode(); | ||||
List<DingOrganization> dingOrganizationList = iDingOrganizationService | |||||
.list(Wrappers.lambdaQuery(DingOrganization.class) | |||||
.eq(DingOrganization::getOrganizationCode, organizationCode)); | |||||
List<DingOrganization> dingOrganizationList = iDingOrganizationService.list(Wrappers | |||||
.lambdaQuery(DingOrganization.class) | |||||
.eq(DingOrganization::getOrganizationCode, organizationCode)); | |||||
if (CollectionUtil.isNotEmpty(dingOrganizationList)) { | if (CollectionUtil.isNotEmpty(dingOrganizationList)) { | ||||
DingOrganization dingOrganization = dingOrganizationList.get(0); | DingOrganization dingOrganization = dingOrganizationList.get(0); | ||||
userFullInfoDTO.setOrganizationCode(dingOrganization.getOrganizationCode()); | userFullInfoDTO.setOrganizationCode(dingOrganization.getOrganizationCode()); | ||||
@@ -174,7 +172,7 @@ public class UserAuthLoginManage { | |||||
userFullInfoDTO.setEmployeeCode(employeeCode); | userFullInfoDTO.setEmployeeCode(employeeCode); | ||||
userFullInfoDTO.setUsername(userInfo.getRealName()); | userFullInfoDTO.setUsername(userInfo.getRealName()); | ||||
userFullInfoDTO.setMobile(userInfo.getMobile()); | userFullInfoDTO.setMobile(userInfo.getMobile()); | ||||
userFullInfoDTO.setAccountId(userInfo.getAccountId()); | |||||
} | } | ||||
public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) { | public UserFullInfoDTO getUserFullInfoByEmployeeCode(String employeeCode) { | ||||
@@ -185,7 +183,7 @@ public class UserAuthLoginManage { | |||||
} | } | ||||
// 返回用户全量信息 | // 返回用户全量信息 | ||||
UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | UserFullInfoDTO userFullInfoDTO = new UserFullInfoDTO(); | ||||
userFullInfoDTOAssembler(userInfo, userFullInfoDTO); | |||||
userFullInfoAssembler(userInfo, userFullInfoDTO); | |||||
return userFullInfoDTO; | return userFullInfoDTO; | ||||
} | } | ||||
} | } |
@@ -20,6 +20,7 @@ import com.ningdatech.pmapi.sys.model.entity.UserRole; | |||||
import com.ningdatech.pmapi.sys.service.IRoleService; | import com.ningdatech.pmapi.sys.service.IRoleService; | ||||
import com.ningdatech.pmapi.sys.service.IUserRoleService; | import com.ningdatech.pmapi.sys.service.IUserRoleService; | ||||
import com.ningdatech.pmapi.user.constant.UserAvailableEnum; | 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.entity.UserInfo; | ||||
import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; | import com.ningdatech.pmapi.user.model.po.ReqUserDetailEditPO; | ||||
import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; | import com.ningdatech.pmapi.user.model.po.ReqUserDetailPO; | ||||
@@ -28,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.ResUserDetailVO; | ||||
import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; | import com.ningdatech.pmapi.user.model.vo.ResUserInfoListVO; | ||||
import com.ningdatech.pmapi.user.model.vo.UserRoleVO; | 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.UserFullInfoDTO; | ||||
import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; | |||||
import com.ningdatech.pmapi.user.service.IUserInfoService; | import com.ningdatech.pmapi.user.service.IUserInfoService; | ||||
import com.ningdatech.pmapi.user.util.LoginUserUtil; | import com.ningdatech.pmapi.user.util.LoginUserUtil; | ||||
import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; | import com.wflow.workflow.bean.dto.ProcessInstanceUserDto; | ||||
import lombok.RequiredArgsConstructor; | 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.stereotype.Component; | ||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
@@ -54,8 +61,9 @@ public class UserInfoManage { | |||||
private final IUserRoleService iUserRoleService; | private final IUserRoleService iUserRoleService; | ||||
private final IRoleService iRoleService; | private final IRoleService iRoleService; | ||||
private final UserInfoHelper userInfoHelper; | private final UserInfoHelper userInfoHelper; | ||||
private final RedisIndexedSessionRepository redisIndexedSessionRepository; | |||||
private final RegionCacheHelper regionCacheHelper; | private final RegionCacheHelper regionCacheHelper; | ||||
private final UserAuthLoginManage userAuthLoginManage; | |||||
public PageVo<ResUserInfoListVO> list(ReqUserInfoListPO req) { | public PageVo<ResUserInfoListVO> list(ReqUserInfoListPO req) { | ||||
PageVo<ResUserInfoListVO> pageVo = new PageVo<>(); | PageVo<ResUserInfoListVO> pageVo = new PageVo<>(); | ||||
@@ -207,7 +215,7 @@ public class UserInfoManage { | |||||
return new ArrayList<>(); | return new ArrayList<>(); | ||||
} | } | ||||
return iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class) | return iUserInfoService.list(Wrappers.lambdaQuery(UserInfo.class) | ||||
.in(UserInfo::getId, compliantUserIdList)) | |||||
.in(UserInfo::getId, compliantUserIdList)) | |||||
.stream().map(UserInfo::getId).collect(Collectors.toList()); | .stream().map(UserInfo::getId).collect(Collectors.toList()); | ||||
} | } | ||||
@@ -332,6 +340,8 @@ public class UserInfoManage { | |||||
}).collect(Collectors.toList()); | }).collect(Collectors.toList()); | ||||
iUserRoleService.saveBatch(userRoleList); | iUserRoleService.saveBatch(userRoleList); | ||||
} | } | ||||
// 刷新用户权限 | |||||
refreshSession(userId); | |||||
} | } | ||||
/** | /** | ||||
@@ -492,6 +502,28 @@ public class UserInfoManage { | |||||
return processInstanceUserDto; | return processInstanceUserDto; | ||||
} | } | ||||
public void refreshSession(Long userId) { | |||||
UserFullInfoDTO ufi = userAuthLoginManage.getUserFullInfo(userId); | |||||
List<String> 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); | |||||
}); | |||||
} | |||||
/** | /** | ||||
* 获取当前用户可控角色列表 | * 获取当前用户可控角色列表 | ||||
* | * | ||||
@@ -2,6 +2,7 @@ package com.ningdatech.pmapi.user.security.auth.credential; | |||||
import com.ningdatech.pmapi.user.constant.LoginTypeEnum; | 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.manage.UserAuthLoginManage; | ||||
import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; | import com.ningdatech.pmapi.user.security.auth.constants.UserDeatilsServiceConstant; | ||||
import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; | import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; | ||||
@@ -32,25 +33,25 @@ public class CredentialLoginUserDetailService implements UserDetailsService { | |||||
String loginTypeStr = split[1]; | String loginTypeStr = split[1]; | ||||
LoginTypeEnum loginTypeEnum = LoginTypeEnum.valueOf(loginTypeStr); | LoginTypeEnum loginTypeEnum = LoginTypeEnum.valueOf(loginTypeStr); | ||||
UserFullInfoDTO userFullInfoDTO = null; | |||||
UserFullInfoDTO userFullInfo; | |||||
switch (loginTypeEnum) { | switch (loginTypeEnum) { | ||||
case PHONE_VERIFICATION_CODE_LOGIN: { | case PHONE_VERIFICATION_CODE_LOGIN: { | ||||
userFullInfoDTO = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username); | |||||
if (Objects.isNull(userFullInfoDTO)) { | |||||
userFullInfo = userAuthLoginManage.queryUserInfoInPhoneNoAuth(username); | |||||
if (Objects.isNull(userFullInfo)) { | |||||
throw new CommonLoginException("改手机号未绑定用户"); | throw new CommonLoginException("改手机号未绑定用户"); | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case USERNAME_PASSWORD_LOGIN: { | 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)); | throw new UsernameNotFoundException(String.format("%s user not exist", username)); | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
case DING_QR_LOGIN: { | case DING_QR_LOGIN: { | ||||
userFullInfoDTO = userAuthLoginManage.queryUserInfoInAccountIdAuth(username); | |||||
if (Objects.isNull(userFullInfoDTO)) { | |||||
userFullInfo = userAuthLoginManage.queryUserInfoInAccountIdAuth(username); | |||||
if (Objects.isNull(userFullInfo)) { | |||||
throw new CommonLoginException("浙政钉账号无法登陆"); | throw new CommonLoginException("浙政钉账号无法登陆"); | ||||
} | } | ||||
} | } | ||||
@@ -59,21 +60,6 @@ public class CredentialLoginUserDetailService implements UserDetailsService { | |||||
throw new UsernameNotFoundException(String.format("%s user not exist", username)); | 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); | |||||
} | } | ||||
} | } |
@@ -71,6 +71,8 @@ public class UserFullInfoDTO { | |||||
*/ | */ | ||||
private List<Role> userRoleList; | private List<Role> userRoleList; | ||||
private Long accountId; | |||||
/** | /** | ||||
* 取最高的权限 | * 取最高的权限 | ||||
* | * | ||||