My application receives an encrypted payload and I have to decrypt each value of the object. After, I have to encrypt the payload with the same format and send response.
What I need is an method to intercept the payload before it reach the controller to decrypt and intercept response to encrypt data.
I'm trying use a filter of javax.servlet but I don`t know how to get the body, change his value and set it back.
I already tried an interceptor but I had the same problem to change request body.
@Component
@Order(1)
public class CryptoFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
// code to decrypt request body goes here
filterChain.doFilter(request, response);
// code to encrypt response body goes here
}
}
The request body cames like this:
{
"key1": "098f6bcd4621d373cade4e832627b4f6",
"key2": "098f6bcd4621d373cade4e832627b4f6",
"key3": {
"key4": "098f6bcd4621d373cade4e832627b4f6"
}
}
And after filter I need this on controller:
{
"key1": "decrypted",
"key2": "decrypted",
"key3": {
"key4": "decrypted"
}
}