ÎļþÃû´Ó Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java ÐÞ¸Ä |
| | |
| | | package com.vci.web.service.impl; |
| | | |
| | | import com.vci.bo.LoginResultBO; |
| | | import com.vci.constant.CacheNameConstant; |
| | | 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.SmPwdStrategyQueryServiceI; |
| | | import com.vci.frameworkcore.compatibility.SmUserQueryServiceI; |
| | | import com.vci.frameworkcore.enumpck.ResourceControlTypeEnum; |
| | | import com.vci.frameworkcore.lcstatuspck.FrameworkDataLCStatus; |
| | | import com.vci.dto.LoginUserDTO; |
| | | import com.vci.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.VciLoginAfter; |
| | | import com.vci.starter.web.annotation.bus.VciLogoutBefore; |
| | | import com.vci.starter.web.annotation.bus.VciLogoutPlugin; |
| | |
| | | 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.*; |
| | | |
| | | import com.vci.bo.LoginResultBO; |
| | | import com.vci.constant.CacheNameConstant; |
| | | import com.vci.dto.LoginUserDTO; |
| | | import com.vci.web.properties.WebProperties; |
| | | import com.vci.starter.web.redis.RedisService; |
| | | import com.vci.web.service.LoginServiceI; |
| | | import com.vci.web.util.Func; |
| | | import com.vci.starter.web.util.ApplicationContextProvider; |
| | | import com.vci.starter.web.util.Lcm.Func; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.util.VciDateUtil; |
| | | import com.vci.starter.web.util.WebThreadLocalUtil; |
| | | import com.vci.web.ajaxTask.SmUserUnLockTask; |
| | | import com.vci.web.ajaxTask.SmUserUnLockTaskManager; |
| | | import com.vci.web.enumpck.ResourceControlTypeEnum; |
| | | import com.vci.web.properties.VciSecurityManageProperties; |
| | | import com.vci.web.properties.WebProperties; |
| | | import com.vci.web.service.ISmFunctionQueryService; |
| | | import com.vci.web.service.OsLoginServiceI; |
| | | import com.vci.web.service.SmPwdStrategyQueryServiceI; |
| | | import com.vci.web.service.SmUserQueryServiceI; |
| | | import com.vci.web.util.PlatformClientUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.slf4j.Logger; |
| | |
| | | * @date 2020/1/29 |
| | | */ |
| | | @Service |
| | | public class LoginServiceImpl implements LoginServiceI { |
| | | public class OsLoginServiceImpl implements OsLoginServiceI { |
| | | |
| | | /** |
| | | * æ¥å¿ |
| | |
| | | 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; |
| | | } |
| | | //说æå·²ç»ç»å½äºï¼é£åºè¯¥åæ¶åæ¥çç»å½ |
| | | 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.getName()); |
| | | if (!passwordIsEqual) { |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("{}å¯ç 䏿£ç¡®", user.getId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //4ãè°ç¨å¹³å°ç»å½æ¥å£ï¼è¿è¡ç»å½ |
| | | 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; |
| | | } |
| | | }*/ |
| | | //å½åç¨æ·æ²¡æé
置就æ¥è¯¢é»è®¤çå¯ç çç¥ |
| | | SmPasswordStrategyVO passwordStrategyVO = pwdStrategyQueryService.getPasswordStrategyVOByUserOid(user.getOid()); |
| | | if (checkPassword) { |
| | | //å端éè¦å
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); |
| | | |
| | | SessionInfo sessionInfo = new SessionInfo(); |
| | | sessionInfo.setToken(token); |
| | | |
| | | //åå§åå¹³å°çtoken |
| | | sessionForLogin.initInvocationInfo(sessionInfo); |
| | | |
| | | //æ·è´ç¨æ·çæ°å°sessionä¼è¯ä¸ |
| | | copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode()); |
| | | //æ·è´è¯·æ±ä¿¡æ¯å°sessionä¼è¯ä¸ |
| | | copyRequest2SessionInfo(clientInfo, sessionInfo); |
| | | |
| | | //è·å人åæå±çé¨é¨ä¿¡æ¯ |
| | | 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()); |
| | | }*/ |
| | | |
| | | //æ·»å å°ä¼è¯ä¿¡æ¯ |
| | | TokenVO tokenVO = saveSessionInfo(sessionInfo); |
| | | loginResult.setTokenVO(tokenVO); |
| | | |
| | | loginResult.setSuccess(true); |
| | | return loginResult; |
| | | } |
| | | |
| | | private MachineInfo getMachieInfo(RequestClientInfo clientInfo) { |
| | | MachineInfo machine = new MachineInfo(); |
| | | machine.country = clientInfo.getCountry(); |
| | |
| | | */ |
| | | private SmUserVO getUserByUserId(String userId) { |
| | | return userQueryService.getUserByUserId(userId); |
| | | } |
| | | |
| | | /** |
| | | * åç¹ç»å½ |
| | | * |
| | | * @param userDTO ç»å½ä¿¡æ¯ |
| | | * @param clientInfo 请æ±ç客æ·ç«¯çä¿¡æ¯ |
| | | * @return ç»å½çç»æå¯¹è±¡ |
| | | * @throws VciBaseException ç»å½å¤±è´¥çæ¶åæåºå¼å¸¸ |
| | | */ |
| | | @Override |
| | | public LoginResultBO singleLogin(LoginUserDTO userDTO, RequestClientInfo clientInfo) throws Exception { |
| | | return login(userDTO,clientInfo,false); |
| | | } |
| | | |
| | | /** |