Jackson: Encryption post serialisation #33001
-
I am trying to figure out the appropriate place to encrypt the payload that is sent to my remote (legacy API).
Decryption with ClientResponseFilter works fine, I suppose because the filter runs before Jackson. Any suggestions on what can be done? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Beta Was this translation helpful? Give feedback.
-
The interceptor below results in an EmptyBody being sent. The code snippet below follows DigitalSigningInterceptor.java @Priority(Priorities.ENTITY_CODER)
@ConstrainedTo(jakarta.ws.rs.RuntimeType.CLIENT)
public class Interceptor implements WriterInterceptor {
@Override
public void aroundWriteTo(WriterInterceptorContext context)
throws IOException, WebApplicationException {
// following https://github.com/resteasy/resteasy/blob/main/security/resteasy-crypto/src/main/java/org/jboss/resteasy/security/doseta/DigitalSigningInterceptor.java#L174
OutputStream old = context.getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
context.setOutputStream(baos);
context.proceed();
byte[] body = baos.toByteArray();
// compute signature - or encrypt
// should be able to write a modified body?
old.write(body);
context.setOutputStream(old);
}
} |
Beta Was this translation helpful? Give feedback.
-
How about creating a custom MessageBodyWriter ? In the MessageBodyWriter you could deserialize and encrypt your entity. |
Beta Was this translation helpful? Give feedback.
Can you try a MessageBodyWriter?