| | |
| | | import org.apache.ibatis.reflection.MetaObject; |
| | | import org.apache.ibatis.reflection.SystemMetaObject; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Field; |
| | |
| | | @Slf4j |
| | | @ConditionalOnProperty(value = "domain.sensitive", havingValue = "true") |
| | | @Component |
| | | @Order(120) |
| | | public class SensitiveInterceptor implements Interceptor { |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | |
| | | |
| | | |
| | | private void sensitive(Object source) { |
| | | // 拿到返回值类型 |
| | | Class<?> sourceClass = source.getClass(); |
| | | // 初始化返回值类型的 MetaObject |
| | | MetaObject metaObject = SystemMetaObject.forObject(source); |
| | | // 捕捉到属性上的标记注解 @Sensitive 并进行对应的脱敏处理 |
| | | Stream.of(sourceClass.getDeclaredFields()) |
| | | .filter(field -> field.isAnnotationPresent(Sensitive.class)) |
| | | .forEach(field -> doSensitive(metaObject, field)); |
| | | if(source!=null) { |
| | | // 拿到返回值类型 |
| | | Class<?> sourceClass = source.getClass(); |
| | | // 初始化返回值类型的 MetaObject |
| | | MetaObject metaObject = SystemMetaObject.forObject(source); |
| | | // 捕捉到属性上的标记注解 @Sensitive 并进行对应的脱敏处理 |
| | | Stream.of(sourceClass.getDeclaredFields()) |
| | | .filter(field -> field.isAnnotationPresent(Sensitive.class)) |
| | | .forEach(field -> doSensitive(metaObject, field)); |
| | | } |
| | | } |
| | | |
| | | |