0

I have a spring boot application and am a beginner with custom annotation. I want to introduce a custom annotation simillar to couchbase java sdk's @EncryptedField. If I apply that annotation to a field in the model class, then that field has to be ecrypted when storing to db and decrypted when retriving back. I am not clear which approach to take ? Should I using Spring AOP for this ? Any inputs to implement this will be really helpful

vijayashankard
  • 721
  • 1
  • 7
  • 23

1 Answers1

0

It depends on what persistence framework you're using.

For Mybatis, you can add an incterceptor

like this

<plugins>       
    <plugin interceptor="com.XXX.XXXX.service.encryptinfo.MyInterceptor" />
</plugins>

Then implement it

    @Intercepts({
    @Signature(type=Executor.class,method="update",args={MappedStatement.class,Object.class}),
    @Signature(type=Executor.class,method="query",args={MappedStatement.class,Object.class,RowBounds.class,ResultHandler.class})
})
public class MyInterceptor implements Interceptor{

    // your logic here
    // write something that use reflection capture your custom annotaion of the entity and field
}
AwesomeHunter
  • 690
  • 6
  • 10