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
Asked
Active
Viewed 593 times
0
-
1How do you access the db? Hibernate? Jdbc? – Stav Shamir Apr 29 '20 at 16:26
-
I am using spring-data-couchbase – vijayashankard Apr 30 '20 at 05:27
1 Answers
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