Search in sources :

Example 31 with SOAPException

use of javax.xml.soap.SOAPException in project wildfly by wildfly.

the class PojoEndpoint method helloError.

public String helloError(String input) {
    try {
        SOAPFault fault = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createFault(input, SOAPConstants.SOAP_VERSIONMISMATCH_FAULT);
        fault.setFaultActor("mr.actor");
        fault.addDetail().addChildElement("test");
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "NullPointerException"));
        fault.appendFaultSubcode(new QName("http://ws.gss.redhat.com/", "OperatorNotFound"));
        throw new SOAPFaultException(fault);
    } catch (SOAPException ex) {
        ex.printStackTrace();
    }
    return "Failure!";
}
Also used : QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 32 with SOAPException

use of javax.xml.soap.SOAPException in project ddf by codice.

the class AssertionConsumerService method processSoapResponse.

@POST
@Consumes({ "text/xml", "application/soap+xml" })
public Response processSoapResponse(InputStream body, @Context HttpServletRequest request) {
    try {
        SOAPPart soapMessage = SamlProtocol.parseSoapMessage(IOUtils.toString(body));
        String relayState = getRelayState(soapMessage);
        org.opensaml.saml.saml2.core.Response samlpResponse = getSamlpResponse(soapMessage);
        boolean validateResponse = validateResponse(samlpResponse);
        if (validateResponse) {
            return processSamlResponse(samlpResponse, relayState);
        }
    } catch (XMLStreamException e) {
        LOGGER.debug("Unable to parse SOAP message from response.", e);
    } catch (IOException e) {
        LOGGER.debug("Unable to get SAMLP response.", e);
    } catch (SOAPException e) {
        LOGGER.debug("Unable to get relay state from response.", e);
    }
    return Response.serverError().entity("Invalid AuthN response.").build();
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) IOException(java.io.IOException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 33 with SOAPException

use of javax.xml.soap.SOAPException in project ddf by codice.

the class IdpEndpoint method determineAuthMethod.

private AuthObj determineAuthMethod(String bodyStr, AuthnRequest authnRequest) {
    XMLStreamReader xmlStreamReader = null;
    try {
        xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(bodyStr));
    } catch (XMLStreamException e) {
        LOGGER.debug("Unable to parse SOAP message from client.", e);
    }
    SoapMessage soapMessage = new SoapMessage(Soap11.getInstance());
    SAAJInInterceptor.SAAJPreInInterceptor preInInterceptor = new SAAJInInterceptor.SAAJPreInInterceptor();
    soapMessage.setContent(XMLStreamReader.class, xmlStreamReader);
    preInInterceptor.handleMessage(soapMessage);
    SAAJInInterceptor inInterceptor = new SAAJInInterceptor();
    inInterceptor.handleMessage(soapMessage);
    SOAPPart soapMessageContent = (SOAPPart) soapMessage.getContent(Node.class);
    AuthObj authObj = new AuthObj();
    try {
        Iterator soapHeaderElements = soapMessageContent.getEnvelope().getHeader().examineAllHeaderElements();
        while (soapHeaderElements.hasNext()) {
            SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) soapHeaderElements.next();
            if (soapHeaderElement.getLocalName().equals("Security")) {
                Iterator childElements = soapHeaderElement.getChildElements();
                while (childElements.hasNext()) {
                    Object nextElement = childElements.next();
                    if (nextElement instanceof SOAPElement) {
                        SOAPElement element = (SOAPElement) nextElement;
                        if (element.getLocalName().equals("UsernameToken")) {
                            Iterator usernameTokenElements = element.getChildElements();
                            Object next;
                            while (usernameTokenElements.hasNext()) {
                                if ((next = usernameTokenElements.next()) instanceof Element) {
                                    Element nextEl = (Element) next;
                                    if (nextEl.getLocalName().equals("Username")) {
                                        authObj.username = nextEl.getTextContent();
                                    } else if (nextEl.getLocalName().equals("Password")) {
                                        authObj.password = nextEl.getTextContent();
                                    }
                                }
                            }
                            if (authObj.username != null && authObj.password != null) {
                                authObj.method = USER_PASS;
                                break;
                            }
                        } else if (element.getLocalName().equals("Assertion") && element.getNamespaceURI().equals("urn:oasis:names:tc:SAML:2.0:assertion")) {
                            authObj.assertion = new SecurityToken(element.getAttribute("ID"), element, null, null);
                            authObj.method = SAML;
                            break;
                        }
                    }
                }
            }
        }
    } catch (SOAPException e) {
        LOGGER.debug("Unable to parse SOAP message.", e);
    }
    RequestedAuthnContext requestedAuthnContext = authnRequest.getRequestedAuthnContext();
    boolean requestingPki = false;
    boolean requestingUp = false;
    if (requestedAuthnContext != null) {
        List<AuthnContextClassRef> authnContextClassRefs = requestedAuthnContext.getAuthnContextClassRefs();
        for (AuthnContextClassRef authnContextClassRef : authnContextClassRefs) {
            String authnContextClassRefStr = authnContextClassRef.getAuthnContextClassRef();
            if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SMARTCARD_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SOFTWARE_PKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_SPKI.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_TLS_CLIENT.equals(authnContextClassRefStr)) {
                requestingPki = true;
            } else if (SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD.equals(authnContextClassRefStr) || SAML2Constants.AUTH_CONTEXT_CLASS_REF_PASSWORD_PROTECTED_TRANSPORT.equals(authnContextClassRefStr)) {
                requestingUp = true;
            }
        }
    } else {
        //The requested auth context isn't required so we don't know what they want... just set both to true
        requestingPki = true;
        requestingUp = true;
    }
    if (requestingUp && authObj.method != null && authObj.method.equals(USER_PASS)) {
        LOGGER.trace("Found UsernameToken and correct AuthnContextClassRef");
        return authObj;
    } else if (requestingPki && authObj.method == null) {
        LOGGER.trace("Found no token, but client requested PKI AuthnContextClassRef");
        authObj.method = PKI;
        return authObj;
    } else if (authObj.method == null) {
        LOGGER.debug("No authentication tokens found for the current request and the client did not request PKI authentication");
    }
    return authObj;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) XMLStreamReader(javax.xml.stream.XMLStreamReader) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) Element(org.w3c.dom.Element) AuthnContextClassRef(org.opensaml.saml.saml2.core.AuthnContextClassRef) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) RequestedAuthnContext(org.opensaml.saml.saml2.core.RequestedAuthnContext) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPException(javax.xml.soap.SOAPException) StringReader(java.io.StringReader) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SignableSAMLObject(org.opensaml.saml.common.SignableSAMLObject) SignableXMLObject(org.opensaml.xmlsec.signature.SignableXMLObject) XMLObject(org.opensaml.core.xml.XMLObject)

Example 34 with SOAPException

use of javax.xml.soap.SOAPException in project ddf by codice.

the class SoapRequestDecoder method decodeRelayState.

public String decodeRelayState(String samlRequest) {
    String relayState = null;
    try {
        SOAPPart soapMessage = SamlProtocol.parseSoapMessage(samlRequest);
        SOAPEnvelope envelope = soapMessage.getEnvelope();
        SOAPHeader header = envelope.getHeader();
        Iterator iterator = header.examineAllHeaderElements();
        while (iterator.hasNext()) {
            SOAPHeaderElement soapHeaderElement = (SOAPHeaderElement) iterator.next();
            if ("RelayState".equals(soapHeaderElement.getLocalName())) {
                relayState = soapHeaderElement.getValue();
                break;
            }
        }
    } catch (XMLStreamException e) {
        throw new IllegalArgumentException("Unable to convert parse SOAP request.");
    } catch (SOAPException e) {
        throw new IllegalArgumentException("Unable to get SOAP envelope.");
    }
    return relayState;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPException(javax.xml.soap.SOAPException) SOAPPart(javax.xml.soap.SOAPPart) Iterator(java.util.Iterator) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 35 with SOAPException

use of javax.xml.soap.SOAPException in project ddf by codice.

the class GuestInterceptor method createAddressing.

private void createAddressing(SoapMessage message, SOAPMessage soapMessage) {
    SOAPFactory soapFactory;
    try {
        soapFactory = SOAPFactory.newInstance();
    } catch (SOAPException e) {
        LOGGER.debug("Could not create a SOAPFactory.", e);
        // can't add anything if we can't create it
        return;
    }
    String addressingProperty = org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
    AddressingProperties addressingProperties = new AddressingProperties();
    try {
        SOAPElement action = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        action.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        AttributedURIType attributedString = new AttributedURIType();
        String actionValue = StringUtils.defaultIfEmpty((String) message.get(SoapBindingConstants.SOAP_ACTION), "");
        attributedString.setValue(actionValue);
        addressingProperties.setAction(attributedString);
        soapMessage.getSOAPHeader().addChildElement(action);
    } catch (SOAPException e) {
        LOGGER.debug("Unable to add addressing action.", e);
    }
    try {
        SOAPElement messageId = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_MESSAGEID_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        String uuid = "urn:uuid:" + UUID.randomUUID().toString();
        messageId.addTextNode(uuid);
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue(uuid);
        addressingProperties.setMessageID(attributedString);
        soapMessage.getSOAPHeader().addChildElement(messageId);
    } catch (SOAPException e) {
        LOGGER.debug("Unable to add addressing messageId.", e);
    }
    try {
        SOAPElement to = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_TO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        to.addTextNode((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        EndpointReferenceType endpointReferenceType = new EndpointReferenceType();
        AttributedURIType attributedString = new AttributedURIType();
        attributedString.setValue((String) message.get(org.apache.cxf.message.Message.REQUEST_URL));
        endpointReferenceType.setAddress(attributedString);
        addressingProperties.setTo(endpointReferenceType);
        soapMessage.getSOAPHeader().addChildElement(to);
    } catch (SOAPException e) {
        LOGGER.debug("Unable to add addressing to.", e);
    }
    try {
        SOAPElement replyTo = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_REPLYTO_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        SOAPElement address = soapFactory.createElement(org.apache.cxf.ws.addressing.Names.WSA_ADDRESS_NAME, org.apache.cxf.ws.addressing.JAXWSAConstants.WSA_PREFIX, org.apache.cxf.ws.security.wss4j.DefaultCryptoCoverageChecker.WSA_NS);
        address.addTextNode(org.apache.cxf.ws.addressing.Names.WSA_ANONYMOUS_ADDRESS);
        replyTo.addChildElement(address);
        soapMessage.getSOAPHeader().addChildElement(replyTo);
    } catch (SOAPException e) {
        LOGGER.debug("Unable to add addressing replyTo.", e);
    }
    message.put(addressingProperty, addressingProperties);
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SOAPFactory(javax.xml.soap.SOAPFactory)

Aggregations

SOAPException (javax.xml.soap.SOAPException)120 SOAPMessage (javax.xml.soap.SOAPMessage)68 IOException (java.io.IOException)38 Element (org.w3c.dom.Element)36 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)24 QName (javax.xml.namespace.QName)22 SOAPBody (javax.xml.soap.SOAPBody)18 SOAPElement (javax.xml.soap.SOAPElement)17 Node (org.w3c.dom.Node)17 SOAPFault (javax.xml.soap.SOAPFault)14 Fault (org.apache.cxf.interceptor.Fault)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)13 SOAPPart (javax.xml.soap.SOAPPart)12 XMLStreamException (javax.xml.stream.XMLStreamException)12 OutputStream (java.io.OutputStream)11 Iterator (java.util.Iterator)11 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)11 ServletException (javax.servlet.ServletException)10 List (java.util.List)9 MessageFactory (javax.xml.soap.MessageFactory)9