Search in sources :

Example 1 with NamespaceContextImpl

use of org.apache.ws.commons.util.NamespaceContextImpl in project verify-hub by alphagov.

the class MatchingServiceHealthCheckIntegrationTests method namespaceContextForSaml.

private NamespaceContext namespaceContextForSaml() {
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml2", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    return context;
}
Also used : NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl)

Example 2 with NamespaceContextImpl

use of org.apache.ws.commons.util.NamespaceContextImpl in project verify-hub by alphagov.

the class SoapMessageManager method unwrapSoapMessage.

public Element unwrapSoapMessage(Element soapElement) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    xpath.setNamespaceContext(context);
    try {
        final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
        Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);
        if (element == null) {
            String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE, writeToString(soapElement), expression);
            LOG.error(errorMessage);
            throw new IllegalArgumentException(errorMessage);
        }
        return element;
    } catch (XPathExpressionException e) {
        throw propagate(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl) Element(org.w3c.dom.Element) XmlUtils.writeToString(uk.gov.ida.shared.utils.xml.XmlUtils.writeToString)

Example 3 with NamespaceContextImpl

use of org.apache.ws.commons.util.NamespaceContextImpl in project verify-hub by alphagov.

the class SoapMessageManagerTest method getAttributeQuery.

private Element getAttributeQuery(Document document) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    xpath.setNamespaceContext(context);
    return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
Also used : XPath(javax.xml.xpath.XPath) NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl) Element(org.w3c.dom.Element)

Aggregations

NamespaceContextImpl (org.apache.ws.commons.util.NamespaceContextImpl)3 XPath (javax.xml.xpath.XPath)2 Element (org.w3c.dom.Element)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 XmlUtils.writeToString (uk.gov.ida.shared.utils.xml.XmlUtils.writeToString)1