密码规则配置功能
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.njcn.user.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.user.api.fallback.PassWordRuleClientFallbackFactory;
|
||||
import com.njcn.user.pojo.po.UserStrategy;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Date: 2024/7/12 15:59【需求编号】
|
||||
*
|
||||
* @author clam
|
||||
* @version V1.0.0
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.USER,
|
||||
// url = "http://127.0.0.1:10201",
|
||||
path = "/password", fallbackFactory = PassWordRuleClientFallbackFactory.class,
|
||||
contextId = "password"
|
||||
)
|
||||
public interface PassWordRuleFeugnClient {
|
||||
@PostMapping(value = "/getUserStrategy")
|
||||
public HttpResult<UserStrategy> getUserStrategy() ;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.njcn.user.api.fallback;
|
||||
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.user.api.PassWordRuleFeugnClient;
|
||||
import com.njcn.user.pojo.po.UserStrategy;
|
||||
import com.njcn.user.utils.UserEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2021年08月24日 10:21
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PassWordRuleClientFallbackFactory implements FallbackFactory<PassWordRuleFeugnClient> {
|
||||
|
||||
|
||||
/**
|
||||
* 输出远程请求接口异常日志
|
||||
* @param cause RPC请求异常
|
||||
*/
|
||||
@Override
|
||||
public PassWordRuleFeugnClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if(cause.getCause() instanceof BusinessException){
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = UserEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new PassWordRuleFeugnClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<UserStrategy> getUserStrategy() {
|
||||
log.error("{}异常,降级处理,异常为:{}","查询密码规则",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,8 @@ public enum UserResponseEnum {
|
||||
CODE_TYPE_ERROR("A0101","验证码类型非法"),
|
||||
SEND_CODE_FAIL("A0101","验证码发送失败"),
|
||||
LOGIN_USER_DELETE("A0101", "账号已被注销"),
|
||||
LOGIN_USER_LOCKED("A0101", "账号已被锁定"),
|
||||
LOGIN_USER_OVERLIMIT("A0101", "登陆用户数不能大于配置用户并发量"),
|
||||
LOGIN_USER_LOCKED("A0102", "账号已被锁定"),
|
||||
LOGIN_USER_UNAUDITED("A0101", "账号未审核"),
|
||||
NEED_MODIFY_PASSWORD("A0101", "密码需修改"),
|
||||
LOGIN_USER_SLEEP("A0101", "账号已休眠"),
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.user.pojo.param.PassWordRuleParam;
|
||||
import com.njcn.user.pojo.po.UserStrategy;
|
||||
import com.njcn.user.service.PassWordRuleService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -53,6 +54,16 @@ public class PassWordRuleController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, passWordRuleParam, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("获取密码规则")
|
||||
@RequestMapping(value = "/getUserStrategy", method = RequestMethod.POST)
|
||||
public HttpResult<UserStrategy> getUserStrategy() {
|
||||
String methodDescribe = getMethodDescribe("getRule");
|
||||
UserStrategy userStrategy = passWordRuleService.getUserStrategy();
|
||||
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userStrategy, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@ApiOperation("解锁超级管理员")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.njcn.user.service;
|
||||
|
||||
import com.njcn.user.pojo.param.PassWordRuleParam;
|
||||
import com.njcn.user.pojo.po.UserStrategy;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
@@ -15,4 +16,6 @@ public interface PassWordRuleService {
|
||||
PassWordRuleParam getRule();
|
||||
|
||||
Boolean unlockRoot();
|
||||
|
||||
UserStrategy getUserStrategy();
|
||||
}
|
||||
|
||||
@@ -69,4 +69,12 @@ public class PassWordRuleServiceImpl implements PassWordRuleService {
|
||||
userService.lambdaUpdate().eq(User::getLoginName,"root").set(User::getState,DataStateEnum.ENABLE.getCode()).update();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserStrategy getUserStrategy() {
|
||||
return iUserStrategyService.lambdaQuery()
|
||||
.eq(UserStrategy::getType, 1)
|
||||
.eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
|
||||
.one();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.njcn.user.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -20,12 +19,10 @@ import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.common.utils.sm.DesUtils;
|
||||
import com.njcn.common.utils.sm.Sm4Utils;
|
||||
import com.njcn.db.constant.DbConstant;
|
||||
import com.njcn.device.pq.api.PqsTerminalLogsClient;
|
||||
import com.njcn.device.pq.pojo.po.PqsTerminalLogs;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import com.njcn.poi.excel.ExcelUtil;
|
||||
import com.njcn.poi.pojo.bo.BaseLineProExcelBody;
|
||||
import com.njcn.system.api.AreaFeignClient;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
@@ -55,7 +52,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.File;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -117,64 +118,64 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
||||
@Override
|
||||
public void judgeUserStatus(String loginName) {
|
||||
User user = getUserByLoginName(loginName);
|
||||
CommonResponseEnum testEnum = CommonResponseEnum.DYNAMIC_RESPONSE_ENUM;
|
||||
testEnum.setMessage("测试自定义等于失败");
|
||||
throw new BusinessException(testEnum);
|
||||
// if (Objects.isNull(user)) {
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_WRONG_PWD);
|
||||
// }
|
||||
// //超级管理员则不做任何逻辑判断
|
||||
// if (user.getType() == 0) {
|
||||
// //更新用户登录时间,以及错误登录记录的信息归零。
|
||||
// user.setState(UserState.ENABLE);
|
||||
// user.setLoginErrorTimes(0);
|
||||
// user.setLoginTime(LocalDateTime.now());
|
||||
// user.setFirstErrorTime(null);
|
||||
// user.setLockTime(null);
|
||||
// this.baseMapper.updateById(user);
|
||||
// return;
|
||||
// }
|
||||
// //根据用户类型获取对应用户策略
|
||||
// UserStrategy userStrategy = userStrategyService.lambdaQuery()
|
||||
// .eq(UserStrategy::getType, user.getCasualUser())
|
||||
// .eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
|
||||
// .one();
|
||||
// switch (user.getState()) {
|
||||
// case UserState.LOCKED:
|
||||
// LocalDateTime lockTime = user.getLockTime();
|
||||
// lockTime = lockTime.plusMinutes(userStrategy.getLockPwdTime());
|
||||
// LocalDateTime nowTime = LocalDateTime.now();
|
||||
// //判断是否满足锁定时间
|
||||
// if (nowTime.isBefore(lockTime)) {
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_LOCKED);
|
||||
// }
|
||||
// break;
|
||||
// case UserState.DELETE:
|
||||
// //用户已注销
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_DELETE);
|
||||
// case UserState.UNCHECK:
|
||||
// //用户未审核
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_UNAUDITED);
|
||||
// case UserState.SLEEP:
|
||||
// //用户已休眠
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_SLEEP);
|
||||
// case UserState.OVERDUE:
|
||||
// //用户密码已过期
|
||||
// throw new BusinessException(UserResponseEnum.LOGIN_USER_PASSWORD_EXPIRED);
|
||||
// default:
|
||||
// if (user.getPwdState() == 1) {
|
||||
// throw new BusinessException(UserResponseEnum.NEED_MODIFY_PWD);
|
||||
// }
|
||||
// //用户状态正常,判断其他细节
|
||||
// judgeFirstLogin(user, userStrategy);
|
||||
// }
|
||||
// //所有验证通过后,更新用户登录时间,以及错误登录记录的信息归零。
|
||||
// user.setState(UserState.ENABLE);
|
||||
// user.setLoginErrorTimes(0);
|
||||
// user.setLoginTime(LocalDateTime.now());
|
||||
// user.setFirstErrorTime(null);
|
||||
// user.setLockTime(null);
|
||||
// this.baseMapper.updateById(user);
|
||||
|
||||
if (Objects.isNull(user)) {
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_WRONG_PWD);
|
||||
}
|
||||
//超级管理员则不做任何逻辑判断
|
||||
if (user.getType() == 0) {
|
||||
//更新用户登录时间,以及错误登录记录的信息归零。
|
||||
user.setState(UserState.ENABLE);
|
||||
user.setLoginErrorTimes(0);
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
user.setFirstErrorTime(null);
|
||||
user.setLockTime(null);
|
||||
this.baseMapper.updateById(user);
|
||||
return;
|
||||
}
|
||||
//根据用户类型获取对应用户策略
|
||||
UserStrategy userStrategy = userStrategyService.lambdaQuery()
|
||||
.eq(UserStrategy::getType, user.getCasualUser())
|
||||
.eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
|
||||
.one();
|
||||
switch (user.getState()) {
|
||||
case UserState.LOCKED:
|
||||
LocalDateTime lockTime = user.getLockTime();
|
||||
lockTime = lockTime.plusMinutes(userStrategy.getLockPwdTime());
|
||||
LocalDateTime nowTime = LocalDateTime.now();
|
||||
//判断是否满足锁定时间
|
||||
if (nowTime.isBefore(lockTime)) {
|
||||
CommonResponseEnum testEnum = CommonResponseEnum.DYNAMIC_RESPONSE_ENUM;
|
||||
testEnum.setMessage("账号已被锁定:锁定剩余时长"+ ChronoUnit.MINUTES.between(nowTime, lockTime)+"分钟");
|
||||
throw new BusinessException(testEnum);
|
||||
}
|
||||
break;
|
||||
case UserState.DELETE:
|
||||
//用户已注销
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_DELETE);
|
||||
case UserState.UNCHECK:
|
||||
//用户未审核
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_UNAUDITED);
|
||||
case UserState.SLEEP:
|
||||
//用户已休眠
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_SLEEP);
|
||||
case UserState.OVERDUE:
|
||||
//用户密码已过期
|
||||
throw new BusinessException(UserResponseEnum.LOGIN_USER_PASSWORD_EXPIRED);
|
||||
default:
|
||||
if (user.getPwdState() == 1) {
|
||||
throw new BusinessException(UserResponseEnum.NEED_MODIFY_PWD);
|
||||
}
|
||||
//用户状态正常,判断其他细节
|
||||
judgeFirstLogin(user, userStrategy);
|
||||
}
|
||||
//所有验证通过后,更新用户登录时间,以及错误登录记录的信息归零。
|
||||
user.setState(UserState.ENABLE);
|
||||
user.setLoginErrorTimes(0);
|
||||
user.setLoginTime(LocalDateTime.now());
|
||||
user.setFirstErrorTime(null);
|
||||
user.setLockTime(null);
|
||||
this.baseMapper.updateById(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user