Skip to content

Commit

Permalink
🐛 修复脱敏注解名称调整导致的坏代码
Browse files Browse the repository at this point in the history
  • Loading branch information
evil0th authored and Hccake committed Apr 22, 2024
1 parent 80f19bc commit 64cb0b5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.ballcat.business.system.desensitize.rule;

import org.ballcat.desensitize.rule.regex.RegexDesensitizeRule;

/**
* 【密文】脱敏,前3后2,中间替换为 4个 * eg. 3950587458326514452641976780061 -> 395****61
*
* @author evil0th
* @since 2.0.0
*/
public class KeyRegexDesensitizeRule implements RegexDesensitizeRule {

@Override
public String getRegex() {
return "(.{3}).*(.{2}$)";
}

@Override
public String getReplacement() {
return "$1****$2";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.ballcat.business.system.desensitize.rule.KeyRegexDesensitizeRule;
import org.ballcat.common.core.validation.group.CreateGroup;
import org.ballcat.common.core.validation.group.UpdateGroup;
import org.ballcat.desensitize.enums.RegexDesensitizationTypeEnum;
import org.ballcat.desensitize.json.annotation.JsonRegexDesensitize;
import org.ballcat.desensitize.annotation.RegexDesensitize;
import org.hibernate.validator.constraints.Range;

/**
Expand All @@ -50,7 +50,7 @@ public class SysUserDTO {
* 前端传入密码
*/
@NotEmpty(message = "pass {}", groups = CreateGroup.class)
@JsonRegexDesensitize(type = RegexDesensitizationTypeEnum.ENCRYPTED_PASSWORD)
@RegexDesensitize(rule = KeyRegexDesensitizeRule.class)
@Schema(title = "前端传入密码")
private String pass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.ballcat.desensitize.enums.RegexDesensitizationTypeEnum;
import org.ballcat.desensitize.json.annotation.JsonRegexDesensitize;
import org.ballcat.business.system.desensitize.rule.KeyRegexDesensitizeRule;
import org.ballcat.desensitize.annotation.RegexDesensitize;

/**
* 用户密码传输DTO,字段序列化时忽略,防止记录
Expand All @@ -36,15 +36,15 @@ public class SysUserPassDTO {
* 前端传入密码
*/
@NotBlank(message = "The password cannot be empty!")
@JsonRegexDesensitize(type = RegexDesensitizationTypeEnum.ENCRYPTED_PASSWORD)
@RegexDesensitize(rule = KeyRegexDesensitizeRule.class)
@Schema(title = "前端输入密码")
private String pass;

/**
* 前端确认密码
*/
@NotBlank(message = "The confirm password cannot be empty!")
@JsonRegexDesensitize(type = RegexDesensitizationTypeEnum.ENCRYPTED_PASSWORD)
@RegexDesensitize(rule = KeyRegexDesensitizeRule.class)
@Schema(title = "前端确认密码")
private String confirmPass;

Expand Down

0 comments on commit 64cb0b5

Please sign in to comment.