style: 应用 Spotless 代码格式化
- 对所有 Java 源文件应用统一的代码格式化 - 统一缩进为 4 个空格 - 清理尾随空白字符和文件末尾换行 - 优化导入语句组织 - 总计格式化 654 个 Java 文件 有问题可以回滚或者找我聊
This commit is contained in:
@@ -2,7 +2,6 @@ package com.starry.common.sensitive;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@@ -6,16 +6,15 @@ 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 lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* <p>
|
||||
* 脱敏序列化
|
||||
* <p>
|
||||
* 脱敏序列化
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@@ -25,30 +24,31 @@ public class SensitiveSerialize extends JsonSerializer<String> implements Contex
|
||||
|
||||
@Override
|
||||
public void serialize(final String originStr, final JsonGenerator jsonGenerator,
|
||||
final SerializerProvider serializerProvider) throws IOException {
|
||||
final SerializerProvider serializerProvider) throws IOException {
|
||||
switch (type) {
|
||||
case CHINESE_NAME:
|
||||
case CHINESE_NAME :
|
||||
jsonGenerator.writeString(SensitiveUtils.chineseName(originStr));
|
||||
break;
|
||||
case MOBILE_PHONE:
|
||||
case MOBILE_PHONE :
|
||||
jsonGenerator.writeString(SensitiveUtils.mobilePhone(originStr));
|
||||
break;
|
||||
case EMAIL:
|
||||
case EMAIL :
|
||||
jsonGenerator.writeString(SensitiveUtils.email(originStr));
|
||||
break;
|
||||
case PASSWORD:
|
||||
case PASSWORD :
|
||||
jsonGenerator.writeString(SensitiveUtils.password(originStr));
|
||||
break;
|
||||
case KEY:
|
||||
case KEY :
|
||||
jsonGenerator.writeString(SensitiveUtils.key(originStr));
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
throw new IllegalArgumentException("未定义的敏感信息枚举类" + type);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonSerializer<?> createContextual(final SerializerProvider serializerProvider, final BeanProperty beanProperty) throws JsonMappingException {
|
||||
public JsonSerializer<?> createContextual(final SerializerProvider serializerProvider,
|
||||
final BeanProperty beanProperty) throws JsonMappingException {
|
||||
if (beanProperty != null) {
|
||||
if (Objects.equals(beanProperty.getType().getRawClass(), String.class)) {
|
||||
Sensitive sensitive = beanProperty.getAnnotation(Sensitive.class);
|
||||
|
||||
@@ -32,10 +32,14 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 对字符串进行脱敏操作
|
||||
*
|
||||
* @param originStr 原始字符串
|
||||
* @param prefixNoMaskLen 左侧需要保留几位明文字段
|
||||
* @param suffixNoMaskLen 右侧需要保留几位明文字段
|
||||
* @param maskStr 用于遮罩的字符串, 如'*'
|
||||
* @param originStr
|
||||
* 原始字符串
|
||||
* @param prefixNoMaskLen
|
||||
* 左侧需要保留几位明文字段
|
||||
* @param suffixNoMaskLen
|
||||
* 右侧需要保留几位明文字段
|
||||
* @param maskStr
|
||||
* 用于遮罩的字符串, 如'*'
|
||||
* @return 脱敏后结果
|
||||
*/
|
||||
public static String process(String originStr, int prefixNoMaskLen, int suffixNoMaskLen, String maskStr) {
|
||||
@@ -61,7 +65,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 中文姓名只显示最后一个汉字
|
||||
*
|
||||
* @param fullName 姓名
|
||||
* @param fullName
|
||||
* 姓名
|
||||
* @return
|
||||
*/
|
||||
public static String chineseName(String fullName) {
|
||||
@@ -74,7 +79,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 手机号码前三位,后四位,如186****2356
|
||||
*
|
||||
* @param num 手机号码
|
||||
* @param num
|
||||
* 手机号码
|
||||
* @return
|
||||
*/
|
||||
public static String mobilePhone(String num) {
|
||||
@@ -84,7 +90,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 地址只显示到地区
|
||||
*
|
||||
* @param address 地址
|
||||
* @param address
|
||||
* 地址
|
||||
* @return
|
||||
*/
|
||||
public static String address(String address) {
|
||||
@@ -94,7 +101,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 电子邮箱 仅显示第一个字母,@后面的地址显示,比如:r**@qq.com
|
||||
*
|
||||
* @param email 电子邮箱
|
||||
* @param email
|
||||
* 电子邮箱
|
||||
* @return
|
||||
*/
|
||||
public static String email(String email) {
|
||||
@@ -113,7 +121,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 密码的全部字符,如:******
|
||||
*
|
||||
* @param password 密码
|
||||
* @param password
|
||||
* 密码
|
||||
* @return
|
||||
*/
|
||||
public static String password(String password) {
|
||||
@@ -126,7 +135,8 @@ public class SensitiveUtils {
|
||||
/**
|
||||
* 密钥除了最后三位,全部,比如:***klo
|
||||
*
|
||||
* @param key 密钥
|
||||
* @param key
|
||||
* 密钥
|
||||
* @return 结果
|
||||
*/
|
||||
public static String key(String key) {
|
||||
@@ -152,4 +162,4 @@ public class SensitiveUtils {
|
||||
String s = mobilePhone("18653653621");
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user