From 7664ba49025a6c549885fc6019e4d3c1886f45a6 Mon Sep 17 00:00:00 2001 From: dangsn <dangsn@chicecm.com> Date: 星期五, 07 六月 2024 14:26:16 +0800 Subject: [PATCH] 调整项目BUG --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java | 527 ++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 324 insertions(+), 203 deletions(-) diff --git a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java index eef1f76..17aa5b1 100644 --- a/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java +++ b/Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java @@ -1,5 +1,8 @@ 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; @@ -7,27 +10,41 @@ 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.*; /** * 鐧诲綍鐨勬湇鍔� @@ -45,38 +62,56 @@ /** * 浼氳瘽澶勭悊 */ - @Autowired + @Resource private VciSessionForLoginI sessionForLogin; /** * 瑙i攣浠诲姟 */ - @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; /** * 鎵ц鐧诲綍 @@ -101,195 +136,200 @@ 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.鑾峰彇鐢ㄦ埛鐨勫璞�.杩欓噷闇�瑕佸吋瀹硅�佸钩鍙板拰鑰乸dm锛岃�佺紪鐮佸拰鑰佸钩鍙版槸涓�涓〃 -// 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; + } + //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍 + 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銆佽皟鐢ㄥ钩鍙扮櫥褰曟帴鍙o紝杩涜鐧诲綍 + 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涓�娆★紝鐒跺悗鍚庡彴鍐峂D5涓�娆★紝 -// 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涓�娆★紝鐒跺悗鍚庡彴鍐峂D5涓�娆★紝 + 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)})); + } + } + } + }*/ + //璇存槑瀵嗙爜姝g‘鐨� -// 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(); //鎷疯礉鐢ㄦ埛鐨勬柊鍒皊ession浼氳瘽涓� copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode()); //鎷疯礉璇锋眰淇℃伅鍒皊ession浼氳瘽涓� 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)})); -// } -// } -// } -// } - - //鍘熸湰鎯充娇鐢╦wt鏉ョ敓鎴恡oken锛屼絾鏄湁浠ヤ笅闂 - //1.jwt涓嶈兘澶勭悊娉ㄩ攢鐨勯棶棰� - //2.jwt鐢熸垚鐨則oken澶暱浜� - //3.鍥犱负鏈钩鍙颁笉鏄簰鑱旂綉绯荤粺锛屽彧闇�瑕佽В鍐冲垎甯冨紡鐢ㄦ埛淇℃伅鐨勮幏鍙栧拰鏉冮檺鐨勬牎楠屽嵆鍙�� - //4.骞冲彴寮曠敤浜唕edis鍜屾暟鎹簱鏉ュ瓨鍌ㄤ細璇濈殑淇℃伅锛屽彧闇�瑕佷繚璇佹牴鎹畉oken鑳借幏鍙栧埌浼氳瘽淇℃伅鍗冲彲 - //5.鍦ㄦ湇鍔″惎鍔ㄧ殑鏃跺�欙紝灏嗕細璇濅俊鎭竻闄わ紝鍦ㄦ敞閿�鐨勬椂鍊欏皢浼氳瘽淇℃伅娓呴櫎 - //uuid鍦ㄩ珮骞跺彂鐨勬儏鍐典笅浼氶噸澶嶏紝浣嗘槸浼犵粺杞欢骞跺彂寰堝皬锛屾墍浠ュ嚭鐜扮殑閲嶅鐨勬鐜囧緢灏� - sessionInfo.setToken(Md5.md5(VciBaseUtil.getPk() + "_" + user.getId())); loginResult.setSessionInfo(sessionInfo); -// updateUserForLoginSuccess(user.getOid()); -// if (StringUtils.isNotBlank(loginInfo) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) { -// //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍 -// 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; } @@ -357,28 +397,7 @@ } } - /** - * 鏍¢獙鏄惁鐧诲綍 - * @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); - } /** * 淇濆瓨浼氳瘽淇℃伅 @@ -388,6 +407,11 @@ 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); } @@ -438,10 +462,6 @@ sessionInfo.setRtxNo(user.getRtxNo()); sessionInfo.setIMId(user.getIMNo()); sessionInfo.setPortalId(user.getId()); - -// sessionInfo.setWorkNo(user.getWorkNo()); -// sessionInfo.setWorkTypeOid(user.getPkWorkType()); -// sessionInfo.setWorkTypeName(user.getPkWorkTypeText()); } /** @@ -475,4 +495,105 @@ 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鍦╮edis涓殑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鍦╮edis涓殑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; + } } -- Gitblit v1.9.3