use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.
the class JweJsonClientResponseFilter method filter.
@Override
public void filter(ClientRequestContext req, ClientResponseContext res) throws IOException {
if (isMethodWithNoContent(req.getMethod()) || isCheckEmptyStream() && !res.hasEntity()) {
return;
}
JweDecryptionOutput out = decrypt(res.getEntityStream());
byte[] bytes = out.getContent();
res.setEntityStream(new ByteArrayInputStream(bytes));
res.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
if (ct != null) {
res.getHeaders().putSingle("Content-Type", ct);
}
if (super.isValidateHttpHeaders()) {
super.validateHttpHeadersIfNeeded(res.getHeaders(), out.getHeaders());
}
}
use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.
the class BookStore method getRecipientText.
private String getRecipientText(JweJsonConsumer consumer, String recipientPropLoc, String recipientKid) {
Message message = JAXRSUtils.getCurrentMessage();
Properties recipientProps = JweUtils.loadJweProperties(message, recipientPropLoc);
JsonWebKey recipientKey = JwkUtils.loadJwkSet(message, recipientProps, null).getKey(recipientKid);
ContentAlgorithm contentEncryptionAlgorithm = JweUtils.getContentEncryptionAlgorithm(recipientProps);
JweDecryptionProvider jweRecipient = JweUtils.createJweDecryptionProvider(recipientKey, contentEncryptionAlgorithm);
JweDecryptionOutput jweRecipientOutput = consumer.decryptWith(jweRecipient, Collections.singletonMap("kid", recipientKid));
return jweRecipientOutput.getContentText();
}
use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.
the class AbstractJweJsonDecryptingFilter method decrypt.
protected JweDecryptionOutput decrypt(InputStream is) throws IOException {
JweJsonConsumer c = new JweJsonConsumer(new String(IOUtils.readBytesFromStream(is), StandardCharsets.UTF_8));
JweDecryptionProvider theProvider = getInitializedDecryptionProvider(c.getProtectedHeader());
JweJsonEncryptionEntry entry = c.getJweDecryptionEntry(theProvider, recipientProperties);
if (entry == null) {
throw new JweException(JweException.Error.INVALID_JSON_JWE);
}
JweDecryptionOutput out = c.decryptWith(theProvider, entry);
JAXRSUtils.getCurrentMessage().put(JweJsonConsumer.class, c);
JAXRSUtils.getCurrentMessage().put(JweJsonEncryptionEntry.class, entry);
return out;
}
use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.
the class JweClientResponseFilter method filter.
@Override
public void filter(ClientRequestContext req, ClientResponseContext res) throws IOException {
if (isMethodWithNoContent(req.getMethod()) || isCheckEmptyStream() && !res.hasEntity()) {
return;
}
JweDecryptionOutput out = decrypt(res.getEntityStream());
byte[] bytes = out.getContent();
res.setEntityStream(new ByteArrayInputStream(bytes));
res.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
if (ct != null) {
res.getHeaders().putSingle("Content-Type", ct);
}
if (super.isValidateHttpHeaders()) {
super.validateHttpHeadersIfNeeded(res.getHeaders(), out.getHeaders());
}
}
use of org.apache.cxf.rs.security.jose.jwe.JweDecryptionOutput in project cxf by apache.
the class JweJsonContainerRequestFilter method filter.
@Override
public void filter(ContainerRequestContext context) throws IOException {
if (isMethodWithNoContent(context.getMethod()) || isCheckEmptyStream() && !context.hasEntity()) {
return;
}
try {
JweDecryptionOutput out = decrypt(context.getEntityStream());
byte[] bytes = out.getContent();
context.setEntityStream(new ByteArrayInputStream(bytes));
context.getHeaders().putSingle("Content-Length", Integer.toString(bytes.length));
String ct = JoseUtils.checkContentType(out.getHeaders().getContentType(), getDefaultMediaType());
if (ct != null) {
context.getHeaders().putSingle("Content-Type", ct);
}
if (super.isValidateHttpHeaders()) {
super.validateHttpHeadersIfNeeded(context.getHeaders(), out.getHeaders());
}
} catch (JweException ex) {
context.abortWith(JAXRSUtils.toResponse(400));
return;
}
}
Aggregations