use of org.apache.cxf.rs.security.jose.jwe.JweJsonProducer in project cxf by apache.
the class JweJsonWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException {
if (ctx.getEntity() == null) {
ctx.proceed();
return;
}
OutputStream actualOs = ctx.getOutputStream();
JweHeaders sharedProtectedHeaders = new JweHeaders();
List<String> propLocs = getPropertyLocations();
List<JweHeaders> perRecipientUnprotectedHeaders = new ArrayList<JweHeaders>(propLocs.size());
for (int i = 0; i < propLocs.size(); i++) {
perRecipientUnprotectedHeaders.add(new JweHeaders());
}
List<JweEncryptionProvider> providers = getInitializedEncryptionProviders(propLocs, sharedProtectedHeaders, perRecipientUnprotectedHeaders);
String ctString = null;
MediaType contentMediaType = ctx.getMediaType();
if (contentTypeRequired && contentMediaType != null) {
if ("application".equals(contentMediaType.getType())) {
ctString = contentMediaType.getSubtype();
} else {
ctString = JAXRSUtils.mediaTypeToString(contentMediaType);
}
}
if (ctString != null) {
sharedProtectedHeaders.setContentType(ctString);
}
protectHttpHeadersIfNeeded(ctx, sharedProtectedHeaders);
if (useJweOutputStream) {
// TODO
} else {
CachedOutputStream cos = new CachedOutputStream();
ctx.setOutputStream(cos);
ctx.proceed();
JweJsonProducer producer = new JweJsonProducer(sharedProtectedHeaders, cos.getBytes());
String jweContent = producer.encryptWith(providers, perRecipientUnprotectedHeaders);
setJoseMediaType(ctx);
IOUtils.copy(new ByteArrayInputStream(StringUtils.toBytesUTF8(jweContent)), actualOs);
actualOs.flush();
}
}
Aggregations