|
|
|
@ -54,6 +54,7 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 密码加密 返回加密信息
|
|
|
|
|
*
|
|
|
|
|
* @param password
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -270,12 +271,15 @@ public class SysUserPasswordUtil {
|
|
|
|
|
int lastDay = Integer.MAX_VALUE;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(passwords)) {
|
|
|
|
|
for (SysUserPassword password : passwords) {
|
|
|
|
|
//防止日期转换错误
|
|
|
|
|
if (StringUtils.isNotBlank(password.getCreateDatetime())){
|
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
|
|
|
|
if (day < lastDay) {
|
|
|
|
|
lastDay = day;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lastDay > num) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
@ -328,22 +332,41 @@ public class SysUserPasswordUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************** 用户登录密码检查 ********************************************/
|
|
|
|
|
public void checkSysUserLogin(SysUser user) {
|
|
|
|
|
public ResultBean checkSysUserLogin(SysUser user) {
|
|
|
|
|
if (ImppSwitchUtil.isLoginActiveDirectory()) {
|
|
|
|
|
// 使用AD域账号登录
|
|
|
|
|
try {
|
|
|
|
|
checkActiveDirectory(user);
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* 检查密码有效期 */
|
|
|
|
|
checkLoginPasswordTimeOut(user);
|
|
|
|
|
ResultBean result = checkLoginPasswordTimeOut(user);
|
|
|
|
|
if(!result.isSuccess()){
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/* 登录 长时间未登录锁定 */
|
|
|
|
|
checkLoginTimeOut(user);
|
|
|
|
|
result = checkLoginTimeOut(user);
|
|
|
|
|
if(!result.isSuccess()){
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
/* 判断是否第一次登录 */
|
|
|
|
|
result = checkFirstLoginChangePwd(user);
|
|
|
|
|
if(!result.isSuccess()){
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 账号 ActiveDirectory 登录集成
|
|
|
|
|
*
|
|
|
|
|
* @param user
|
|
|
|
|
*/
|
|
|
|
|
public void checkActiveDirectory(SysUser user) {
|
|
|
|
@ -397,6 +420,7 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录 失败次数检查
|
|
|
|
|
*
|
|
|
|
|
* @param userId
|
|
|
|
|
* @param resultBean
|
|
|
|
|
* @param e
|
|
|
|
@ -455,40 +479,54 @@ public class SysUserPasswordUtil {
|
|
|
|
|
/**
|
|
|
|
|
* 登录 检查密码有效期
|
|
|
|
|
*/
|
|
|
|
|
private void checkLoginPasswordTimeOut(SysUser user) {
|
|
|
|
|
private ResultBean checkLoginPasswordTimeOut(SysUser user) {
|
|
|
|
|
try {
|
|
|
|
|
int passwordDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_VALID_DAY, CommonConstWords.CONFIG_PWD_VALID_DAY_DEFAULT);
|
|
|
|
|
if (passwordDayMax > 0) {
|
|
|
|
|
|
|
|
|
|
SysUserPassword password = userPasswordService.get(user.getUserLoginPasswordId());
|
|
|
|
|
if(Objects.nonNull(password)){
|
|
|
|
|
if (Objects.nonNull(password) && StringUtils.isNotBlank(password.getCreateDatetime())) {
|
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
|
|
|
|
if (day > passwordDayMax) {
|
|
|
|
|
// 锁定账号信息
|
|
|
|
|
userService.doLockSysUserById(user.getId());
|
|
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
// .setErrorDetail("账号密码已过期")
|
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
|
// .build();
|
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("账号密码已过期")
|
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
|
.build();
|
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
// throw e;
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录 长时间未登录锁定
|
|
|
|
|
*/
|
|
|
|
|
private void checkLoginTimeOut(SysUser user) {
|
|
|
|
|
private ResultBean checkLoginTimeOut(SysUser user) {
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isBlank(user.getUserLoginLastDateTime())){
|
|
|
|
|
return ResultBean.success("上次登录时间为空");
|
|
|
|
|
}
|
|
|
|
|
int loginDayMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT, CommonConstWords.CONFIG_USER_LOGIN_DAY_OUT_DEFAULT);
|
|
|
|
|
if (loginDayMax > 0) {
|
|
|
|
|
|
|
|
|
@ -498,20 +536,57 @@ public class SysUserPasswordUtil {
|
|
|
|
|
//todo: 账户没有被锁定,由于异常事务回滚,导致账户没有被锁定,这个更新操作就是多余的
|
|
|
|
|
userService.doLockSysUserById(user.getId());
|
|
|
|
|
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
// throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
// .setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
// .setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
// .setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
|
// .setErrorSolution("请联系系统管理员")
|
|
|
|
|
// .build();
|
|
|
|
|
ImppBusiException exception = ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("长时间未登录账号已被锁定")
|
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
|
.build();
|
|
|
|
|
return ResultBean.fail(exception);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
// throw e;
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
|
|
|
|
LOGGER.error("长时间未登录处理异常,异常信息:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 第一次登录是否修改密码
|
|
|
|
|
*/
|
|
|
|
|
private ResultBean checkFirstLoginChangePwd(SysUser user) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
int firstLoginChangePwd = RedisCacheTool.getSysConfigIntVal(CommonConstWords.FIRST_LOGIN_CHANGE_PWD_SWITCH_KEY, CommonConstWords.FIRST_LOGIN_CHANGE_PWD_SWITCH_DEFAULT_VALUE);
|
|
|
|
|
if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == firstLoginChangePwd) {
|
|
|
|
|
if (null == user.getUserLoginNum() || user.getUserLoginNum() <= 0) {
|
|
|
|
|
return ResultBean.fail()
|
|
|
|
|
.setCode(ImppExceptionEnum.LOGIN_EXCEPTION_CHANGE_PWD.getCode())
|
|
|
|
|
.setErrorMsg(ImppExceptionEnum.LOGIN_EXCEPTION_CHANGE_PWD.getDescription());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("首次登录验证出错,异常信息:{}", e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e);
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|