@ Aspect intercept handles custom FIELD and PARAMETER

The

project uses springboot to provide interface services. The original business is: all data submitted by consumers are all encrypted information , for example:
127.0.0.1 serviceencrypted data1 = ciphertext & data2= ciphertext & data3= ciphertext ;
service needs to decode all data before business calculation. Therefore, according to business needs, a interceptor pair is designed. However, in the recent business adjustment, consumers no longer submit all encrypted data , for example:
127.0.0.1Universe ServiceSecretdata1 = ciphertext & data2= ciphertext & data3= plaintext ;
therefore, the service needs to be treated separately for decoding. A slightly stupid way is to use exception handling in the previous interceptor and increase exception catch when decoding the content, so that exceptions (decoding failure) will not be decoded.
although the scheme is somewhat frustrated (there will be a decoding process regardless of whether the data is ciphertext or not), it works anyway. But I believe that there must be a better solution, so if you want to optimize it, the first thing that comes to mind at present is to use custom annotations (similar to @ valid), in method parameters or Bean object members, to add custom annotations to the input parameters or fields that need to be decoded, and then use AOP section to uniformly decode the annotation content (it feels good in theory, compared with the exception mechanism. It only needs to be decoded and will be decoded only if the data is actually used.

= gorgeous dividing line =

implementation:

2:


/**
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.METHOD })
public @interface Decryption{
}
    
/**
*javaBeanField
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD})
public @interface DecodeParam{
   //DES
   DecoderEnum decoder() default DecoderEnum.DES;
}

/**
* 
*/
@Aspect
@Component
public class DecryptionResolver {

    @Pointcut("execution(* * *(..)) && @annotation(com.annotation.Decryption)")
    public void desPoint() {
    }
    
    /*
    :
        * 
        * 
        * 
        * 
    */
}


the above code meets the business requirements, but needs to write 2 annotations, which makes it unfriendly, so I wonder if you can only use @ DecodeParam annotations. However, the result is that in @ Aspect , parameters or JavaBean Field annotations are not directly intercepted. I would like to ask you viewers if there is any way to make @ Aspect take effect directly on parameter annotations, or your ideas for dealing with similar business. Thank you very much ~

Mar.23,2021
Menu