@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceSensitiveMethod {
booleanenabled() defaulttrue;
booleanencParamEnabled() defaultfalse;
booleanencResultEnabled() defaultfalse;
booleansensitiveResultEnabled() defaulttrue;
ClasssensitiveClass() defaultInteger.class;
SensitiveMapMeta[] sensitiveMapMeta() default {};
}
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceSensitiveMapMeta {
Stringkey() default"";
ClasssensitiveClass() defaultInteger.class;
booleanencResultEnabled() defaultfalse;
booleansensitiveResultEnabled() defaulttrue;
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceEncMeta {
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceEncSubMeta {
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceSensitiveMeta {
intrpStart() default0;
intrpEnd() default1;
StringrpSymbol() default"*";
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documentedpublic@interfaceSensitiveSubMeta {
}
@Slf4j@Aspect@Order(Ordered.LOWEST_PRECEDENCE-100)
@Component@ConditionalOnProperty(prefix="open.advice.sensitive", name="enabled", havingValue="true")
publicclassSensitiveInfoAspect {
@AutowiredprivateListsensitiveManageChain=newCopyOnWriteArrayList<>();
@AutowiredprivateTransSensitiveFieldProvidertransSensitiveField;
@Pointcut("@annotation(com.open.util.entity.annotation.SensitiveMethod)")
privatevoidallAnnotationMethod() {
}
@Around("allAnnotationMethod()")
publicObjectdoAround(ProceedingJoinPointpoint) throwsThrowable {
MethodSignaturesignature= (MethodSignature) point.getSignature();
Methodmethod=signature.getMethod();
SensitiveMethodsensitiveMethodMeta=method.getAnnotation(SensitiveMethod.class);
if (sensitiveMethodMeta.encParamEnabled()) {
ArrayListdecFields=newArrayList<>();
Object[] args=point.getArgs();
Annotation[][] paramAnnotations=method.getParameterAnnotations();
for (inti=0; i<paramAnnotations.length; i++) {
for (intj=0; j<paramAnnotations[i].length; j++) {
AnnotationcurrentAnnotation=paramAnnotations[i][j];
Objectarg=args[i];
if (currentAnnotationinstanceofRequestBody&&Objects.nonNull(arg)) {
Field[] fields=arg.getClass().getDeclaredFields();
transSensitiveField.classifyFields(arg.getClass(), fields, decFields, null, null, null);
log.debug("Source args[{}] value {}", i, arg);
decFields.forEach(e->transSensitiveField.decField(e, arg));
}
}
}
}
ObjecttempObj=point.proceed();
if (!sensitiveMethodMeta.enabled() ||Objects.isNull(tempObj)) {
returntempObj;
}
ListsortedChain=sensitiveManageChain.stream()
.sorted(Comparator.comparing(SensitiveManageChain::getOrder)).collect(Collectors.toList());
for (inti=0; i<sortedChain.size() -1; i++) {
sortedChain.get(i).setNextChain(sortedChain.get(i+1));
}
returnsortedChain.get(0).sensitiveHand(tempObj, method, sensitiveMethodMeta, null, newArrayList<>(), newArrayList<>(),
newArrayList<>(), newArrayList<>(), sortedChain);
}
}