use of org.apache.xml.security.stax.impl.OutboundSecurityContextImpl in project cxf by apache.
the class WSS4JStaxOutInterceptor method handleMessage.
public void handleMessage(SoapMessage mc) throws Fault {
OutputStream os = mc.getContent(OutputStream.class);
String encoding = getEncoding(mc);
XMLStreamWriter newXMLStreamWriter;
try {
WSSSecurityProperties secProps = createSecurityProperties();
translateProperties(mc, secProps);
configureCallbackHandler(mc, secProps);
final OutboundSecurityContext outboundSecurityContext = new OutboundSecurityContextImpl();
configureProperties(mc, outboundSecurityContext, secProps);
if (secProps.getActions() == null || secProps.getActions().isEmpty()) {
// If no actions configured then return
return;
}
handleSecureMTOM(mc, secProps);
if (secProps.getAttachmentCallbackHandler() == null) {
secProps.setAttachmentCallbackHandler(new AttachmentCallbackHandler(mc));
}
SecurityEventListener securityEventListener = configureSecurityEventListener(mc, secProps);
OutboundWSSec outboundWSSec = WSSec.getOutboundWSSec(secProps);
@SuppressWarnings("unchecked") final List<SecurityEvent> requestSecurityEvents = (List<SecurityEvent>) mc.getExchange().get(SecurityEvent.class.getName() + ".in");
outboundSecurityContext.putList(SecurityEvent.class, requestSecurityEvents);
outboundSecurityContext.addSecurityEventListener(securityEventListener);
newXMLStreamWriter = outboundWSSec.processOutMessage(os, encoding, outboundSecurityContext);
mc.setContent(XMLStreamWriter.class, newXMLStreamWriter);
} catch (WSSecurityException e) {
throw new Fault(e);
} catch (WSSPolicyException e) {
throw new Fault(e);
}
mc.put(AbstractOutDatabindingInterceptor.DISABLE_OUTPUTSTREAM_OPTIMIZATION, Boolean.TRUE);
try {
newXMLStreamWriter.writeStartDocument(encoding, "1.0");
} catch (XMLStreamException e) {
throw new Fault(e);
}
mc.removeContent(OutputStream.class);
mc.put(OUTPUT_STREAM_HOLDER, os);
// Add a final interceptor to write end elements
mc.getInterceptorChain().add(ending);
}
Aggregations