feat(密码规则验证完成): 用户登录,密码修改
parent
28a50b844c
commit
8783b9a33f
@ -1,34 +1,34 @@
|
|||||||
package cn.estsh.i3plus.core.apiservice.mq;
|
//package cn.estsh.i3plus.core.apiservice.mq;
|
||||||
|
//
|
||||||
import cn.estsh.i3plus.core.apiservice.serviceimpl.mdm.SysToolSyncDataService;
|
//import cn.estsh.i3plus.core.apiservice.serviceimpl.mdm.SysToolSyncDataService;
|
||||||
import cn.estsh.i3plus.pojo.mdm.bean.busi.core.MdmGearCoreBusiExtd;
|
//import cn.estsh.i3plus.pojo.mdm.bean.busi.core.MdmGearCoreBusiExtd;
|
||||||
import com.rabbitmq.client.Channel;
|
//import com.rabbitmq.client.Channel;
|
||||||
import org.springframework.amqp.core.Message;
|
//import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import static cn.estsh.i3plus.platform.common.util.MdmConstWords.QUEUE_MDM_SYNC_DATA_CORE;
|
//import static cn.estsh.i3plus.platform.common.util.MdmConstWords.QUEUE_MDM_SYNC_DATA_CORE;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @Description :
|
// * @Description :
|
||||||
* @Reference :
|
// * @Reference :
|
||||||
* @Author : yunhao
|
// * @Author : yunhao
|
||||||
* @CreateDate : 2020-05-28 16:54
|
// * @CreateDate : 2020-05-28 16:54
|
||||||
* @Modify:
|
// * @Modify:
|
||||||
**/
|
// **/
|
||||||
@Component
|
//@Component
|
||||||
public class MdmDataSyncQueueReceiver extends BaseMdmDataSyncQueueReceiver {
|
//public class MdmDataSyncQueueReceiver extends BaseMdmDataSyncQueueReceiver {
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 初始化类关系
|
// * 初始化类关系
|
||||||
*/
|
// */
|
||||||
public MdmDataSyncQueueReceiver() {
|
// public MdmDataSyncQueueReceiver() {
|
||||||
putMdmDataRef(SysToolSyncDataService.class, MdmGearCoreBusiExtd.mdmMasterClass, MdmGearCoreBusiExtd.class);
|
// putMdmDataRef(SysToolSyncDataService.class, MdmGearCoreBusiExtd.mdmMasterClass, MdmGearCoreBusiExtd.class);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
@RabbitListener(queues = QUEUE_MDM_SYNC_DATA_CORE)
|
// @RabbitListener(queues = QUEUE_MDM_SYNC_DATA_CORE)
|
||||||
public void syncMasterData(String syncDataStr, Channel channel, Message message) {
|
// public void syncMasterData(String syncDataStr, Channel channel, Message message) {
|
||||||
processSyncMasterData(syncDataStr, channel, message);
|
// processSyncMasterData(syncDataStr, channel, message);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
@ -0,0 +1,505 @@
|
|||||||
|
package cn.estsh.i3plus.core.apiservice.util;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserPasswordService;
|
||||||
|
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService;
|
||||||
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.EncryptTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
|
||||||
|
import cn.estsh.i3plus.pojo.platform.bean.SysUserPassword;
|
||||||
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||||
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||||
|
import cn.estsh.impp.framework.boot.util.*;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
import javax.naming.ldap.LdapContext;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description :
|
||||||
|
* @Reference :
|
||||||
|
* @Author : wei.peng
|
||||||
|
* @CreateDate : 20-6-8 上午10:10
|
||||||
|
* @Modify:
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class SysUserPasswordUtil {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger(SysUserPasswordUtil.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysUserPasswordService userPasswordService;
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
@Autowired
|
||||||
|
private ISysUserService userService;
|
||||||
|
|
||||||
|
@Resource(name = CommonConstWords.IMPP_REDIS_CORE)
|
||||||
|
protected ImppRedis redisCore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码加密 返回加密信息
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final String encoder(String password){
|
||||||
|
try {
|
||||||
|
return EncryptTool.hexMD5(password);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("密码加密失败")
|
||||||
|
.setErrorSolution("请重新操作")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************** 用户保存密码检查 ********************************************/
|
||||||
|
|
||||||
|
public void checkPasswordSave(SysUser user) {
|
||||||
|
/* 密码 长度校验 */
|
||||||
|
checkPasswordLength(user.getUserLoginPassword());
|
||||||
|
/* 密码 大写字母校验 */
|
||||||
|
checkPasswordUppercaseEnglish(user.getUserLoginPassword());
|
||||||
|
/* 密码 小写字母校验 */
|
||||||
|
checkPasswordlowerEnglish(user.getUserLoginPassword());
|
||||||
|
/* 密码 数字校验 */
|
||||||
|
checkPasswordNumber(user.getUserLoginPassword());
|
||||||
|
/* 密码 特殊字符校验 */
|
||||||
|
checkPasswordSpecial(user.getUserLoginPassword());
|
||||||
|
/* 密码 重复使用校验 */
|
||||||
|
checkPasswordRepeatDay(user);
|
||||||
|
/* 密码 密码正则校验 */
|
||||||
|
checkPasswordRepeat(user.getUserLoginPassword());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码长度检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordLength(String content) {
|
||||||
|
int length = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_LENGTH, CommonConstWords.CONFIG_PWD_LENGTH_DEFAULT);
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(content) || StringUtils.length(content) < length) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("长度不够" + length + "位")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 大写字母检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordUppercaseEnglish(String content) {
|
||||||
|
boolean isUppercaseEnglish = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXIST_UPPERCASE_ENGLISH, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(content) && isUppercaseEnglish) {
|
||||||
|
char[] chars = content.toCharArray();
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
for (char ch : chars) {
|
||||||
|
// Chart ASCLL 编码比对 A-Z
|
||||||
|
if (ch >= 65 && ch <= 90) {
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num <= 0) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("必须包含大写英文")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 小写字母检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordlowerEnglish(String content) {
|
||||||
|
boolean isUppercaseEnglish = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXIST_LOWER_ENGLISH, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(content) && isUppercaseEnglish) {
|
||||||
|
char[] chars = content.toCharArray();
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
for (char ch : chars) {
|
||||||
|
// Chart ASCLL 编码比对 a-z
|
||||||
|
if (ch >= 97 && ch <= 122) {
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num <= 0) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("必须包含小写英文")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 数字检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordNumber(String content) {
|
||||||
|
boolean isUppercaseEnglish = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXIST_NUMBER, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(content) && isUppercaseEnglish) {
|
||||||
|
char[] chars = content.toCharArray();
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
for (char ch : chars) {
|
||||||
|
// Chart ASCLL 编码比对 0-9
|
||||||
|
if (ch >= 48 && ch <= 57) {
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num <= 0) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("必须包含数字")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 特殊字符检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordSpecial(String content) {
|
||||||
|
boolean isUppercaseEnglish = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXIST_NUMBER, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(content) && isUppercaseEnglish) {
|
||||||
|
char[] chars = content.toCharArray();
|
||||||
|
int num = 0;
|
||||||
|
|
||||||
|
for (char ch : chars) {
|
||||||
|
// Chart ASCLL 编码比对 特殊字符
|
||||||
|
if ((ch >= 32 && ch <= 47)|| (ch >= 58 && ch <= 64)||
|
||||||
|
(ch >= 91 && ch <= 96)|| (ch >= 123 && ch <= 126)) {
|
||||||
|
++num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (num <= 0) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("必须包含数字")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 中文字符检查
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordSpecialCn(String content) {
|
||||||
|
boolean isUppercaseEnglish = RedisCacheTool.getSysConfigBooleanVal(CommonConstWords.CONFIG_PWD_EXIST_SPECIAL_CHAR, CommonEnumUtil.TRUE_OR_FALSE.FALSE);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(content) && isUppercaseEnglish) {
|
||||||
|
if (!Pattern.compile("[\u4e00-\u9fa5]").matcher(content).find()) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("必须包含中文字符")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 近期密码重复检查
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
private void checkPasswordRepeatDay(SysUser user) {
|
||||||
|
int num = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_PWD_REPEAT_DAY, CommonConstWords.CONFIG_PWD_REPEAT_DAY_DEFAULT);
|
||||||
|
if (num > 0) {
|
||||||
|
try {
|
||||||
|
SysUserPassword userPassword = new SysUserPassword();
|
||||||
|
userPassword.setUserId(user.getId());
|
||||||
|
userPassword.setUserPassword(EncryptTool.hexMD5(user.getUserLoginPassword()));
|
||||||
|
|
||||||
|
List<SysUserPassword> passwords = userPasswordService.findAllByBean(userPassword);
|
||||||
|
|
||||||
|
int lastDay = Integer.MAX_VALUE;
|
||||||
|
if (CollectionUtils.isNotEmpty(passwords)) {
|
||||||
|
for (SysUserPassword password : passwords) {
|
||||||
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
||||||
|
if (day < lastDay) {
|
||||||
|
lastDay = day;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastDay <= num) {
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("请勿使用重复密码")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.error("密码加密错误,异常信息:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码 正则表达式教研
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
*/
|
||||||
|
private void checkPasswordRepeat(String content) {
|
||||||
|
String regulars = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_PWD_REPEAT_REGULARS);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(regulars) && regulars.indexOf(",") != -1) {
|
||||||
|
String[] split = regulars.split(",");
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (String compile : split) {
|
||||||
|
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+"】密码校验不通过")
|
||||||
|
.setErrorSolution("请重新输入")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (ImppBusiException e){
|
||||||
|
// 业务异常 抛出
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/******************************************** 用户登录密码检查 ********************************************/
|
||||||
|
public void checkSysUserLogin(SysUser user) {
|
||||||
|
if(ImppSwitchUtil.isLoginActiveDirectory()){
|
||||||
|
// 使用AD域账号登录
|
||||||
|
checkActiveDirectory(user);
|
||||||
|
}else{
|
||||||
|
/* 检查密码有效期 */
|
||||||
|
checkLoginPasswordTimeOut(user);
|
||||||
|
/* 登录 长时间未登录锁定 */
|
||||||
|
checkLoginTimeOut(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号 ActiveDirectory 登录集成
|
||||||
|
* @param user
|
||||||
|
*/
|
||||||
|
public void checkActiveDirectory(SysUser user) {
|
||||||
|
if(ImppSwitchUtil.isLoginActiveDirectory()){
|
||||||
|
String activeDirectoryUrl = RedisCacheTool.getSysConfigStrVal(CommonConstWords.CONFIG_PWD_ACTIVE_DIRECTORY_URL);
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(activeDirectoryUrl)) {
|
||||||
|
LdapContext context = ImppLdapUtils.getLdapContext(activeDirectoryUrl, user.getUserLoginName(), user.getUserLoginPassword());
|
||||||
|
if(Objects.isNull(context)){
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("ActiveDirectory 登录失败请重新登录")
|
||||||
|
.setErrorSolution("请重新操作")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 释放链接资源
|
||||||
|
context.close();
|
||||||
|
} catch (NamingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("ActiveDirectory 未配置链接地址")
|
||||||
|
.setErrorSolution("请联系管理员")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录 错误次数检查
|
||||||
|
*/
|
||||||
|
public void checkLoginErrorNumber(String loginName, ResultBean resultBean, Exception e) {
|
||||||
|
SysUser user = userService.getSysUserByLoginName(loginName);
|
||||||
|
if(Objects.nonNull(user)){
|
||||||
|
checkLoginErrorNumber(user.getId(), resultBean, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录 失败次数检查
|
||||||
|
* @param userId
|
||||||
|
* @param resultBean
|
||||||
|
* @param e
|
||||||
|
*/
|
||||||
|
public void checkLoginErrorNumber(Long userId, ResultBean resultBean, Exception e) {
|
||||||
|
int loginErrorNumberMax = RedisCacheTool.getSysConfigIntVal(CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUMBER, CommonConstWords.CONFIG_USER_LOGIN_ERROR_NUMBER_DEFAULT);
|
||||||
|
String today = TimeTool.getToday();
|
||||||
|
|
||||||
|
int loginErrorNumber = 0;
|
||||||
|
String redisKey = CommonConstWords.USER_LOGIN_ERROR + ":" + today + ":" + userId;
|
||||||
|
try {
|
||||||
|
Object redisValue = redisCore.getObject(redisKey);
|
||||||
|
if(Objects.nonNull(redisValue)){
|
||||||
|
loginErrorNumber = (Integer)redisValue;
|
||||||
|
}
|
||||||
|
}catch (Exception exception){
|
||||||
|
LOGGER.error("获取登录异常次数错误,错误信息:{}", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Objects.equals(loginErrorNumberMax,loginErrorNumber)){
|
||||||
|
// 锁定账号信息
|
||||||
|
userService.doLockSysUserById(userId);
|
||||||
|
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("账号已被锁定")
|
||||||
|
.setErrorSolution("请联系系统管理员")
|
||||||
|
.build();
|
||||||
|
}else if(loginErrorNumber > loginErrorNumberMax){
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("账号已锁定")
|
||||||
|
.setErrorSolution("请联系系统管理员")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录异常 更新登录失败次数
|
||||||
|
if(Objects.nonNull(e)){
|
||||||
|
++loginErrorNumber;
|
||||||
|
|
||||||
|
if(Objects.nonNull(resultBean)){
|
||||||
|
int num = loginErrorNumberMax - loginErrorNumber;
|
||||||
|
if(num == 0){
|
||||||
|
resultBean.setErrorMsg(resultBean.getErrorMsg() + "密码输入错误。用户已被锁定请联系管理员!");
|
||||||
|
}else{
|
||||||
|
resultBean.setErrorMsg(resultBean.getErrorMsg() + "密码输入错误。再输入错误"+ num +"次,用户将被锁定");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redisCore.putObject(redisKey,loginErrorNumber,CommonConstWords.REDIS_TIME_DAY_ONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录 检查密码有效期
|
||||||
|
*/
|
||||||
|
private void 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)){
|
||||||
|
int day = TimeTool.getSecoundsBetweenTime(4, password.getCreateDatetime(), TimeTool.getNowTime(true));
|
||||||
|
if(day > passwordDayMax){
|
||||||
|
// 锁定账号信息
|
||||||
|
userService.doLockSysUserById(user.getId());
|
||||||
|
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("账号密码已过期")
|
||||||
|
.setErrorSolution("请联系系统管理员")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (ImppBusiException e){
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e){
|
||||||
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录 长时间未登录锁定
|
||||||
|
*/
|
||||||
|
private void checkLoginTimeOut(SysUser user) {
|
||||||
|
try {
|
||||||
|
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(day > loginDayMax){
|
||||||
|
// 锁定账号信息
|
||||||
|
userService.doLockSysUserById(user.getId());
|
||||||
|
|
||||||
|
throw ImppExceptionBuilder.newInstance()
|
||||||
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
||||||
|
.setErrorCode(ImppExceptionEnum.NOT_CONFIG_EXCEPTION.getCode())
|
||||||
|
.setErrorDetail("长时间未登录账号已被锁定")
|
||||||
|
.setErrorSolution("请联系系统管理员")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch (ImppBusiException e){
|
||||||
|
throw e;
|
||||||
|
}catch (Exception e){
|
||||||
|
LOGGER.error("密码有效期处理异常,异常信息:{}", e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue