|
|
@ -7,6 +7,7 @@ import cn.estsh.i3plus.platform.common.tool.EncryptTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysUserPassword;
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysUserPassword;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
@ -28,8 +29,10 @@ import org.springframework.util.ObjectUtils;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.naming.NamingException;
|
|
|
|
import javax.naming.NamingException;
|
|
|
|
import javax.naming.ldap.LdapContext;
|
|
|
|
import javax.naming.ldap.LdapContext;
|
|
|
|
|
|
|
|
import javax.persistence.EntityManager;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
@ -119,6 +122,9 @@ public class SysUserPasswordUtil {
|
|
|
|
* @param user
|
|
|
|
* @param user
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void checkPasswordLogin(SysUser user) {
|
|
|
|
public void checkPasswordLogin(SysUser user) {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
SysConfig sysConfig = RedisCacheTool.getSysConfigByConfigCode(CommonConstWords.CONFIG_PWD_LENGTH);
|
|
|
|
|
|
|
|
if(StringUtils.isEmpty(user.getUserPasswordLastModifyTime()) || user.getUserPasswordLastModifyTime().compareTo(sysConfig.getModifyDatetime()) >= 0) {
|
|
|
|
/* 密码 长度校验 */
|
|
|
|
/* 密码 长度校验 */
|
|
|
|
checkPasswordLength(user.getUserLoginPassword());
|
|
|
|
checkPasswordLength(user.getUserLoginPassword());
|
|
|
|
/* 密码 大写字母校验 */
|
|
|
|
/* 密码 大写字母校验 */
|
|
|
@ -132,6 +138,7 @@ public class SysUserPasswordUtil {
|
|
|
|
/* 密码 密码正则校验 */
|
|
|
|
/* 密码 密码正则校验 */
|
|
|
|
checkPasswordRepeat(user.getUserLoginPassword());
|
|
|
|
checkPasswordRepeat(user.getUserLoginPassword());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************** 用户保存密码检查 ********************************************/
|
|
|
|
/******************************************** 用户保存密码检查 ********************************************/
|
|
|
|
|
|
|
|
|
|
|
@ -150,6 +157,8 @@ public class SysUserPasswordUtil {
|
|
|
|
checkPasswordRepeatDay(user);
|
|
|
|
checkPasswordRepeatDay(user);
|
|
|
|
/* 密码 密码正则校验 */
|
|
|
|
/* 密码 密码正则校验 */
|
|
|
|
checkPasswordRepeat(user.getUserLoginPassword());
|
|
|
|
checkPasswordRepeat(user.getUserLoginPassword());
|
|
|
|
|
|
|
|
/* 密码 用户修改密码频次校验 */
|
|
|
|
|
|
|
|
checkPasswordFrequency(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -327,7 +336,7 @@ public class SysUserPasswordUtil {
|
|
|
|
// List<SysUserPassword> passwords = userPasswordService.findAllByBean(userPassword);
|
|
|
|
// List<SysUserPassword> passwords = userPasswordService.findAllByBean(userPassword);
|
|
|
|
|
|
|
|
|
|
|
|
//修改为查询这个账号最近的密码是否重复
|
|
|
|
//修改为查询这个账号最近的密码是否重复
|
|
|
|
List<SysUserPassword> passwords = userPasswordService.findPasswordByPassword(EncryptTool.hexMD5(user.getUserLoginPassword()),user.getId());
|
|
|
|
List<SysUserPassword> passwords = userPasswordService.findPasswordByPasswordAndResetPwdTime(EncryptTool.hexMD5(user.getUserLoginPassword()),user.getId());
|
|
|
|
|
|
|
|
|
|
|
|
int lastDay = Integer.MAX_VALUE;
|
|
|
|
int lastDay = Integer.MAX_VALUE;
|
|
|
|
if (CollectionUtils.isNotEmpty(passwords)) {
|
|
|
|
if (CollectionUtils.isNotEmpty(passwords)) {
|
|
|
@ -344,7 +353,7 @@ public class SysUserPasswordUtil {
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorDetail(String.format("最近%s天内,请勿使用重复密码",num))
|
|
|
|
.setErrorDetail(String.format("最近%s次内,请勿使用重复密码",num))
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -400,6 +409,62 @@ public class SysUserPasswordUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 密码 用户修改密码频次校验
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param user
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private void checkPasswordFrequency(SysUser user) {
|
|
|
|
|
|
|
|
String frequencyDay = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_USER_MODIFY_PWD_FREQUENCY_DAY);
|
|
|
|
|
|
|
|
String frequencyNum = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_USER_MODIFY_PWD_FREQUENCY_NUM);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(frequencyDay) && StringUtils.isNotBlank(frequencyNum)) {
|
|
|
|
|
|
|
|
//获取到修改的次数count
|
|
|
|
|
|
|
|
Integer modifyUnlockNum = user.getModifyPwdNum();
|
|
|
|
|
|
|
|
if(null!= modifyUnlockNum && modifyUnlockNum >= Integer.parseInt(frequencyNum)){
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("密码【%s】天只能修改【%s】次",frequencyDay,frequencyNum)
|
|
|
|
|
|
|
|
.setErrorSolution("修改次数过多")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 校验正确登录是否在自动锁定的时间
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param user
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private ResultBean checkAuthUnlockTime(SysUser user) {
|
|
|
|
|
|
|
|
//校验自动解锁次数是否达到三次
|
|
|
|
|
|
|
|
if (null != user.getAutoUnlockNum() && user.getAutoUnlockNum() >= 3){
|
|
|
|
|
|
|
|
//锁定账号并设定锁定类型
|
|
|
|
|
|
|
|
userService.doLockAndStatusSysUserById(user.getId(),CommonEnumUtil.LOCK_TYPE.LOGGER_TOO_MANY_FAILURES.getValue());
|
|
|
|
|
|
|
|
return ResultBean.fail()
|
|
|
|
|
|
|
|
.setCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorMsg(LocaleUtils.getLocaleRes("用户名或密码多次输入错误。用户已被锁定请联系管理员!"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String unlockRedisKey = CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUM_UNLOCK_TIME + "_" + user.getId();
|
|
|
|
|
|
|
|
String unlockTime = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUM_UNLOCK_TIME);
|
|
|
|
|
|
|
|
Object redisUnlockTime = redisCore.getObject(unlockRedisKey);
|
|
|
|
|
|
|
|
if(null != redisUnlockTime){
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
int secoundsBetweenTime = TimeTool.getSecoundsBetweenTime(1, redisUnlockTime.toString(), TimeTool.getNowTime(null));
|
|
|
|
|
|
|
|
secoundsBetweenTime = Integer.parseInt(unlockTime) * 60 - secoundsBetweenTime;
|
|
|
|
|
|
|
|
return ResultBean.fail()
|
|
|
|
|
|
|
|
.setCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorMsg(LocaleUtils.getLocaleRes("登录失败次数过多。请【" + secoundsBetweenTime/60 + "】分【" + secoundsBetweenTime%60 + "】秒后再试"));
|
|
|
|
|
|
|
|
} catch (ParseException parseException) {
|
|
|
|
|
|
|
|
parseException.printStackTrace();
|
|
|
|
|
|
|
|
LOGGER.error("时间计算异常", parseException);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************** 用户登录密码检查 ********************************************/
|
|
|
|
/******************************************** 用户登录密码检查 ********************************************/
|
|
|
|
public ResultBean checkSysUserLogin(SysUser user) {
|
|
|
|
public ResultBean checkSysUserLogin(SysUser user) {
|
|
|
@ -429,7 +494,11 @@ public class SysUserPasswordUtil {
|
|
|
|
if (!result.isSuccess()) {
|
|
|
|
if (!result.isSuccess()) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 判断自动锁定时间 */
|
|
|
|
|
|
|
|
result = checkAuthUnlockTime(user);
|
|
|
|
|
|
|
|
if (!result.isSuccess()) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
//登录时是否检查用户密码是否符合安全规则
|
|
|
|
//登录时是否检查用户密码是否符合安全规则
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int isLoginCheckPassword = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_LOGIN_CHECK_PASSWORD,CommonConstWords.CONFIG_LOGIN_CHECK_PASSWORD_DEFAULT);
|
|
|
|
int isLoginCheckPassword = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_LOGIN_CHECK_PASSWORD,CommonConstWords.CONFIG_LOGIN_CHECK_PASSWORD_DEFAULT);
|
|
|
@ -520,6 +589,8 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
|
|
int loginErrorNumber = 0;
|
|
|
|
int loginErrorNumber = 0;
|
|
|
|
String redisKey = CommonConstWords.USER_LOGIN_ERROR + ":" + today + ":" + userId;
|
|
|
|
String redisKey = CommonConstWords.USER_LOGIN_ERROR + ":" + today + ":" + userId;
|
|
|
|
|
|
|
|
String redisAuthUnlockKey = CommonConstWords.USER_LOGIN_ERROR + ":" + "authUnlockKey" + ":" + today + ":" + userId;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Object redisValue = redisCore.getObject(redisKey);
|
|
|
|
Object redisValue = redisCore.getObject(redisKey);
|
|
|
|
if (Objects.nonNull(redisValue)) {
|
|
|
|
if (Objects.nonNull(redisValue)) {
|
|
|
@ -529,7 +600,9 @@ public class SysUserPasswordUtil {
|
|
|
|
LOGGER.error("获取登录异常次数错误,错误信息:{}", exception.getMessage());
|
|
|
|
LOGGER.error("获取登录异常次数错误,错误信息:{}", exception.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(loginErrorNumberMax, loginErrorNumber)) {
|
|
|
|
Object authUnlockNum = redisCore.getObject(redisAuthUnlockKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(loginErrorNumberMax, loginErrorNumber) && authUnlockNum != null && Integer.parseInt(authUnlockNum.toString())>=3) {
|
|
|
|
// 锁定账号信息
|
|
|
|
// 锁定账号信息
|
|
|
|
userService.doLockSysUserById(userId);
|
|
|
|
userService.doLockSysUserById(userId);
|
|
|
|
|
|
|
|
|
|
|
@ -539,7 +612,9 @@ public class SysUserPasswordUtil {
|
|
|
|
.setErrorDetail("账号已被锁定")
|
|
|
|
.setErrorDetail("账号已被锁定")
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
} else if (loginErrorNumber > loginErrorNumberMax) {
|
|
|
|
} else if (loginErrorNumber > loginErrorNumberMax && authUnlockNum != null && Integer.parseInt(authUnlockNum.toString())>=3) {
|
|
|
|
|
|
|
|
// 锁定账号信息
|
|
|
|
|
|
|
|
userService.doLockSysUserById(userId);
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
@ -554,98 +629,134 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
|
|
if (Objects.nonNull(resultBean)) {
|
|
|
|
if (Objects.nonNull(resultBean)) {
|
|
|
|
int num = loginErrorNumberMax - loginErrorNumber;
|
|
|
|
int num = loginErrorNumberMax - loginErrorNumber;
|
|
|
|
if (num == 0) {
|
|
|
|
if (num <= 0) {
|
|
|
|
resultBean.setErrorMsg(LocaleUtils.getLocaleRes("密码输入错误。用户已被锁定请联系管理员!"));
|
|
|
|
int autoUnlockNum = 0;
|
|
|
|
|
|
|
|
String unlockTime = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUM_UNLOCK_TIME);
|
|
|
|
|
|
|
|
String unlockRedisKey = CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUM_UNLOCK_TIME + "_" + userId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (null != authUnlockNum) {
|
|
|
|
|
|
|
|
autoUnlockNum = Integer.parseInt(authUnlockNum.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Object redisUnlockTime = redisCore.getObject(unlockRedisKey);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (null == redisUnlockTime) {
|
|
|
|
|
|
|
|
redisCore.putObject(unlockRedisKey, TimeTool.getNowTime(null), Long.parseLong(unlockTime) * 60L);
|
|
|
|
|
|
|
|
redisCore.putObject(redisAuthUnlockKey, autoUnlockNum++, CommonConstWords.REDIS_TIME_DAY_ONE);
|
|
|
|
|
|
|
|
if(autoUnlockNum >= 3 ){
|
|
|
|
|
|
|
|
userService.doLockAndStatusSysUserById(userId,CommonEnumUtil.LOCK_TYPE.LOGGER_TOO_MANY_FAILURES.getValue());
|
|
|
|
|
|
|
|
redisCore.deleteKey(unlockRedisKey);
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
|
|
|
.setErrorDetail("登录失败次数过多")
|
|
|
|
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resultBean.setErrorMsg(LocaleUtils.getLocaleRes("用户名或密码输入错误。请【" + unlockTime + "】分钟后再试"));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
resultBean.setErrorMsg(String.format(LocaleUtils.getLocaleRes("密码输入错误。再输入错误 %s 次,用户将被锁定"), num));
|
|
|
|
try {
|
|
|
|
|
|
|
|
int secoundsBetweenTime = TimeTool.getSecoundsBetweenTime(1, redisUnlockTime.toString(), TimeTool.getNowTime(null));
|
|
|
|
|
|
|
|
secoundsBetweenTime = Integer.parseInt(unlockTime) * 60 - secoundsBetweenTime;
|
|
|
|
|
|
|
|
resultBean.setErrorMsg(LocaleUtils.getLocaleRes("登录失败次数过多。请【" + secoundsBetweenTime/60 + "】分【" + secoundsBetweenTime%60 + "】秒后再试"));
|
|
|
|
|
|
|
|
} catch (ParseException parseException) {
|
|
|
|
|
|
|
|
parseException.printStackTrace();
|
|
|
|
|
|
|
|
LOGGER.error("时间计算异常", parseException);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resultBean.setErrorMsg(String.format(LocaleUtils.getLocaleRes("用户名或密码输入错误。还有 %s 次机会"), num));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
redisCore.putObject(redisKey, loginErrorNumber, CommonConstWords.REDIS_TIME_DAY_ONE);
|
|
|
|
redisCore.putObject(redisKey, loginErrorNumber, CommonConstWords.REDIS_TIME_DAY_ONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 登录 检查密码有效期
|
|
|
|
* 登录 长时间未登录锁定
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ResultBean checkLoginPasswordTimeOut(SysUser user) {
|
|
|
|
private ResultBean checkLoginTimeOut(SysUser user) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int passwordDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_VALID_DAY, CommonConstWords.CONFIG_PWD_VALID_DAY_DEFAULT);
|
|
|
|
if (StringUtils.isBlank(user.getUserLoginLastDateTime())) {
|
|
|
|
if (passwordDayMax > 0) {
|
|
|
|
return ResultBean.fail("上次登录时间为空");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean longTimenNotLogin = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_USER_UNLOGIN_LONG_TIME_LOCK, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
|
|
|
|
|
|
|
int loginDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT, CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT_DEFAULT);
|
|
|
|
|
|
|
|
if (longTimenNotLogin && loginDayMax > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
SysUserPassword password = userPasswordService.get(user.getUserLoginPasswordId());
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, user.getUserLoginLastDateTime(), TimeTool.getNowTime(true));
|
|
|
|
if (Objects.nonNull(password) && StringUtils.isNotBlank(password.getCreateDatetime())) {
|
|
|
|
if (day > loginDayMax) {
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
|
|
|
|
|
|
|
if (day > passwordDayMax) {
|
|
|
|
|
|
|
|
// 锁定账号信息
|
|
|
|
// 锁定账号信息
|
|
|
|
|
|
|
|
//todo: 账户没有被锁定,由于异常事务回滚,导致账户没有被锁定,这个更新操作就是多余的
|
|
|
|
userService.doLockSysUserById(user.getId());
|
|
|
|
userService.doLockSysUserById(user.getId());
|
|
|
|
|
|
|
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
// .setErrorDetail("账号密码已过期")
|
|
|
|
// .setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
// .build();
|
|
|
|
// .build();
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorDetail("账号密码已过期")
|
|
|
|
.setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
// throw e;
|
|
|
|
// throw e;
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
|
|
|
LOGGER.error("长时间未登录处理异常,异常信息:{}", e.getMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ResultBean.success();
|
|
|
|
return ResultBean.success();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 登录 长时间未登录锁定
|
|
|
|
* 登录 检查密码有效期
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private ResultBean checkLoginTimeOut(SysUser user) {
|
|
|
|
private ResultBean checkLoginPasswordTimeOut(SysUser user) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (StringUtils.isBlank(user.getUserLoginLastDateTime())) {
|
|
|
|
boolean pwdExpireSwitch = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXPIRE_SWITCH, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
|
|
|
return ResultBean.success("上次登录时间为空");
|
|
|
|
// int passwordDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_VALID_DAY, CommonConstWords.CONFIG_PWD_VALID_DAY_DEFAULT);
|
|
|
|
}
|
|
|
|
Integer userPasswordOverdueValue = user.getUserPasswordOverdue();
|
|
|
|
int loginDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT, CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT_DEFAULT);
|
|
|
|
|
|
|
|
if (loginDayMax > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, user.getUserLoginLastDateTime(), TimeTool.getNowTime(true));
|
|
|
|
if (pwdExpireSwitch && userPasswordOverdueValue == CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
if (day > loginDayMax) {
|
|
|
|
SysConfig sysConfigByConfigCode = RedisCacheTool.getSysConfigByConfigCode(CommonConstWords.CONFIG_PWD_EXPIRE_DAY_TIME);
|
|
|
|
|
|
|
|
String configValue = sysConfigByConfigCode.getConfigValue();
|
|
|
|
|
|
|
|
SysUserPassword password = userPasswordService.get(user.getUserLoginPasswordId());
|
|
|
|
|
|
|
|
if (Objects.nonNull(password) && StringUtils.isNotBlank(password.getCreateDatetime())) {
|
|
|
|
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
|
|
|
|
|
|
|
if (day > Integer.parseInt(configValue)) {
|
|
|
|
// 锁定账号信息
|
|
|
|
// 锁定账号信息
|
|
|
|
//todo: 账户没有被锁定,由于异常事务回滚,导致账户没有被锁定,这个更新操作就是多余的
|
|
|
|
// userService.doLockSysUserById(user.getId());
|
|
|
|
userService.doLockSysUserById(user.getId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
// .setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
// .setErrorDetail("账号密码已过期")
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
// .build();
|
|
|
|
// .build();
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
.setErrorCode(ImppExceptionEnum.LOGIN_EXCEPTION_PASSWORD_EXPIRED.getCode())
|
|
|
|
.setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
.setErrorDetail("账号密码已过期")
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
.setErrorSolution("请重新修改密码")
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
// throw e;
|
|
|
|
// throw e;
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOGGER.error("长时间未登录处理异常,异常信息:{}", e.getMessage());
|
|
|
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ResultBean.success();
|
|
|
|
return ResultBean.success();
|
|
|
|