mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-10 08:50:29 +08:00
chore(v0.11): 全路径纳入版本库与走查整改
- .gitignore:显式放行全部 maven-*、scripts、dev-support、frontend、反1、artifacts、历史导出目录
- 新增跟踪:device-manager/device-sdk/legacy-public、davinci-manager、cwos-*、cwos-resource 等源码与附属资源
- davinci FileStorageManagerImpl:Feign Response 关闭、绝对 URL 拉流 SSRF 校验(协议/主机/解析地址)
- davinci OuterCallFeignClient:补充契约说明
- cwos-common-aks AksConstant:final 类 + 私有构造防误实例化
- device-manager DeviceConstant:沿用 DEFAULT_APPLICATIONID 拼写修正
Made-with: Cursor
Former-commit-id: 0a34c76a82
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
package cn.cloudwalk.cloud.sensitive;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract class AbstractSensitiveHandler
|
||||
implements SensitiveHandler
|
||||
{
|
||||
public String sensitive(String text, SensitiveType type) {
|
||||
if (type.equals(strategy())) {
|
||||
return sensitive(text);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract SensitiveType strategy();
|
||||
|
||||
public abstract String sensitive(String paramString);
|
||||
}
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package cn.cloudwalk.cloud.sensitive;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.BankCardSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.ChineseNameSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.CnapsCodeSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.EmailSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.FixedPhoneSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.IdCardSensitiveHandler;
|
||||
import cn.cloudwalk.cloud.sensitive.handler.MobilePhoneSensitiveHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class CompositeSensitiveHandler
|
||||
implements SensitiveHandler
|
||||
{
|
||||
private static List<SensitiveHandler> SENSITIVE_HANDLER_LIST = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
static {
|
||||
SENSITIVE_HANDLER_LIST.add(new IdCardSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new EmailSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new BankCardSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new CnapsCodeSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new FixedPhoneSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new ChineseNameSensitiveHandler());
|
||||
SENSITIVE_HANDLER_LIST.add(new MobilePhoneSensitiveHandler());
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text, SensitiveType type) {
|
||||
for (SensitiveHandler handler : SENSITIVE_HANDLER_LIST) {
|
||||
String result = handler.sensitive(text, type);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package cn.cloudwalk.cloud.sensitive;
|
||||
|
||||
import cn.cloudwalk.cloud.annotation.I8ndescribed;
|
||||
import cn.cloudwalk.cloud.utils.ApplicationContextUtils;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.BeanProperty;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class I8ndescribedSerialize
|
||||
extends JsonSerializer<String>
|
||||
implements ContextualSerializer
|
||||
{
|
||||
private I8ndescribed i8ndescribed;
|
||||
|
||||
public I8ndescribedSerialize() {}
|
||||
|
||||
public I8ndescribedSerialize(I8ndescribed i8ndescribed) {
|
||||
this.i8ndescribed = i8ndescribed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||
if (property != null) {
|
||||
if (Objects.equals(property.getType().getRawClass(), String.class)) {
|
||||
|
||||
I8ndescribed cloudwalkI8N = (I8ndescribed)property.getAnnotation(I8ndescribed.class);
|
||||
if (cloudwalkI8N == null) {
|
||||
cloudwalkI8N = (I8ndescribed)property.getContextAnnotation(I8ndescribed.class);
|
||||
}
|
||||
|
||||
if (cloudwalkI8N != null) {
|
||||
return new I8ndescribedSerialize(cloudwalkI8N);
|
||||
}
|
||||
}
|
||||
|
||||
return prov.findValueSerializer(property.getType(), property);
|
||||
}
|
||||
|
||||
return prov.findNullValueSerializer(property);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
|
||||
if (this.i8ndescribed == null) {
|
||||
gen.writeString(value);
|
||||
} else {
|
||||
gen.writeString(ApplicationContextUtils.getMessage(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package cn.cloudwalk.cloud.sensitive;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
|
||||
public interface SensitiveHandler {
|
||||
String sensitive(String paramString, SensitiveType paramSensitiveType);
|
||||
}
|
||||
|
||||
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package cn.cloudwalk.cloud.sensitive;
|
||||
|
||||
import cn.cloudwalk.cloud.annotation.SensitiveField;
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.BeanProperty;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class SensitiveInfoSerialize
|
||||
extends JsonSerializer<String>
|
||||
implements ContextualSerializer
|
||||
{
|
||||
/* 34 */ private static final Logger logger = LoggerFactory.getLogger(SensitiveInfoSerialize.class);
|
||||
|
||||
|
||||
|
||||
|
||||
/* 39 */ private static CompositeSensitiveHandler handler = new CompositeSensitiveHandler();
|
||||
|
||||
|
||||
|
||||
|
||||
private SensitiveField sensitiveField;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public SensitiveInfoSerialize() {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public SensitiveInfoSerialize(SensitiveField sensitiveField) {
|
||||
/* 57 */ this.sensitiveField = sensitiveField;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
|
||||
/* 64 */ if (property != null) {
|
||||
|
||||
|
||||
/* 67 */ if (Objects.equals(property.getType().getRawClass(), String.class)) {
|
||||
|
||||
|
||||
/* 70 */ SensitiveField sensitiveField = (SensitiveField)property.getAnnotation(SensitiveField.class);
|
||||
/* 71 */ if (sensitiveField == null) {
|
||||
/* 72 */ sensitiveField = (SensitiveField)property.getContextAnnotation(SensitiveField.class);
|
||||
}
|
||||
|
||||
|
||||
/* 76 */ if (sensitiveField != null) {
|
||||
/* 77 */ return new SensitiveInfoSerialize(sensitiveField);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
/* 82 */ logger.debug("未对字段进行序列化,因为数据类型非String");
|
||||
}
|
||||
|
||||
/* 85 */ return prov.findValueSerializer(property.getType(), property);
|
||||
}
|
||||
|
||||
/* 88 */ return prov.findNullValueSerializer(property);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
|
||||
/* 95 */ SensitiveType type = this.sensitiveField.type();
|
||||
/* 96 */ if (!SensitiveType.NULL.equals(type)) {
|
||||
/* 97 */ String ret = handler.sensitive(value, type);
|
||||
/* 98 */ gen.writeString(ret);
|
||||
} else {
|
||||
gen.writeString(split(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String split(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = text.length();
|
||||
if (this.sensitiveField.prefix() + this.sensitiveField.suffix() >= length) {
|
||||
return text;
|
||||
}
|
||||
|
||||
String left = StringUtils.left(text, this.sensitiveField.prefix());
|
||||
String right = StringUtils.right(text, this.sensitiveField.suffix());
|
||||
|
||||
length = this.sensitiveField.suffix() + this.sensitiveField.split();
|
||||
return left.concat(StringUtils.leftPad(right, length, '*'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package cn.cloudwalk.cloud.sensitive.configuration;
|
||||
|
||||
import cn.cloudwalk.cloud.sensitive.introspector.DisableI8ndescribedIntrospector;
|
||||
import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({I8ndescribedProperties.class})
|
||||
@ConditionalOnProperty(name = {"disable"}, havingValue = "true", matchIfMissing = false, prefix = "cloudwalk.i8ndescribed")
|
||||
public class I8ndescribedConfiguration
|
||||
{
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Bean
|
||||
public DisableI8ndescribedIntrospector disableI8ndescribedIntrospector() {
|
||||
DisableI8ndescribedIntrospector intrspector = new DisableI8ndescribedIntrospector();
|
||||
this.objectMapper.setAnnotationIntrospector((AnnotationIntrospector)intrspector);
|
||||
|
||||
return intrspector;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package cn.cloudwalk.cloud.sensitive.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ConfigurationProperties(prefix = "cloudwalk.sensitive")
|
||||
public class I8ndescribedProperties
|
||||
{
|
||||
public static final String I8NDESCRIBED_PREFIX = "cloudwalk.i8ndescribed";
|
||||
public static final String I8NDESCRIBED_DISABLE_VALUE = "true";
|
||||
public static final String I8NDESCRIBED_KEY = "disable";
|
||||
private String disable = "true";
|
||||
|
||||
public String getDisable() {
|
||||
return this.disable;
|
||||
}
|
||||
|
||||
public void setDisable(String disable) {
|
||||
this.disable = disable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package cn.cloudwalk.cloud.sensitive.configuration;
|
||||
|
||||
import cn.cloudwalk.cloud.sensitive.introspector.DisableSensitiveInfoIntrospector;
|
||||
import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({SensitiveInfoProperties.class})
|
||||
@ConditionalOnProperty(name = {"disable"}, havingValue = "true", matchIfMissing = false, prefix = "cloudwalk.sensitive")
|
||||
public class SensitiveInfoConfiguration
|
||||
{
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Bean
|
||||
public DisableSensitiveInfoIntrospector disableSensitiveInfoIntrospector() {
|
||||
DisableSensitiveInfoIntrospector intrspector = new DisableSensitiveInfoIntrospector();
|
||||
this.objectMapper.setAnnotationIntrospector((AnnotationIntrospector)intrspector);
|
||||
|
||||
return intrspector;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package cn.cloudwalk.cloud.sensitive.configuration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ConfigurationProperties(prefix = "cloudwalk.sensitive")
|
||||
public class SensitiveInfoProperties
|
||||
{
|
||||
public static final String FIELD_SENSITIVE_PREFIX = "cloudwalk.sensitive";
|
||||
public static final String FIELD_SENSITIVE_DISABLE_VALUE = "true";
|
||||
public static final String FIELD_SENSITIVE_KEY = "disable";
|
||||
private String disable = "true";
|
||||
|
||||
public String getDisable() {
|
||||
return this.disable;
|
||||
}
|
||||
|
||||
public void setDisable(String disable) {
|
||||
this.disable = disable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class BankCardSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.BANK_CARD;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
if (length < 10) {
|
||||
return text;
|
||||
}
|
||||
String left = StringUtils.left(text, 6);
|
||||
String right = StringUtils.right(text, 4);
|
||||
|
||||
return left.concat(StringUtils.removeStart(StringUtils.leftPad(right, length, '*'), "******"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ChineseNameSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.CHINESE_NAME;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
String w = StringUtils.left(text, 1);
|
||||
|
||||
return StringUtils.rightPad(w, (length > 4) ? 4 : length, '*');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class CnapsCodeSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.CNAPS_CODE;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
if (length < 2) {
|
||||
return text;
|
||||
}
|
||||
String left = StringUtils.left(text, 2);
|
||||
return StringUtils.rightPad(left, length, '*');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class EmailSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.EMAIL;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int index = StringUtils.indexOf(text, 64);
|
||||
if (index <= 1) {
|
||||
return text;
|
||||
}
|
||||
return StringUtils.rightPad(StringUtils.left(text, 1), index, '*')
|
||||
.concat(StringUtils.mid(text, index, StringUtils.length(text)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class FixedPhoneSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.FIXED_PHONE;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
if (length <= 4) {
|
||||
return text;
|
||||
}
|
||||
String last = StringUtils.right(text, 4);
|
||||
return StringUtils.leftPad(last, length, '*');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class IdCardSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
private static final int ID_CARD_LENGTH = 8;
|
||||
private static final int PRE_CHAR_LENGTH = 3;
|
||||
private static final int LST_CHAR_LENGTH = 4;
|
||||
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.ID_CARD;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
if (length < 8) {
|
||||
return text;
|
||||
}
|
||||
String pre = StringUtils.left(text, 3);
|
||||
String num = StringUtils.right(text, 4);
|
||||
|
||||
return pre.concat(StringUtils.leftPad(num, 8, '*'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package cn.cloudwalk.cloud.sensitive.handler;
|
||||
|
||||
import cn.cloudwalk.cloud.enums.SensitiveType;
|
||||
import cn.cloudwalk.cloud.sensitive.AbstractSensitiveHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class MobilePhoneSensitiveHandler
|
||||
extends AbstractSensitiveHandler
|
||||
{
|
||||
public SensitiveType strategy() {
|
||||
return SensitiveType.MOBILE_PHONE;
|
||||
}
|
||||
|
||||
|
||||
public String sensitive(String text) {
|
||||
if (StringUtils.isBlank(text)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int length = StringUtils.length(text);
|
||||
if (length < 7) {
|
||||
return text;
|
||||
}
|
||||
String left = StringUtils.left(text, 3);
|
||||
String right = StringUtils.right(text, 4);
|
||||
|
||||
return left.concat(StringUtils.leftPad(right, 8, '*'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package cn.cloudwalk.cloud.sensitive.introspector;
|
||||
|
||||
import cn.cloudwalk.cloud.annotation.I8ndescribed;
|
||||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class DisableI8ndescribedIntrospector
|
||||
extends JacksonAnnotationIntrospector
|
||||
{
|
||||
private static final long serialVersionUID = 5915688650237481024L;
|
||||
|
||||
public boolean isAnnotationBundle(Annotation ann) {
|
||||
if (ann.annotationType().equals(I8ndescribed.class)) {
|
||||
return false;
|
||||
}
|
||||
return super.isAnnotationBundle(ann);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package cn.cloudwalk.cloud.sensitive.introspector;
|
||||
|
||||
import cn.cloudwalk.cloud.annotation.SensitiveField;
|
||||
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class DisableSensitiveInfoIntrospector
|
||||
extends JacksonAnnotationIntrospector
|
||||
{
|
||||
private static final long serialVersionUID = 5915688650237481024L;
|
||||
|
||||
public boolean isAnnotationBundle(Annotation ann) {
|
||||
if (ann.annotationType().equals(SensitiveField.class)) {
|
||||
return false;
|
||||
}
|
||||
return super.isAnnotationBundle(ann);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user