App用户密码调整

This commit is contained in:
2023-08-23 15:54:00 +08:00
parent 487a5f79c7
commit 39c910a33d
12 changed files with 209 additions and 9 deletions

View File

@@ -17,6 +17,12 @@ public interface PatternRegex {
*/
String PASSWORD_REGEX = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[\\=\\[\\]\\{\\}\\.\\,\\\\\\@\\#\\_\\!\\$\\%\\^\\&\\*\\(\\)\\?\\<\\>\\/\\|\\~,\\-\\+]).{8,16}$";
/**
* APP密码长度为8-16
*/
String APP_PASSWORD_REGEX = "{8,16}$";
/**
* 手机的密码
*/

View File

@@ -17,6 +17,11 @@ public interface BusinessTopic {
*/
String NJCN_APP_EVENT_TOPIC = "njcnAppEventTopic";
/**
* 治理告警接收主题
*/
String NJCN_APP_WARN_TOPIC = "njcnAppWarnTopic";
interface AppDataTag {
@@ -31,5 +36,21 @@ public interface BusinessTopic {
String RT_TAG = "rt";
}
interface AppEventTag {
/**
* 暂态事件(录波)tag
*/
String EVENT_TAG = "event";
}
interface AppWarnTag {
/**
* 告警事件tag
*/
String WARN_TAG = "warn";
}
}

View File

@@ -0,0 +1,77 @@
package com.njcn.mq.message;
import com.njcn.middle.rocket.domain.BaseMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/8/22 11:06
*/
@Data
public class AppEventMessage extends BaseMessage {
@ApiModelProperty("网络设备码")
private String id;
private Integer mid;
@ApiModelProperty("逻辑设备 治理逻辑设备为1 电能质量设备为2")
private Integer did;
private Integer pri;
private Integer type;
private Msg msg;
@Data
public static class Msg{
@ApiModelProperty("逻辑子设备 治理逻辑设备为0 电能质量设备为1、2")
private Integer clDid;
private Integer dataType;
@ApiModelProperty("数据属性:无-0、实时-1、统计-2")
private Integer dataAttr;
private Integer dsNameIdx;
private List<DataArray> dataArray;
}
@Data
public static class DataArray{
private Integer idx;
private String name;
private Long dataTimeSec;
private Long dataTimeUSec;
@ApiModelProperty("事件类型")
private String type;
private List<Param> param;
}
@Data
public static class Param{
private String name;
private String type;
private String unit;
private Object data;
}
}

View File

@@ -0,0 +1,29 @@
package com.njcn.mq.template;
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
import com.njcn.mq.constant.BusinessResource;
import com.njcn.mq.constant.BusinessTopic;
import com.njcn.mq.message.AppEventMessage;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/8/11 15:28
*/
@Component
public class AppEventMessageTemplate extends RocketMQEnhanceTemplate {
public AppEventMessageTemplate(RocketMQTemplate template) {
super(template);
}
public SendResult sendMember(AppEventMessage appEventMessage) {
appEventMessage.setSource(BusinessResource.APP_RESOURCE);
return send(BusinessTopic.NJCN_APP_EVENT_TOPIC, BusinessTopic.AppEventTag.EVENT_TAG, appEventMessage);
}
}

View File

@@ -7,6 +7,7 @@ import com.njcn.system.pojo.dto.EpdDTO;
import com.njcn.system.pojo.param.EleEpdPqdParam;
import com.njcn.system.pojo.po.EleEpdPqd;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@@ -48,4 +49,7 @@ public interface EpdFeignClient {
@PostMapping("/findAll")
HttpResult<List<EpdDTO>> findAll();
@PostMapping("/findByName")
HttpResult<EleEpdPqd> findByName(@RequestParam("name") String name);
}

View File

@@ -88,6 +88,12 @@ public class EpdFeignClientFallbackFactory implements FallbackFactory<EpdFeignCl
log.error("{}异常,降级处理,异常为:{}","查询所有字典数据",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override
public HttpResult<EleEpdPqd> findByName(String name) {
log.error("{}异常,降级处理,异常为:{}","根据名称查询字典信息",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}

View File

@@ -196,12 +196,23 @@ public class EleEpdPqdController extends BaseController {
@PostMapping("/findAll")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("查询所有字典数据")
// @ApiIgnore
@ApiIgnore
public HttpResult<List<EpdDTO>> findAll(){
String methodDescribe = getMethodDescribe("findAll");
List<EpdDTO> list = eleEpdPqdService.findAll();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@PostMapping("/findByName")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("根据名称查询字典信息")
@ApiImplicitParam(name = "name", value = "指标名称", required = true)
@ApiIgnore
public HttpResult<EleEpdPqd> findByName(@RequestParam("name") @Validated String name){
String methodDescribe = getMethodDescribe("findByName");
EleEpdPqd po = eleEpdPqdService.lambdaQuery().eq(EleEpdPqd::getName,name).one();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
}

View File

@@ -48,6 +48,7 @@ public enum UserResponseEnum {
INVALID_TIME("A0101", "用户当前时间段禁止访问"),
PASSWORD_TRANSPORT_ERROR("A0101", "密码传输完整性被破坏"),
SPECIAL_PASSWORD("A0101", "密码需要包含特殊字符字母数字长度为8-16"),
APP_PASSWORD("A0101", "密码长度为8-16"),
REPEAT_PASSWORD("A0101", "新密码与旧密码不能一致"),
REGISTER_FAIL("A0102", "注册失败"),

View File

@@ -34,7 +34,7 @@ public interface IUserSetService extends IService<UserSet> {
* @author xy
* @date 2022/1/21 12:39
*/
String updatePassword(String id,String newPassword);
String updatePassword(String id,String newPassword, Boolean result);
/**
* 功能描述: 未登录 修改用户密码

View File

@@ -228,7 +228,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
if (Objects.isNull(user)){
throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_NOT_FOUND);
}
String secretPassword = userSetService.updatePassword(userId, password);
String secretPassword = userSetService.updatePassword(userId, password,false);
user.setPassword(secretPassword);
user.setPwdValidity(LocalDateTime.now());
user.setLoginTime(LocalDateTime.now());
@@ -252,7 +252,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, User> impleme
if (Objects.isNull(user)){
throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_NOT_FOUND);
}
String secretPassword = userSetService.updatePassword(user.getId(), password);
String secretPassword = userSetService.updatePassword(user.getId(), password,false);
user.setPassword(secretPassword);
user.setPwdValidity(LocalDateTime.now());
user.setLoginTime(LocalDateTime.now());

View File

@@ -349,7 +349,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
@Override
public boolean updatePassword(String id, String password) {
String secretPassword = userSetService.updatePassword(id, password);
String secretPassword = userSetService.updatePassword(id, password,true);
User user = lambdaQuery().eq(User::getId, id).one();
user.setPassword(secretPassword);
user.setPwdValidity(LocalDateTime.now());

View File

@@ -65,15 +65,15 @@ public class UserSetServiceImpl extends ServiceImpl<UserSetMapper, UserSet> impl
}
@Override
public String updatePassword(String id,String newPassword) {
public String updatePassword(String id,String newPassword,Boolean result) {
String password = getSecretPassword(newPassword);
return updatePsd(id,password);
return updatePsd(id,password,result);
}
@Override
public String updateFirstPassword(String id, String newPassword, String name, String ip) {
String password = getSecretPasswordNotLogin(newPassword, name, ip);
return updatePsd(id,password);
return updatePsd(id,password,true);
}
@Override
@@ -110,7 +110,52 @@ public class UserSetServiceImpl extends ServiceImpl<UserSetMapper, UserSet> impl
* @param password
* @return
*/
private String updatePsd(String id, String password) {
private String updatePsd(String id, String password,Boolean result) {
Sm4Utils sm4;
String psd,strSm4;
if (result){
String standard = PatternRegex.PASSWORD_REGEX;
Pattern pattern = Pattern.compile(standard);
Matcher m=pattern.matcher(password);
if (!m.find()){
throw new BusinessException(UserResponseEnum.SPECIAL_PASSWORD);
}
//密码是否需要复杂校验
} else {
String standard = PatternRegex.APP_PASSWORD_REGEX;
Pattern pattern = Pattern.compile(standard);
Matcher m=pattern.matcher(password);
if (!m.find()){
throw new BusinessException(UserResponseEnum.APP_PASSWORD);
}
}
UserSet userSet = this.lambdaQuery().eq(UserSet::getUserId, id).one();
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("sys_user.id",id);
User user = userMapper.selectOne(userQueryWrapper);
String secretPassword = user.getPassword();
if (Objects.isNull(userSet)){
UserSet newUserSet = new UserSet();
String secretKey = PubUtils.randomCode(16);
newUserSet.setSecretKey(secretKey);
sm4 = new Sm4Utils(secretKey);
strSm4 = sm4.encryptData_ECB(password);
newUserSet.setStandBy(strSm4);
newUserSet.setUserId(id);
this.save(newUserSet);
psd = sm4.encryptData_ECB(strSm4 + secretKey);
} else {
sm4 = new Sm4Utils(userSet.getSecretKey());
strSm4 = sm4.encryptData_ECB(password);
psd = sm4.encryptData_ECB(strSm4 + userSet.getSecretKey());
}
if (Objects.equals(secretPassword,psd)){
throw new BusinessException(UserResponseEnum.REPEAT_PASSWORD);
}
return psd;
}
private String updateAppPsd(String id, String password) {
Sm4Utils sm4;
String psd,strSm4;
String standard = PatternRegex.PASSWORD_REGEX;