From cc6354cee46ff8facbd16c8919f2616c9031acdb Mon Sep 17 00:00:00 2001 From: yuxc <yuxc@vci-tech.com> Date: 星期五, 21 六月 2024 10:19:59 +0800 Subject: [PATCH] 1、三元账号验证修改,以及获取数据修改 --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java | 507 ++++++++++++++++++++++++++++++++----------------------- 1 files changed, 296 insertions(+), 211 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..aba5f04 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,24 +1,37 @@ package com.vci.web.service.impl; +import com.vci.client.mw.ClientSessionUtility; +import com.vci.corba.common.PLException; +import com.vci.corba.common.data.InvocationInfo; +import com.vci.corba.framework.data.DeptInfo; +import com.vci.corba.framework.data.LoginResult; +import com.vci.corba.framework.data.LoginState; +import com.vci.corba.framework.data.MachineInfo; import com.vci.frameworkcore.ajaxTask.SmUserUnLockTask; import com.vci.frameworkcore.ajaxTask.SmUserUnLockTaskManager; import com.vci.frameworkcore.compatibility.ISmFunctionQueryService; import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI; import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; +import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum; +import com.vci.frameworkcore.pagemodel.SmFunctionVO; 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.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.util.ApplicationContextProvider; -import com.vci.starter.web.util.Md5; -import com.vci.starter.web.util.VciBaseUtil; +import com.vci.starter.web.pagemodel.TokenVO; +import com.vci.starter.web.util.*; 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; @@ -26,8 +39,13 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import javax.annotation.Resource; import java.lang.reflect.Method; +import java.util.Date; +import java.util.List; import java.util.Map; + +import static com.vci.frameworkcore.constant.FrameWorkBusLangCodeConstant.*; /** * 鐧诲綍鐨勬湇鍔� @@ -45,38 +63,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 +137,229 @@ 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 userIdTokenKey = CacheNameConstant.cacheKey(CacheNameConstant.USERID_TOKEN_KEY, userDTO.getUserId().trim()); + if(redisService.hasKey(userIdTokenKey) && !userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()){ + loginResult.setFailCode(USER_IS_LOGINED); + loginResult.setFailMsg("褰撳墠鐢ㄦ埛宸茬粡鍦ㄥ叾浠栧湴鏂圭櫥褰曪紒"); + return loginResult; + } + //璇存槑宸茬粡鐧诲綍浜嗭紝閭e簲璇ュ彇娑堝師鏉ョ殑鐧诲綍 + if (redisService.hasKey(userIdTokenKey) && userDTO.isForceLogin() && securityManageProperties.isUserOneLogin()) { + String tokenKey = redisService.getCacheObject(userIdTokenKey); + redisService.deleteObject(tokenKey); + redisService.deleteObject(userIdTokenKey); + } + + //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紝杩涜鐧诲綍 + MachineInfo machine = getMachieInfo(clientInfo); + machine.country = clientInfo.getCountry(); + machine.language = clientInfo.getLanguage(); + machine.osUser = clientInfo.getOsUser(); + machine.machine = clientInfo.getMachine(); + + String token = null; + try { + LoginResult chkRes = platformClientUtil.getFrameworkService().checkLogin(userDTO.getUserId(),userDTO.getPassword(), machine); + 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; + } + token = chkRes.token; + } catch (Exception e) { + loginResult.setFailCode(SYSTEM_ERROR); + loginResult.setFailMsgArray(new String[]{userDTO.getUserId()}); + return loginResult; + } + if(StringUtils.isBlank(token)){ + loginResult.setFailMsg(TOKEN_EMPTY); + 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(); + sessionInfo.setToken(token); + + //鍒濆鍖栧钩鍙扮殑token + sessionForLogin.initInvocationInfo(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()); -// } + + //鑾峰彇浜哄憳鎵�灞炵殑閮ㄩ棬淇℃伅 + try { + DeptInfo deptInfo = platformClientUtil.getFrameworkService().fetchDeptByUserId(user.getOid()); + sessionInfo.setDeptOid(deptInfo.id); + sessionInfo.setDeptName(deptInfo.name); + sessionInfo.setDeptNum(deptInfo.num); + } catch (PLException e) { + throw new VciBaseException("鑾峰彇鐢ㄦ埛鎵�灞為儴闂ㄥけ璐�:"+e.getMessage()); + } + + /** //鏌ヨ鎵�鏈夌殑瑙掕壊 + 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()); -// } - - 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()); -// } + 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()); + }*/ //娣诲姞鍒颁細璇濅俊鎭� -// saveSessionInfo(sessionInfo); + TokenVO tokenVO = saveSessionInfo(sessionInfo); + loginResult.setTokenVO(tokenVO); - //鐧诲綍鍚庢墽琛� -// BusAnnotationUtil.callForAnnotation(VciLoginPlugin.class,VciLoginAfter.class,userDTO,clientInfo,loginResult); + loginResult.setSuccess(true); return loginResult; + } + + private MachineInfo getMachieInfo(RequestClientInfo clientInfo) { + MachineInfo machine = new MachineInfo(); + machine.country = clientInfo.getCountry(); + machine.language = clientInfo.getLanguage(); + machine.osUser = clientInfo.getOsUser(); + machine.machine = clientInfo.getMachine(); + return machine; + } + + /** + * 鑾峰彇鐢ㄦ埛淇℃伅 + * @param userId userId + * @Return com.vci.frameworkcore.pagemodel.SmUserVO + */ + private SmUserVO getUserByUserId(String userId) { + return userQueryService.getUserByUserId(userId); } @@ -357,38 +427,18 @@ } } - /** - * 鏍¢獙鏄惁鐧诲綍 - * @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); - } /** * 淇濆瓨浼氳瘽淇℃伅 * @param sessionInfo 浼氳瘽淇℃伅 */ - private void saveSessionInfo(SessionInfo sessionInfo){ + private TokenVO saveSessionInfo(SessionInfo sessionInfo){ if(sessionForLogin == null){ throw new VciBaseException("娌℃湁閰嶇疆浼氳瘽瀛樺偍鐨勬湇鍔�"); } - sessionForLogin.saveSessionInfo(sessionInfo); + WebThreadLocalUtil.setCurrentUserSessionInfoInThread(sessionInfo); + return sessionForLogin.createToken(sessionInfo); } /** @@ -438,10 +488,7 @@ sessionInfo.setRtxNo(user.getRtxNo()); sessionInfo.setIMId(user.getIMNo()); sessionInfo.setPortalId(user.getId()); - -// sessionInfo.setWorkNo(user.getWorkNo()); -// sessionInfo.setWorkTypeOid(user.getPkWorkType()); -// sessionInfo.setWorkTypeName(user.getPkWorkTypeText()); + sessionInfo.setLastLoginTime(user.getLastLoginTime()!=null?user.getLastLoginTime().getTime(): VciDateUtil.getNowTime()); } /** @@ -475,4 +522,42 @@ private void updateUserForLoginSuccess(String userOid){ userQueryService.updateUserLoginTime(userOid); } + + /** + * 鑾峰彇鐧诲綍閿欒鐮� + * @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