Search in sources :

Example 16 with W3CDOMStreamWriter

use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.

the class LogicalHandlerOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    if (binding.getHandlerChain().isEmpty()) {
        return;
    }
    HandlerChainInvoker invoker = getInvoker(message);
    if (invoker.getLogicalHandlers().isEmpty()) {
        return;
    }
    XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class);
    Node nd = message.getContent(Node.class);
    SOAPMessage m = message.getContent(SOAPMessage.class);
    final Document document;
    if (m != null) {
        document = m.getSOAPPart();
    } else if (nd != null) {
        document = nd.getOwnerDocument();
    } else {
        document = DOMUtils.newDocument();
        message.setContent(Node.class, document);
    }
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment());
    // Replace stax writer with DomStreamWriter
    message.setContent(XMLStreamWriter.class, writer);
    message.put(ORIGINAL_WRITER, origWriter);
    message.getInterceptorChain().add(ending);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 17 with W3CDOMStreamWriter

use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.

the class AegisElementDataWriter method write.

public void write(Object obj, QName elementName, boolean optional, Element output, AegisType aegisType) throws Exception {
    W3CDOMStreamWriter swriter = new W3CDOMStreamWriter(output);
    writer.write(obj, elementName, optional, swriter, aegisType);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter)

Example 18 with W3CDOMStreamWriter

use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.

the class AegisElementDataWriter method write.

public void write(Object obj, QName elementName, boolean optional, Element output, java.lang.reflect.Type objectType) throws Exception {
    W3CDOMStreamWriter swriter = new W3CDOMStreamWriter(output);
    writer.write(obj, elementName, optional, swriter, objectType);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter)

Example 19 with W3CDOMStreamWriter

use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.

the class AbstractSTSClient method issue.

/**
 * Make an "Issue" invocation and return the response as a STSResponse Object
 */
protected STSResponse issue(String appliesTo, String action, String requestType, String binaryExchange) throws Exception {
    createClient();
    BindingOperationInfo boi = findOperation("/RST/Issue");
    client.getRequestContext().putAll(ctx);
    if (action != null) {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, action);
    } else if (isSecureConv) {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/SCT");
    } else {
        client.getRequestContext().put(SoapBindingConstants.SOAP_ACTION, namespace + "/RST/Issue");
    }
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartElement("wst", "RequestSecurityToken", namespace);
    writer.writeNamespace("wst", namespace);
    if (context != null) {
        writer.writeAttribute(null, "Context", context);
    }
    boolean wroteKeySize = false;
    String keyTypeTemplate = null;
    String sptt = null;
    if (template != null && DOMUtils.getFirstElement(template) != null) {
        if (this.useSecondaryParameters()) {
            writer.writeStartElement("wst", "SecondaryParameters", namespace);
        }
        Element tl = DOMUtils.getFirstElement(template);
        while (tl != null) {
            StaxUtils.copy(tl, writer);
            if ("KeyType".equals(tl.getLocalName())) {
                keyTypeTemplate = DOMUtils.getContent(tl);
            } else if ("KeySize".equals(tl.getLocalName())) {
                wroteKeySize = true;
                keySize = Integer.parseInt(DOMUtils.getContent(tl));
            } else if ("TokenType".equals(tl.getLocalName())) {
                sptt = DOMUtils.getContent(tl);
            }
            tl = DOMUtils.getNextElement(tl);
        }
        if (this.useSecondaryParameters()) {
            writer.writeEndElement();
        }
    }
    if (isSpnego) {
        tokenType = STSUtils.getTokenTypeSCT(namespace);
        sendKeyType = false;
    }
    if (sptt == null) {
        addTokenType(writer);
    }
    addRequestType(requestType, writer);
    if (enableAppliesTo) {
        addAppliesTo(writer, appliesTo);
    }
    addClaims(writer);
    if (isSecureConv || enableLifetime) {
        addLifetime(writer);
    }
    // Write out renewal semantics
    writeRenewalSemantics(writer);
    Element onBehalfOfToken = getOnBehalfOfToken();
    if (onBehalfOfToken != null) {
        writer.writeStartElement("wst", "OnBehalfOf", namespace);
        StaxUtils.copy(onBehalfOfToken, writer);
        writer.writeEndElement();
    }
    if (keyTypeTemplate == null) {
        keyTypeTemplate = writeKeyType(writer, keyType);
    }
    byte[] requestorEntropy = null;
    X509Certificate cert = null;
    Crypto crypto = null;
    if (keySize <= 0) {
        keySize = 256;
    }
    if (keyTypeTemplate != null && keyTypeTemplate.endsWith("SymmetricKey")) {
        requestorEntropy = writeElementsForRSTSymmetricKey(writer, wroteKeySize);
    } else if (keyTypeTemplate != null && keyTypeTemplate.endsWith("PublicKey")) {
        // Use the given cert, or else get it from a Crypto instance
        if (useKeyCertificate != null) {
            cert = useKeyCertificate;
        } else {
            crypto = createCrypto(false);
            cert = getCert(crypto);
        }
        writeElementsForRSTPublicKey(writer, cert);
    } else if (isSpnego || isSecureConv) {
        addKeySize(keySize, writer);
    }
    if (binaryExchange != null) {
        addBinaryExchange(binaryExchange, writer);
    }
    Element actAsSecurityToken = getActAsToken();
    if (actAsSecurityToken != null) {
        writer.writeStartElement(STSUtils.WST_NS_08_02, "ActAs");
        StaxUtils.copy(actAsSecurityToken, writer);
        writer.writeEndElement();
    }
    Element customElement = getCustomContent();
    if (customElement != null) {
        StaxUtils.copy(customElement, writer);
    }
    writer.writeEndElement();
    Object[] obj = client.invoke(boi, new DOMSource(writer.getDocument().getDocumentElement()));
    @SuppressWarnings("unchecked") Collection<Attachment> attachments = (Collection<Attachment>) client.getResponseContext().get(Message.ATTACHMENTS);
    return new STSResponse((DOMSource) obj[0], requestorEntropy, cert, crypto, attachments);
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) Attachment(org.apache.cxf.message.Attachment) X509Certificate(java.security.cert.X509Certificate) Crypto(org.apache.wss4j.common.crypto.Crypto) Collection(java.util.Collection) ClaimCollection(org.apache.cxf.rt.security.claims.ClaimCollection)

Example 20 with W3CDOMStreamWriter

use of org.apache.cxf.staxutils.W3CDOMStreamWriter in project cxf by apache.

the class MetadataWriter method getMetaData.

public Document getMetaData(String serviceURL, String assertionConsumerServiceURL, String logoutURL, Key signingKey, X509Certificate signingCert, boolean wantRequestsSigned) throws Exception {
    W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
    writer.writeStartDocument(StandardCharsets.UTF_8.name(), "1.0");
    String referenceID = IDGenerator.generateID("_");
    writer.writeStartElement("md", "EntityDescriptor", SSOConstants.SAML2_METADATA_NS);
    writer.writeAttribute("ID", referenceID);
    writer.writeAttribute("entityID", serviceURL);
    writer.writeNamespace("md", SSOConstants.SAML2_METADATA_NS);
    writer.writeNamespace("wsa", SSOConstants.WS_ADDRESSING_NS);
    writer.writeNamespace("xsi", SSOConstants.SCHEMA_INSTANCE_NS);
    writeSAMLMetadata(writer, assertionConsumerServiceURL, logoutURL, signingCert, wantRequestsSigned);
    // EntityDescriptor
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
    if (LOG.isDebugEnabled()) {
        String out = DOM2Writer.nodeToString(writer.getDocument());
        LOG.debug("***************** unsigned ****************");
        LOG.debug(out);
        LOG.debug("***************** unsigned ****************");
    }
    Document doc = writer.getDocument();
    if (signingKey != null) {
        return signMetaInfo(signingCert, signingKey, doc, referenceID);
    }
    return doc;
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) Document(org.w3c.dom.Document)

Aggregations

W3CDOMStreamWriter (org.apache.cxf.staxutils.W3CDOMStreamWriter)60 Element (org.w3c.dom.Element)29 DOMSource (javax.xml.transform.dom.DOMSource)24 XMLStreamException (javax.xml.stream.XMLStreamException)15 Document (org.w3c.dom.Document)14 WebClient (org.apache.cxf.jaxrs.client.WebClient)9 Node (org.w3c.dom.Node)9 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)8 Fault (org.apache.cxf.interceptor.Fault)8 XMLStreamReader (javax.xml.stream.XMLStreamReader)7 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)7 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)7 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)7 JAXBElement (javax.xml.bind.JAXBElement)6 JAXBException (javax.xml.bind.JAXBException)5 SOAPMessage (javax.xml.soap.SOAPMessage)5 SoapFault (org.apache.cxf.binding.soap.SoapFault)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4