Search in sources :

Example 1 with OutboundSecurityContextImpl

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);
}
Also used : WSSSecurityProperties(org.apache.wss4j.stax.ext.WSSSecurityProperties) TokenSecurityEvent(org.apache.xml.security.stax.securityEvent.TokenSecurityEvent) SecurityEvent(org.apache.xml.security.stax.securityEvent.SecurityEvent) OutputStream(java.io.OutputStream) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Fault(org.apache.cxf.interceptor.Fault) OutboundSecurityContextImpl(org.apache.xml.security.stax.impl.OutboundSecurityContextImpl) OutboundSecurityContext(org.apache.xml.security.stax.ext.OutboundSecurityContext) OutboundWSSec(org.apache.wss4j.stax.setup.OutboundWSSec) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) LinkedList(java.util.LinkedList) List(java.util.List) WSSPolicyException(org.apache.wss4j.common.WSSPolicyException) SecurityEventListener(org.apache.xml.security.stax.securityEvent.SecurityEventListener)

Aggregations

OutputStream (java.io.OutputStream)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Fault (org.apache.cxf.interceptor.Fault)1 WSSPolicyException (org.apache.wss4j.common.WSSPolicyException)1 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)1 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)1 OutboundWSSec (org.apache.wss4j.stax.setup.OutboundWSSec)1 OutboundSecurityContext (org.apache.xml.security.stax.ext.OutboundSecurityContext)1 OutboundSecurityContextImpl (org.apache.xml.security.stax.impl.OutboundSecurityContextImpl)1 SecurityEvent (org.apache.xml.security.stax.securityEvent.SecurityEvent)1 SecurityEventListener (org.apache.xml.security.stax.securityEvent.SecurityEventListener)1 TokenSecurityEvent (org.apache.xml.security.stax.securityEvent.TokenSecurityEvent)1