| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.vci.client.logon.base.LogonHandler; |
| | | import com.vci.corba.framework.data.LoginResult; |
| | | import com.vci.corba.framework.data.LoginState; |
| | | import com.vci.frameworkcore.ajaxTask.SmUserUnLockTask; |
| | | import com.vci.frameworkcore.ajaxTask.SmUserUnLockTaskManager; |
| | | import com.vci.frameworkcore.compatibility.ISmFunctionQueryService; |
| | |
| | | import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; |
| | | import com.vci.frameworkcore.pagemodel.SmUserVO; |
| | | import com.vci.frameworkcore.properties.VciSecurityManageProperties; |
| | | import com.vci.starter.web.annotation.bus.*; |
| | | import com.vci.starter.web.annotation.bus.VciLoginAfter; |
| | | import com.vci.starter.web.annotation.bus.VciLogoutBefore; |
| | | import com.vci.starter.web.annotation.bus.VciLogoutPlugin; |
| | | import com.vci.starter.web.constant.TokenKeyConstant; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.interceptor.VciSessionForLoginI; |
| | | import com.vci.starter.web.pagemodel.RequestClientInfo; |
| | | import com.vci.starter.web.pagemodel.SessionInfo; |
| | | import com.vci.starter.web.pagemodel.TokenVO; |
| | | import com.vci.starter.web.util.ApplicationContextProvider; |
| | | import com.vci.starter.web.util.JwtUtils; |
| | | import com.vci.starter.web.util.Md5; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.web.bo.LoginResultBO; |
| | | import com.vci.web.constant.CacheNameConstant; |
| | | import com.vci.web.dto.LoginUserDTO; |
| | | import com.vci.web.properties.WebProperties; |
| | | import com.vci.web.redis.RedisService; |
| | | import com.vci.web.service.LoginServiceI; |
| | | import com.vci.web.util.BusAnnotationUtil; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.lang.reflect.Method; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.*; |
| | | |
| | | /** |
| | | * 登录的服务 |
| | |
| | | /** |
| | | * 会话处理 |
| | | */ |
| | | @Autowired |
| | | @Resource |
| | | private VciSessionForLoginI sessionForLogin; |
| | | |
| | | /** |
| | | * 解锁任务 |
| | | */ |
| | | @Autowired |
| | | @Resource |
| | | private SmUserUnLockTaskManager unLockTaskManager; |
| | | |
| | | /** |
| | | * 权限管理的相关配置 |
| | | */ |
| | | @Autowired |
| | | @Resource |
| | | private VciSecurityManageProperties securityManageProperties; |
| | | |
| | | /** |
| | | * 用户查询服务,可以兼容老平台 |
| | | */ |
| | | @Autowired() |
| | | @Resource |
| | | private SmUserQueryServiceI userQueryService; |
| | | |
| | | /** |
| | | * 角色的查询服务,可以兼容老平台 |
| | | */ |
| | | @Autowired |
| | | @Resource |
| | | private SmRoleQueryServiceI roleQueryService; |
| | | |
| | | /** |
| | | * 权限的查询服务,可以兼容老平台 |
| | | */ |
| | | @Autowired |
| | | @Resource |
| | | private ISmFunctionQueryService functionQueryService; |
| | | |
| | | /** |
| | | * redis服务 |
| | | */ |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | /** |
| | | * 客户端配置文件 |
| | | */ |
| | | @Resource |
| | | private WebProperties webProperties; |
| | | |
| | | /** |
| | | * 平台调用客户端 |
| | | */ |
| | | @Resource |
| | | private PlatformClientUtil platformClientUtil; |
| | | |
| | | /** |
| | | * 执行登录 |
| | |
| | | LoginResultBO loginResult = new LoginResultBO(); |
| | | loginResult.setSuccess(false); |
| | | //1.判断用户的基本信息 |
| | | // VciBaseUtil.alertNotNull(userDTO, "登录信息", userDTO.getUserId(), "用户账号"); |
| | | // if (checkPassword) { |
| | | // VciBaseUtil.alertNotNull(userDTO.getPassword(), "登录密码"); |
| | | // } |
| | | //登录之前调用插件 |
| | | BusAnnotationUtil.callForAnnotation(VciLoginPlugin.class,VciLoginBefore.class,userDTO,clientInfo); |
| | | VciBaseUtil.alertNotNull(userDTO, "登录信息", userDTO.getUserId(), "用户账号"); |
| | | if (checkPassword) { |
| | | VciBaseUtil.alertNotNull(userDTO.getPassword(), "登录密码"); |
| | | } |
| | | |
| | | // String loginInfo = checkIsLogined(userDTO.getUserId()); |
| | | // if (!userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) { |
| | | // //需要看看是否已经登录了 |
| | | // if (StringUtils.isNotBlank(loginInfo)) { |
| | | // loginResult.setFailCode(USER_IS_LOGINED); |
| | | // loginResult.setFailMsg(loginInfo); |
| | | // return loginResult; |
| | | // } |
| | | // } |
| | | //2.获取用户的对象.这里需要兼容老平台和老pdm,老编码和老平台是一个表 |
| | | // SmUserVO user = userQueryService.getUserByUserId(userDTO.getUserId().trim()); |
| | | // if (user == null || StringUtils.isEmpty(user.getOid())) { |
| | | // loginResult.setFailCode(USER_NOT_FOUND); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | // return loginResult; |
| | | // } |
| | | //需要看看是否已经登录了 |
| | | String loginKey = CacheNameConstant.cacheKey(CacheNameConstant.VCI_USER_LOGIN, userDTO.getUserId()); |
| | | if(redisService.hasKey(loginKey) && !userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()){ |
| | | loginResult.setFailCode(USER_IS_LOGINED); |
| | | loginResult.setFailMsg("当前用户已经在其他地方登录!"); |
| | | return loginResult; |
| | | } |
| | | //说明已经登录了,那应该取消原来的登录 |
| | | if (redisService.hasKey(loginKey) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) { |
| | | redisService.deleteObject(CacheNameConstant.VCI_USER_LOGIN); |
| | | } |
| | | |
| | | //2.获取用户的对象. |
| | | SmUserVO user = getUserByUserId(userDTO.getUserId().trim()); |
| | | if (user == null || StringUtils.isBlank(user.getOid())) { |
| | | loginResult.setFailCode(USER_NOT_FOUND); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | return loginResult; |
| | | } |
| | | |
| | | //3、判断密码是否正确 |
| | | if (checkPassword) { |
| | | boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid()); |
| | | if (!passwordIsEqual) { |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("{}密码不正确", user.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //4、调用平台登录接口,进行登录 |
| | | LogonHandler handler = new LogonHandler(); |
| | | try { |
| | | LoginResult chkRes = handler.checkLogin(userDTO.getUserId(), userDTO.getPassword()); |
| | | loginResult.setFailCode(getErrorCode(chkRes)); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), String.valueOf(chkRes.auxInfo)}); |
| | | if(chkRes.state == LoginState.Error || chkRes.state == LoginState.Locked || chkRes.state == LoginState.Freeze){ |
| | | return loginResult; |
| | | } |
| | | } catch (Exception e) { |
| | | loginResult.setFailCode(SYSTEM_ERROR); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | return loginResult; |
| | | } |
| | | |
| | | //如果用户已经被停用和锁定,不能登录 |
| | | //如果用户的失效日期已经超过了当前时间,不能登录 |
| | | //只有新平台的用户才判断失效 |
| | | // if (FrameworkDataLCStatus.DISABLED.getValue().equals(user.getLcStatus())) { |
| | | // loginResult.setFailCode(USER_IS_DISABLED); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | // return loginResult; |
| | | // } |
| | | // if (userQueryService.checkUserLock(user, user.getPwdWrongCount())) { |
| | | // loginResult.setFailCode(USER_IS_LOCK); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | // return loginResult; |
| | | // } |
| | | // if (user.getDisabledate() != null) { |
| | | // //2021版本才有这个属性的值,当前这个没有这个值 |
| | | // Date disableDate = VciDateUtil.addOrSubDate(user.getDisabledate(), Calendar.DATE, 1); |
| | | // if (disableDate != null && disableDate.getTime() < System.currentTimeMillis()) { |
| | | // loginResult.setFailCode(USER_MORE_THAN_DISABLE_DATE); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | // return loginResult; |
| | | // } |
| | | // } |
| | | // if (user.getPwdWrongCount() == null) { |
| | | // user.setPwdWrongCount(0); |
| | | // } |
| | | // SmPasswordStrategyVO passwordStrategyVO = userQueryService.getPasswordStrategyVOByUserOid(user.getOid()); |
| | | // if (checkPassword) { |
| | | // boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid()); |
| | | // //3.判断用户的密码是否正确 |
| | | // if (!passwordIsEqual) { |
| | | // //前端需要先md5一次,然后后台再MD5一次, |
| | | // if (logger.isDebugEnabled()) { |
| | | // logger.debug("{}密码不正确", user.getId()); |
| | | // } |
| | | // if (passwordStrategyVO == null) { |
| | | // //可能数据问题没有设置密码策略 |
| | | // passwordStrategyVO = new SmPasswordStrategyVO(); |
| | | // passwordStrategyVO.setRetryTime(6); |
| | | // passwordStrategyVO.setLockTime(30); |
| | | // } |
| | | // if (passwordStrategyVO.getRetryTime() <= (user.getPwdWrongCount() + 1)) { |
| | | // user.setLockFlag(true); |
| | | // updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | // addUserToUnLock(userDTO.getUserId(), passwordStrategyVO.getLockTime()); |
| | | // updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | // loginResult.setFailCode(USER_PWD_LOCK); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), passwordStrategyVO.getLockTime() + ""}); |
| | | // return loginResult; |
| | | // } else { |
| | | // //还没有到锁定的次数 |
| | | // updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | // //5, 这是第一次错误,剩下的是 5- (0+1) |
| | | // loginResult.setFailCode(USER_PWD_NOT_EQUAL); |
| | | // loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), (passwordStrategyVO.getRetryTime() - (user.getPwdWrongCount() + 1)) + ""}); |
| | | // return loginResult; |
| | | // } |
| | | // } |
| | | // } |
| | | /**if (FrameworkDataLCStatus.DISABLED.getValue().equals(user.getLcStatus())) { |
| | | loginResult.setFailCode(USER_IS_DISABLED); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | return loginResult; |
| | | } |
| | | if (userQueryService.checkUserLock(user, user.getPwdWrongCount())) { |
| | | loginResult.setFailCode(USER_IS_LOCK); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | return loginResult; |
| | | } |
| | | if (user.getDisabledate() != null) { |
| | | //2021版本才有这个属性的值,当前这个没有这个值 |
| | | Date disableDate = VciDateUtil.addOrSubDate(user.getDisabledate(), Calendar.DATE, 1); |
| | | if (disableDate != null && disableDate.getTime() < System.currentTimeMillis()) { |
| | | loginResult.setFailCode(USER_MORE_THAN_DISABLE_DATE); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); |
| | | return loginResult; |
| | | } |
| | | } |
| | | |
| | | SmPasswordStrategyVO passwordStrategyVO = userQueryService.getPasswordStrategyVOByUserOid(user.getOid()); |
| | | if (checkPassword) { |
| | | boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid()); |
| | | //3.判断用户的密码是否正确 |
| | | if (!passwordIsEqual) { |
| | | //前端需要先md5一次,然后后台再MD5一次, |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("{}密码不正确", user.getId()); |
| | | } |
| | | if (passwordStrategyVO == null) { |
| | | //可能数据问题没有设置密码策略 |
| | | passwordStrategyVO = new SmPasswordStrategyVO(); |
| | | passwordStrategyVO.setRetryTime(6); |
| | | passwordStrategyVO.setLockTime(30); |
| | | } |
| | | if (passwordStrategyVO.getRetryTime() <= (user.getPwdWrongCount() + 1)) { |
| | | user.setLockFlag(true); |
| | | updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | addUserToUnLock(userDTO.getUserId(), passwordStrategyVO.getLockTime()); |
| | | updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | loginResult.setFailCode(USER_PWD_LOCK); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), passwordStrategyVO.getLockTime() + ""}); |
| | | return loginResult; |
| | | } else { |
| | | //还没有到锁定的次数 |
| | | updateUserPwdWrongCount(user.getOid(), user.getPwdWrongCount() + 1); |
| | | //5, 这是第一次错误,剩下的是 5- (0+1) |
| | | loginResult.setFailCode(USER_PWD_NOT_EQUAL); |
| | | loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), (passwordStrategyVO.getRetryTime() - (user.getPwdWrongCount() + 1)) + ""}); |
| | | return loginResult; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //检查是否该修改密码 |
| | | if (!clientInfo.isSso() && checkPassword) { |
| | | //最后修改时间+ 失效时间,大于等于当前日期,则需要马上修改密码 |
| | | Date currentDay = null; |
| | | try { |
| | | currentDay = VciDateUtil.getNow(VciDateUtil.DateFormat); |
| | | } catch (Throwable e) { |
| | | if (logger.isErrorEnabled()) { |
| | | logger.error("获取当前日期", e); |
| | | } |
| | | } |
| | | if (currentDay != null && passwordStrategyVO != null && passwordStrategyVO.getValidDay() != null) { |
| | | Date inValidDay = null; |
| | | if (user.getLastModifyPasswordTime() == null) { |
| | | //重来没有登录过 |
| | | loginResult.setMustChangePassword(true); |
| | | } else { |
| | | inValidDay = VciDateUtil.addOrSubDate(user.getLastModifyPasswordTime(), Calendar.DATE, passwordStrategyVO.getValidDay()); |
| | | if (inValidDay.getTime() <= (currentDay).getTime()) { |
| | | loginResult.setMustChangePassword(true); |
| | | } |
| | | } |
| | | if (!loginResult.isMustChangePassword()) { |
| | | if (VciDateUtil.addOrSubDate(inValidDay, Calendar.DATE, -(passwordStrategyVO.getRemindDay())).getTime() |
| | | <= (currentDay).getTime()) { |
| | | //您的密码还有{0}天过期,请及时修改密码 |
| | | long remainDay = VciDateUtil.getDaySub(inValidDay, currentDay); |
| | | loginResult.setPasswordInfo(MessageFormat.format(PASSWORD_REMAIN_DAY, new String[]{String.valueOf(remainDay)})); |
| | | } |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | //说明密码正确的 |
| | | // if (logger.isDebugEnabled()) { |
| | | // logger.debug("{}的密码正确", user.getId()); |
| | | // } |
| | | // user.setLastLoginTime(new Date()); |
| | | // user.setPwdWrongCount(0); |
| | | SmUserVO user = new SmUserVO(); |
| | | user.setId("1"); |
| | | user.setName("1"); |
| | | user.setOid("1"); |
| | | user.setUserType("1"); |
| | | user.setUserTypeText("1"); |
| | | user.setSecretGrade(1); |
| | | user.setSecretGradeText("1"); |
| | | user.setSex("1"); |
| | | user.setSexText("1"); |
| | | user.setPkPerson("1"); |
| | | user.setPkPersonName("1"); |
| | | user.setPkDepartment("1"); |
| | | user.setPkDepartmentName("1"); |
| | | user.setPkDuty("1"); |
| | | user.setPkDutyName("1"); |
| | | user.setEmail("1"); |
| | | user.setTel("1"); |
| | | user.setRtxNo("1"); |
| | | user.setIMNo("1"); |
| | | |
| | | |
| | | |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("{}的密码正确", user.getId()); |
| | | } |
| | | user.setLastLoginTime(new Date()); |
| | | user.setPwdWrongCount(0); |
| | | |
| | | SessionInfo sessionInfo = new SessionInfo(); |
| | | //拷贝用户的新到session会话中 |
| | | copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode()); |
| | | //拷贝请求信息到session会话中 |
| | | copyRequest2SessionInfo(clientInfo, sessionInfo); |
| | | //查询所有的角色 |
| | | // List<SmRoleVO> roleVOList = roleQueryService.listRoleByUserOid(user.getOid(), null); |
| | | // if (!CollectionUtils.isEmpty(roleVOList)) { |
| | | // Map<String, String> roleOidNameMap = roleVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t.getName())); |
| | | // sessionInfo.setRolesName(roleOidNameMap); |
| | | // } else { |
| | | // sessionInfo.setRolesName(new HashMap()); |
| | | // } |
| | | |
| | | /** //查询所有的角色 |
| | | List<SmRoleVO> roleVOList = roleQueryService.listRoleByUserOid(user.getOid(), null); |
| | | if (!CollectionUtils.isEmpty(roleVOList)) { |
| | | Map<String, String> roleOidNameMap = roleVOList.stream().collect(Collectors.toMap(s -> s.getOid(), t -> t.getName())); |
| | | sessionInfo.setRolesName(roleOidNameMap); |
| | | } else { |
| | | sessionInfo.setRolesName(new HashMap()); |
| | | } |
| | | //查询所有的权限 |
| | | // List<SmFunctionVO> functionVOList = functionQueryService.listFunctionByUserOid(user.getOid(), null, ResourceControlTypeEnum.BS); |
| | | // if (!CollectionUtils.isEmpty(functionVOList)) { |
| | | // List<String> functionOidList = functionVOList.stream().map(s -> s.getOid()).collect(Collectors.toList()); |
| | | // sessionInfo.setFunctionOids(functionOidList); |
| | | // } else { |
| | | // sessionInfo.setFunctionOids(new ArrayList()); |
| | | // } |
| | | List<SmFunctionVO> functionVOList = functionQueryService.listFunctionByUserOid(user.getOid(), null, ResourceControlTypeEnum.BS); |
| | | if (!CollectionUtils.isEmpty(functionVOList)) { |
| | | List<String> functionOidList = functionVOList.stream().map(s -> s.getOid()).collect(Collectors.toList()); |
| | | sessionInfo.setFunctionOids(functionOidList); |
| | | } else { |
| | | sessionInfo.setFunctionOids(new ArrayList()); |
| | | }*/ |
| | | |
| | | loginResult.setSuccess(true); |
| | | //检查是否该修改密码 |
| | | // if (!clientInfo.isSso() && checkPassword) { |
| | | // //最后修改时间+ 失效时间,大于等于当前日期,则需要马上修改密码 |
| | | // Date currentDay = null; |
| | | // try { |
| | | // currentDay = VciDateUtil.getNow(VciDateUtil.DateFormat); |
| | | // } catch (Throwable e) { |
| | | // if (logger.isErrorEnabled()) { |
| | | // logger.error("获取当前日期", e); |
| | | // } |
| | | // } |
| | | // if (currentDay != null && passwordStrategyVO != null && passwordStrategyVO.getValidDay() != null) { |
| | | // Date inValidDay = null; |
| | | // if (user.getLastModifyPasswordTime() == null) { |
| | | // //重来没有登录过 |
| | | // loginResult.setMustChangePassword(true); |
| | | // } else { |
| | | // inValidDay = VciDateUtil.addOrSubDate(user.getLastModifyPasswordTime(), Calendar.DATE, passwordStrategyVO.getValidDay()); |
| | | // if (inValidDay.getTime() <= (currentDay).getTime()) { |
| | | // loginResult.setMustChangePassword(true); |
| | | // } |
| | | // } |
| | | // if (!loginResult.isMustChangePassword()) { |
| | | // if (VciDateUtil.addOrSubDate(inValidDay, Calendar.DATE, -(passwordStrategyVO.getRemindDay())).getTime() |
| | | // <= (currentDay).getTime()) { |
| | | // //您的密码还有{0}天过期,请及时修改密码 |
| | | // long remainDay = VciDateUtil.getDaySub(inValidDay, currentDay); |
| | | // loginResult.setPasswordInfo(MessageFormat.format(PASSWORD_REMAIN_DAY, new String[]{String.valueOf(remainDay)})); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | //原本想使用jwt来生成token,但是有以下问题 |
| | | //1.jwt不能处理注销的问题 |
| | | //2.jwt生成的token太长了 |
| | | //3.因为本平台不是互联网系统,只需要解决分布式用户信息的获取和权限的校验即可。 |
| | | //4.平台引用了redis和数据库来存储会话的信息,只需要保证根据token能获取到会话信息即可 |
| | | //5.在服务启动的时候,将会话信息清除,在注销的时候将会话信息清除 |
| | | //uuid在高并发的情况下会重复,但是传统软件并发很小,所以出现的重复的概率很小 |
| | | |
| | | sessionInfo.setToken(Md5.md5(VciBaseUtil.getPk() + "_" + user.getId())); |
| | | loginResult.setSessionInfo(sessionInfo); |
| | | // updateUserForLoginSuccess(user.getOid()); |
| | | // if (StringUtils.isNotBlank(loginInfo) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) { |
| | | // //说明已经登录了,那应该取消原来的登录 |
| | | // popUser(userDTO.getUserId()); |
| | | // } |
| | | |
| | | //添加到会话信息 |
| | | // saveSessionInfo(sessionInfo); |
| | | saveSessionInfo(sessionInfo); |
| | | |
| | | //登录后执行 |
| | | // BusAnnotationUtil.callForAnnotation(VciLoginPlugin.class,VciLoginAfter.class,userDTO,clientInfo,loginResult); |
| | | return loginResult; |
| | | } |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * @param userId userId |
| | | * @Return com.vci.frameworkcore.pagemodel.SmUserVO |
| | | */ |
| | | private SmUserVO getUserByUserId(String userId) { |
| | | String userKey = CacheNameConstant.cacheKey(CacheNameConstant.VCI_USER,userId); |
| | | String userOid = redisService.getCacheObject(userKey); |
| | | String oidKey = CacheNameConstant.cacheKey(CacheNameConstant.VCI_USER_OID, userOid); |
| | | SmUserVO userVO = redisService.getCacheObject(oidKey); |
| | | if(userVO == null || StringUtils.isBlank(userVO.getOid())){ |
| | | userVO = userQueryService.getUserByUserId(userId); |
| | | } |
| | | return userVO; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 校验是否登录 |
| | | * @param userId 用户名 |
| | | * @return 已经登录时, |
| | | */ |
| | | private String checkIsLogined(String userId) { |
| | | if(sessionForLogin == null){ |
| | | throw new VciBaseException("没有配置会话存储的服务"); |
| | | } |
| | | return sessionForLogin.checkIsLogined(userId); |
| | | } |
| | | |
| | | /** |
| | | * 把以前的登录信息移除 |
| | | * @param userId 用户名 |
| | | */ |
| | | private void popUser(String userId){ |
| | | if(sessionForLogin == null){ |
| | | throw new VciBaseException("没有配置会话存储的服务"); |
| | | } |
| | | sessionForLogin.popUser(userId); |
| | | } |
| | | |
| | | /** |
| | | * 保存会话信息 |
| | |
| | | if(sessionForLogin == null){ |
| | | throw new VciBaseException("没有配置会话存储的服务"); |
| | | } |
| | | //将权限信息,放入redis缓存中。以防止session中的信息过多,存入数据库中出现错误 |
| | | redisService.setCacheList(sessionInfo.getToken(),sessionInfo.getFunctionOids()); |
| | | redisService.expire(sessionInfo.getToken(), 1, TimeUnit.HOURS); |
| | | |
| | | sessionInfo.setFunctionOids(new ArrayList<>()); |
| | | sessionForLogin.saveSessionInfo(sessionInfo); |
| | | } |
| | | |
| | |
| | | sessionInfo.setRtxNo(user.getRtxNo()); |
| | | sessionInfo.setIMId(user.getIMNo()); |
| | | sessionInfo.setPortalId(user.getId()); |
| | | |
| | | // sessionInfo.setWorkNo(user.getWorkNo()); |
| | | // sessionInfo.setWorkTypeOid(user.getPkWorkType()); |
| | | // sessionInfo.setWorkTypeName(user.getPkWorkTypeText()); |
| | | } |
| | | |
| | | /** |
| | |
| | | private void updateUserForLoginSuccess(String userOid){ |
| | | userQueryService.updateUserLoginTime(userOid); |
| | | } |
| | | |
| | | /** |
| | | * 创建许可的信息 |
| | | * |
| | | * @param sessionInfo session的信息 |
| | | * @return 许可信息 |
| | | */ |
| | | @Override |
| | | public TokenVO createToken(SessionInfo sessionInfo) { |
| | | return createToken(TokenKeyConstant.TOKEN_KEY_PREFIX_IN_REDIS, sessionInfo); |
| | | } |
| | | |
| | | /** |
| | | * 创建许可的信息 |
| | | * @param key token在redis中的key |
| | | * @param sessionInfo session的信息 |
| | | * @return 许可信息 |
| | | */ |
| | | @Override |
| | | public TokenVO createToken(String key, SessionInfo sessionInfo) { |
| | | if(StringUtils.isBlank(sessionInfo.getToken())) { |
| | | String token = Md5.md5(VciBaseUtil.getPk() + "_" + sessionInfo.getUserId()); |
| | | sessionInfo.setToken(token); |
| | | } |
| | | if(StringUtils.isBlank(key)){ |
| | | key = TokenKeyConstant.TOKEN_KEY_PREFIX_IN_REDIS; |
| | | } |
| | | refreshToken(key, sessionInfo); |
| | | Map<String,Object> claimsMap = new HashMap<>(); |
| | | claimsMap.put(TokenKeyConstant.JWT_TOKEN_KEY,sessionInfo.getToken()); |
| | | claimsMap.put(TokenKeyConstant.JWT_USER_KEY,sessionInfo.getUserOid()); |
| | | claimsMap.put(TokenKeyConstant.JWT_USER_NAME_KEY,sessionInfo.getUserName()); |
| | | claimsMap.put(TokenKeyConstant.JWT_USER_CODE_KEY,sessionInfo.getUserId()); |
| | | TokenVO tokenVO = new TokenVO(); |
| | | tokenVO.setAccessToken(JwtUtils.createToken(claimsMap)); |
| | | tokenVO.setExpireTime(TokenKeyConstant.EXPIRATION); |
| | | return tokenVO; |
| | | } |
| | | |
| | | /** |
| | | * 刷新token |
| | | * @param sessionInfo session的信息 |
| | | */ |
| | | @Override |
| | | public void refreshToken(SessionInfo sessionInfo) { |
| | | refreshToken(TokenKeyConstant.TOKEN_KEY_PREFIX_IN_REDIS, sessionInfo); |
| | | } |
| | | |
| | | /** |
| | | * 刷新token |
| | | * @param key token在redis中的key |
| | | * @param sessionInfo session的信息 |
| | | */ |
| | | @Override |
| | | public void refreshToken(String key, SessionInfo sessionInfo) { |
| | | if(sessionInfo!=null && StringUtils.isNotBlank(sessionInfo.getToken())){ |
| | | if(StringUtils.isBlank(key)){ |
| | | key = TokenKeyConstant.TOKEN_KEY_PREFIX_IN_REDIS; |
| | | } |
| | | String redisKey = key + sessionInfo.getToken(); |
| | | redisService.setCacheObject(redisKey, sessionInfo, webProperties.getClientSessionAliveMax()!=0?webProperties.getClientSessionAliveMax(): TokenKeyConstant.EXPIRATION, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取登录错误码 |
| | | * @param chkRes 平台登录校验结果 |
| | | * @Return java.lang.String |
| | | */ |
| | | public String getErrorCode(LoginResult chkRes){ |
| | | String message = ""; |
| | | switch(chkRes.state.value()) |
| | | { |
| | | case 0: |
| | | return ""; |
| | | case 1: |
| | | return LOGIN_SUCCESS; |
| | | case 10: |
| | | return USER_NOT_FOUND; |
| | | case 11: |
| | | return USER_PWD_NOT_EQUAL; |
| | | case 12: |
| | | return USER_IS_DISABLED; |
| | | case 13: |
| | | return USER_IS_LOCK; |
| | | case 14: |
| | | return PASSWORD_INIT; |
| | | case 15: |
| | | return PASSWORD_REMAIN_DAY; |
| | | case 16: |
| | | return PASSWORD_EXPIRE; |
| | | case 17: |
| | | return PASSWORD_POLICY_UPDATED; |
| | | case 20: |
| | | return SYSTEM_ERROR; |
| | | default: |
| | | message = SYSTEM_ERROR; |
| | | break; |
| | | } |
| | | return message; |
| | | } |
| | | } |