|
|
|
@ -54,10 +54,11 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 密码加密 返回加密信息
|
|
|
|
|
*
|
|
|
|
|
* @param password
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public static final String encoder(String password){
|
|
|
|
|
public static final String encoder(String password) {
|
|
|
|
|
try {
|
|
|
|
|
return EncryptTool.hexMD5(password);
|
|
|
|
|
} catch (NoSuchAlgorithmException e) {
|
|
|
|
@ -215,8 +216,8 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
for (char ch : chars) {
|
|
|
|
|
// Chart ASCLL 编码比对 特殊字符
|
|
|
|
|
if ((ch >= 32 && ch <= 47)|| (ch >= 58 && ch <= 64)||
|
|
|
|
|
(ch >= 91 && ch <= 96)|| (ch >= 123 && ch <= 126)) {
|
|
|
|
|
if ((ch >= 32 && ch <= 47) || (ch >= 58 && ch <= 64) ||
|
|
|
|
|
(ch >= 91 && ch <= 96) || (ch >= 123 && ch <= 126)) {
|
|
|
|
|
++num;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -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()
|
|
|
|
@ -307,47 +311,66 @@ public class SysUserPasswordUtil {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
for (String compile : split) {
|
|
|
|
|
if(StringUtils.isNotBlank(compile)){
|
|
|
|
|
if (StringUtils.isNotBlank(compile)) {
|
|
|
|
|
if (!Pattern.compile(compile).matcher(content).find()) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
|
.setErrorDetail("正则【"+compile+"】密码校验不通过")
|
|
|
|
|
.setErrorDetail("正则【" + compile + "】密码校验不通过")
|
|
|
|
|
.setErrorSolution("请重新输入")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}catch (ImppBusiException e){
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
// 业务异常 抛出
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************** 用户登录密码检查 ********************************************/
|
|
|
|
|
public void checkSysUserLogin(SysUser user) {
|
|
|
|
|
if(ImppSwitchUtil.isLoginActiveDirectory()){
|
|
|
|
|
public ResultBean checkSysUserLogin(SysUser user) {
|
|
|
|
|
if (ImppSwitchUtil.isLoginActiveDirectory()) {
|
|
|
|
|
// 使用AD域账号登录
|
|
|
|
|
try {
|
|
|
|
|
checkActiveDirectory(user);
|
|
|
|
|
}else{
|
|
|
|
|
} 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) {
|
|
|
|
|
if(ImppSwitchUtil.isLoginActiveDirectory()){
|
|
|
|
|
if (ImppSwitchUtil.isLoginActiveDirectory()) {
|
|
|
|
|
String activeDirectoryUrl = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_PWD_ACTIVE_DIRECTORY_URL);
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(activeDirectoryUrl)) {
|
|
|
|
@ -374,7 +397,7 @@ public class SysUserPasswordUtil {
|
|
|
|
|
.setErrorSolution("请重新操作")
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
@ -390,13 +413,14 @@ public class SysUserPasswordUtil {
|
|
|
|
|
*/
|
|
|
|
|
public void checkLoginErrorNumber(String loginName, ResultBean resultBean, Exception e) {
|
|
|
|
|
SysUser user = userService.getSysUserByLoginName(loginName);
|
|
|
|
|
if(Objects.nonNull(user)){
|
|
|
|
|
if (Objects.nonNull(user)) {
|
|
|
|
|
checkLoginErrorNumber(user.getId(), resultBean, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录 失败次数检查
|
|
|
|
|
*
|
|
|
|
|
* @param userId
|
|
|
|
|
* @param resultBean
|
|
|
|
|
* @param e
|
|
|
|
@ -409,14 +433,14 @@ public class SysUserPasswordUtil {
|
|
|
|
|
String redisKey = CommonConstWords.USER_LOGIN_ERROR + ":" + today + ":" + userId;
|
|
|
|
|
try {
|
|
|
|
|
Object redisValue = redisCore.getObject(redisKey);
|
|
|
|
|
if(Objects.nonNull(redisValue)){
|
|
|
|
|
loginErrorNumber = (Integer)redisValue;
|
|
|
|
|
if (Objects.nonNull(redisValue)) {
|
|
|
|
|
loginErrorNumber = (Integer) redisValue;
|
|
|
|
|
}
|
|
|
|
|
}catch (Exception exception){
|
|
|
|
|
} catch (Exception exception) {
|
|
|
|
|
LOGGER.error("获取登录异常次数错误,错误信息:{}", exception.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(Objects.equals(loginErrorNumberMax,loginErrorNumber)){
|
|
|
|
|
if (Objects.equals(loginErrorNumberMax, loginErrorNumber)) {
|
|
|
|
|
// 锁定账号信息
|
|
|
|
|
userService.doLockSysUserById(userId);
|
|
|
|
|
|
|
|
|
@ -426,7 +450,7 @@ public class SysUserPasswordUtil {
|
|
|
|
|
.setErrorDetail("账号已被锁定")
|
|
|
|
|
.setErrorSolution("请联系系统管理员")
|
|
|
|
|
.build();
|
|
|
|
|
}else if(loginErrorNumber > loginErrorNumberMax){
|
|
|
|
|
} else if (loginErrorNumber > loginErrorNumberMax) {
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
|
|
|
@ -436,82 +460,133 @@ public class SysUserPasswordUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登录异常 更新登录失败次数
|
|
|
|
|
if(Objects.nonNull(e)){
|
|
|
|
|
if (Objects.nonNull(e)) {
|
|
|
|
|
++loginErrorNumber;
|
|
|
|
|
|
|
|
|
|
if(Objects.nonNull(resultBean)){
|
|
|
|
|
if (Objects.nonNull(resultBean)) {
|
|
|
|
|
int num = loginErrorNumberMax - loginErrorNumber;
|
|
|
|
|
if(num == 0){
|
|
|
|
|
if (num == 0) {
|
|
|
|
|
resultBean.setErrorMsg(LocaleUtils.getLocaleRes("密码输入错误。用户已被锁定请联系管理员!"));
|
|
|
|
|
}else{
|
|
|
|
|
} 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 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){
|
|
|
|
|
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){
|
|
|
|
|
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;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (ImppBusiException 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){
|
|
|
|
|
if (loginDayMax > 0) {
|
|
|
|
|
|
|
|
|
|
int day = TimeTool.getSecoundsBetweenTime(4, user.getUserLoginLastDateTime(), TimeTool.getNowTime(true));
|
|
|
|
|
if(day > loginDayMax){
|
|
|
|
|
if (day > loginDayMax) {
|
|
|
|
|
// 锁定账号信息
|
|
|
|
|
//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;
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
|
|
|
|
} catch (ImppBusiException 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 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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|