From 7b3d5fb08fdbd2ce574c3b9ab666c8c7082be728 Mon Sep 17 00:00:00 2001 From: ludc Date: 星期五, 06 九月 2024 15:38:35 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java | 684 ++++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 460 insertions(+), 224 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..fbe28cb 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,33 +1,52 @@ package com.vci.web.service.impl; +import com.vci.corba.common.PLException; +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.SmPwdStrategyQueryServiceI; import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; -import com.vci.frameworkcore.pagemodel.SmUserVO; +import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum; +import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus; +import com.vci.pagemodel.SmFunctionVO; +import com.vci.pagemodel.SmPasswordStrategyVO; +import com.vci.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.web.bo.LoginResultBO; -import com.vci.web.dto.LoginUserDTO; +import com.vci.starter.web.pagemodel.TokenVO; +import com.vci.starter.web.util.*; + +import com.vci.bo.LoginResultBO; +import com.vci.constant.CacheNameConstant; +import com.vci.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.Func; +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.Map; +import java.text.MessageFormat; +import java.util.*; +import java.util.stream.Collectors; + +import static com.vci.constant.FrameWorkBusLangCodeConstant.*; /** * 鐧诲綍鐨勬湇鍔� @@ -45,38 +64,68 @@ /** * 浼氳瘽澶勭悊 */ - @Autowired + @Resource private VciSessionForLoginI sessionForLogin; /** * 瑙i攣浠诲姟 */ - @Autowired + @Resource private SmUserUnLockTaskManager unLockTaskManager; /** * 鏉冮檺绠$悊鐨勭浉鍏抽厤缃� */ - @Autowired + @Resource private VciSecurityManageProperties securityManageProperties; /** * 鐢ㄦ埛鏌ヨ鏈嶅姟锛屽彲浠ュ吋瀹硅�佸钩鍙� */ - @Autowired() + @Resource private SmUserQueryServiceI userQueryService; + + /** + * 瀵嗙爜绛栫暐鏌ヨ鏈嶅姟 + */ + @Resource + private SmPwdStrategyQueryServiceI pwdStrategyQueryService; + + /** + * 鍔熻兘鑿滃崟鐨勬煡璇㈡湇鍔� + */ + @Resource + private ISmFunctionQueryService functionQueryService; /** * 瑙掕壊鐨勬煡璇㈡湇鍔★紝鍙互鍏煎鑰佸钩鍙� */ - @Autowired - private SmRoleQueryServiceI roleQueryService; + //@Resource + //private SmRoleQueryServiceI roleQueryService; /** * 鏉冮檺鐨勬煡璇㈡湇鍔★紝鍙互鍏煎鑰佸钩鍙� */ - @Autowired - private ISmFunctionQueryService functionQueryService; + //@Resource + //private ISmFunctionQueryService functionQueryService; + + /** + * redis鏈嶅姟 + */ + @Resource + private RedisService redisService; + + /** + * 瀹㈡埛绔厤缃枃浠� + */ + @Resource + private WebProperties webProperties; + + /** + * 骞冲彴璋冪敤瀹㈡埛绔� + */ + @Resource + private PlatformClientUtil platformClientUtil; /** * 鎵ц鐧诲綍 @@ -85,7 +134,7 @@ * @throws VciBaseException 鐧诲綍鍙戠敓寮傚父鐨勬椂鍊欏嚭鐜颁簡閿欒 */ @Override - public LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws VciBaseException { + public LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws PLException { return login(userDTO,clientInfo,true); } @@ -97,201 +146,375 @@ * @return 鎵ц缁撴灉 * @throws VciBaseException 鍙傛暟閿欒锛岀敤鎴蜂笉鑳界櫥褰曠瓑浼氭姏鍑哄紓甯� */ - private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword) throws VciBaseException { + private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*鍗曠偣鐧诲綍涓嶉渶瑕佹牎楠屽瘑鐮�*/) throws VciBaseException, PLException { 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); -// 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; -// } + //1.鍒ゆ柇鐢ㄦ埛鐨勫熀鏈俊鎭� + VciBaseUtil.alertNotNull(userDTO, "鐧诲綍淇℃伅", userDTO.getUserId(), "鐢ㄦ埛璐﹀彿"); + if (checkPassword) { + VciBaseUtil.alertNotNull(userDTO.getPassword(), "鐧诲綍瀵嗙爜"); + } + //2銆佸垽鏂崟璁惧鐧诲綍,鏄惁宸茬粡鐧诲綍浜� + 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); + } + + //3.鑾峰彇鐢ㄦ埛鐨勫璞★紙瀵硅薄涓寘鍚鑹查儴闂ㄨ繕鏈夊瘑鐮佺瓥鐣ヤ俊鎭�(褰撳墠鐢ㄦ埛娌¤缃瘑鐮佺瓥鐣ュ氨鏄彇鐨勯粯璁ゅ瘑鐮佺瓥鐣�)锛� + 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; + } + + //4銆佸垽鏂瘑鐮佹槸鍚︽纭紙骞冲彴鐨刢heckLogin鏂规硶濂藉儚鏈夊瀵嗙爜杩涜姣斿鐨勬柟娉曪級 + /*if (checkPassword) { + boolean passwordIsEqual = userQueryService.checkPasswordEqual(userDTO.getPassword(), user.getOid()); + if (!passwordIsEqual) { + if (logger.isDebugEnabled()) { + logger.debug("{}瀵嗙爜涓嶆纭�", user.getId()); + } + } + }*/ + + //5銆佽皟鐢ㄥ钩鍙扮櫥褰曟帴鍙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 { + //鍓嶇浼犺繃鏉ョ殑瀵嗙爜鏄粡杩囧姞瀵嗕紶杈撶殑锛屾墍浠ラ渶瑕佹寜鐓х害瀹氳В瀵嗭紝鍐嶄紶缁欏钩鍙拌繘琛屾瘮瀵� + userDTO.setPassword(Func.decryptAes(userDTO.getPassword(),"daliantan0v0vcip")); + LoginResult chkRes = platformClientUtil.getFrameworkService().checkLogin(userDTO.getUserId(),userDTO.getPassword(), machine); + loginResult.setFailCode(getErrorCode(chkRes)); + //loginResult.setFailMsgArray(new String[]{userDTO.getUserId(), String.valueOf(chkRes.auxInfo)}); + loginResult.setFailMsgArray(new String[]{String.valueOf(chkRes.auxInfo)}); + //鏍规嵁涓嶅悓鐘舵�佸鐞嗗钩鍙拌繑鍥炵殑淇℃伅 + if(chkRes.state.equals(LoginState.Error) || chkRes.state.equals(LoginState.Locked) || chkRes.state.equals(LoginState.Freeze)){ + return loginResult; + } + //鍏充簬瀵嗙爜绛栫暐鐩稿叧鐨勮繑鍥炰俊鎭鐞� + if(chkRes.state.equals(LoginState.InitialPW)){ + loginResult.setMustChangePassword(true); + loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜鏄鐞嗗憳鍒濆鐨勫瘑鐮侊紝闇�瑕佷慨鏀瑰瘑鐮佹墠鑳借繘琛屽叾瀹冩搷浣�!"); + return loginResult; + }else if(chkRes.state.equals(LoginState.PWExpired)){ + //闇�瑕佺珛鍗充慨鏀瑰瘑鐮� + loginResult.setMustChangePassword(true); + loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜宸茬粡杩囨湡,璇疯繘琛屼慨鏀癸紒"); + return loginResult; + }else if(chkRes.state.equals(LoginState.PWPolicyUpdated)){ + //绛栫暐淇敼锛岀洿鎺ヨ繑鍥為檺鍒剁敤鎴峰悗缁搷浣� + loginResult.setMustChangePassword(true); + loginResult.setPasswordInfo("鎮ㄧ殑瀵嗙爜绛栫暐宸茬粡淇敼锛岄渶瑕佷慨鏀瑰瘑鐮佹墠鑳借繘琛屽叾瀹冩搷浣�!"); + return loginResult; + }else if(chkRes.state.equals(LoginState.PWWillExpire)){ + loginResult.setPasswordInfo(String.format("鎮ㄧ殑瀵嗙爜鏈夋晥鏈熻繕鏈�%s澶�,璇锋敞鎰忎慨鏀�!",chkRes.auxInfo)); + } + 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; + } + //6銆佺櫥褰曟垚鍔熶箣鍚庨渶瑕佸鐞嗙殑閫昏緫 + user.setLastLoginTime(new Date());//鏈�鍚庣櫥褰曟椂闂� + user.setPwdWrongCount(0);//瀵嗙爜閿欒娆℃暟娓�0 + //澶勭悊鐢ㄦ埛鐧诲綍鎴愬姛鐨剆ession + SessionInfo sessionInfo = new SessionInfo(); + sessionInfo.setToken(token); + //鍒濆鍖栧钩鍙扮殑token + sessionForLogin.initInvocationInfo(sessionInfo); + //鎷疯礉鐢ㄦ埛鍒版柊鐨剆ession浼氳瘽涓� + copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode()); + //鎷疯礉璇锋眰淇℃伅鍒皊ession浼氳瘽涓� + copyRequest2SessionInfo(clientInfo, sessionInfo); + + //鏌ョ湅浜嗗钩鍙扮殑鐧诲綍鏂规硶鍏跺疄鏄湁澶勭悊閮ㄩ棬瑙掕壊绛夌浉鍏充俊鎭殑浣嗘槸涓嶇煡閬撲负浠�涔堟棤娉曡幏鍙栧埌 + //閮ㄩ棬淇℃伅澶勭悊 + sessionInfo.setDeptOid(user.getPkDepartment()); + sessionInfo.setDeptName(user.getPkDepartmentName()); + sessionInfo.setDeptNum(user.getPkDepartmentNum()); + //瑙掕壊淇℃伅澶勭悊 + String roleOids = user.getPkPerson(); + String roleNames = user.getPkPersonName(); + HashMap<String, String> roleOidNameMap = new HashMap<>(); + if(Func.isNotBlank(roleOids) && Func.isNotBlank(roleOids)){ + String[] oids = roleOids.split(","); + String[] names = roleNames.split(","); + for (int i = 0; i < oids.length; i++) { + roleOidNameMap.put(oids[i],names[i]); + } + } + sessionInfo.setRolesName(roleOidNameMap); + + //鏌ヨ鎵�鏈夌殑鏉冮檺 + 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()); + } + + //娣诲姞鍒颁細璇濅俊鎭� + TokenVO tokenVO = saveSessionInfo(sessionInfo); + loginResult.setTokenVO(tokenVO); + loginResult.setSuccess(true); + return loginResult; + } + + /** + * 鐧诲綍_搴熷純鏂规硶锛屼富瑕佺敤鏉ュ浠� + * @param userDTO 鐢ㄦ埛鐨勬暟鎹紶杈撳璞� + * @param clientInfo 瀹㈡埛绔殑淇℃伅 + * @param checkPassword 鏄惁鏍¢獙瀵嗙爜 + * @return 鎵ц缁撴灉 + * @throws VciBaseException 鍙傛暟閿欒锛岀敤鎴蜂笉鑳界櫥褰曠瓑浼氭姏鍑哄紓甯� + */ + private LoginResultBO login_old(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*鍗曠偣鐧诲綍涓嶉渶瑕佹牎楠屽瘑鐮�*/) throws VciBaseException, PLException { + LoginResultBO loginResult = new LoginResultBO(); + loginResult.setSuccess(false); + + //1.鍒ゆ柇鐢ㄦ埛鐨勫熀鏈俊鎭� + VciBaseUtil.alertNotNull(userDTO, "鐧诲綍淇℃伅", userDTO.getUserId(), "鐢ㄦ埛璐﹀彿"); + if (checkPassword) { + VciBaseUtil.alertNotNull(userDTO.getPassword(), "鐧诲綍瀵嗙爜"); + } + //2銆佸垽鏂崟璁惧鐧诲綍,鏄惁宸茬粡鐧诲綍浜� + 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); + } + + //3.鑾峰彇鐢ㄦ埛鐨勫璞★紙瀵硅薄涓寘鍚鑹查儴闂ㄨ繕鏈夊瘑鐮佺瓥鐣ヤ俊鎭級 + 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 (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 (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 = pwdStrategyQueryService.getPasswordStrategyVOByUserOid(user.getOid()); + if (checkPassword) { + //鍓嶇闇�瑕佸厛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()); -// } - //鏌ヨ鎵�鏈夌殑鏉冮檺 -// 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)})); -// } -// } -// } -// } + //鑾峰彇浜哄憳鎵�灞炵殑閮ㄩ棬淇℃伅 + 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()); + } - //鍘熸湰鎯充娇鐢╦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<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()); + }*/ //娣诲姞鍒颁細璇濅俊鎭� -// 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); + } /** * 鍗曠偣鐧诲綍 @@ -302,7 +525,7 @@ * @throws VciBaseException 鐧诲綍澶辫触鐨勬椂鍊欐姏鍑哄紓甯� */ @Override - public LoginResultBO singleLogin(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws VciBaseException { + public LoginResultBO singleLogin(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws PLException { return login(userDTO,clientInfo,false); } @@ -358,37 +581,15 @@ } /** - * 鏍¢獙鏄惁鐧诲綍 - * @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 +639,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 +673,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 UNKNOWN; + 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