Search in sources :

Example 36 with SOAPException

use of javax.xml.soap.SOAPException in project tomee by apache.

the class Inflate method handleMessage.

public boolean handleMessage(SOAPMessageContext mc) {
    try {
        final SOAPMessage message = mc.getMessage();
        final SOAPBody body = message.getSOAPBody();
        final String localName = body.getFirstChild().getLocalName();
        if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
            final Node responseNode = body.getFirstChild();
            final Node returnNode = responseNode.getFirstChild();
            final Node intNode = returnNode.getFirstChild();
            final int value = new Integer(intNode.getNodeValue());
            intNode.setNodeValue(Integer.toString(value * 1000));
        }
        return true;
    } catch (SOAPException e) {
        return false;
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 37 with SOAPException

use of javax.xml.soap.SOAPException in project tomee by apache.

the class Increment method handleMessage.

public boolean handleMessage(SOAPMessageContext mc) {
    try {
        final SOAPMessage message = mc.getMessage();
        final SOAPBody body = message.getSOAPBody();
        final String localName = body.getFirstChild().getLocalName();
        if ("sumResponse".equals(localName) || "multiplyResponse".equals(localName)) {
            final Node responseNode = body.getFirstChild();
            final Node returnNode = responseNode.getFirstChild();
            final Node intNode = returnNode.getFirstChild();
            final int value = new Integer(intNode.getNodeValue());
            intNode.setNodeValue(Integer.toString(value + 1));
        }
        return true;
    } catch (SOAPException e) {
        return false;
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 38 with SOAPException

use of javax.xml.soap.SOAPException in project tomee by apache.

the class SaajMetaFactoryImpl method callFactoryMethod.

private Object callFactoryMethod(String methodName, String arg) throws SOAPException {
    SAAJMetaFactory factory = (SAAJMetaFactory) SaajFactoryFinder.find("javax.xml.soap.MetaFactory");
    try {
        Method method = factory.getClass().getDeclaredMethod(methodName, new Class[] { String.class });
        boolean accessibility = method.isAccessible();
        try {
            method.setAccessible(true);
            Object result = method.invoke(factory, new Object[] { arg });
            return result;
        } catch (InvocationTargetException e) {
            if (e.getTargetException() instanceof SOAPException) {
                throw (SOAPException) e.getTargetException();
            } else {
                throw new SOAPException("Error calling factory method: " + methodName, e);
            }
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new SOAPException("Error calling factory method: " + methodName, e);
        } finally {
            method.setAccessible(accessibility);
        }
    } catch (NoSuchMethodException e) {
        throw new SOAPException("Factory method not found: " + methodName, e);
    }
}
Also used : SAAJMetaFactory(javax.xml.soap.SAAJMetaFactory) SOAPException(javax.xml.soap.SOAPException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 39 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 40 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)

Aggregations

SOAPException (javax.xml.soap.SOAPException)78 SOAPMessage (javax.xml.soap.SOAPMessage)46 IOException (java.io.IOException)35 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)24 Element (org.w3c.dom.Element)23 Response (com.sun.identity.saml2.protocol.Response)10 OutputStream (java.io.OutputStream)10 ServletException (javax.servlet.ServletException)9 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)8 Iterator (java.util.Iterator)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 SOAPBody (javax.xml.soap.SOAPBody)8 SOAPElement (javax.xml.soap.SOAPElement)8 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)8 IDPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement)7 List (java.util.List)7 SOAPPart (javax.xml.soap.SOAPPart)7 Issuer (com.sun.identity.saml2.assertion.Issuer)6 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6