Search in sources :

Example 26 with SOAPException

use of javax.xml.soap.SOAPException in project OpenAM by OpenRock.

the class IDPSingleSignOnServiceSOAP method sendError.

private void sendError(HttpServletResponse response, String faultCode, String rbKey, String detail) throws IOException {
    try {
        SOAPMessage soapFault = SOAPCommunicator.getInstance().createSOAPFault(faultCode, rbKey, detail);
        if (soapFault != null) {
            // are generated as part of the save.
            if (soapFault.saveRequired()) {
                soapFault.saveChanges();
            }
            response.setStatus(HttpServletResponse.SC_OK);
            SAML2Utils.putHeaders(soapFault.getMimeHeaders(), response);
            // Write out the message on the response stream
            try (OutputStream os = response.getOutputStream()) {
                soapFault.writeTo(os);
                os.flush();
            }
        } else {
            response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        }
    } catch (SOAPException ex) {
        SAML2Utils.debug.error("IDPSingleSignOnServiceSOAP.sendError:", ex);
    }
}
Also used : OutputStream(java.io.OutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 27 with SOAPException

use of javax.xml.soap.SOAPException in project OpenAM by OpenRock.

the class AssertionIDRequestServiceSOAP method doGetPost.

private void doGetPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // handle DOS attack
    SAMLUtils.checkHTTPContentLength(req);
    String pathInfo = req.getPathInfo();
    if (pathInfo == null) {
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AssertionIDRequestServiceSOAP.doGetPost: " + "pathInfo is null.");
        }
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "nullPathInfo", SAML2Utils.bundle.getString("nullPathInfo"));
        return;
    }
    String role = null;
    int index = pathInfo.indexOf(SAML2MetaManager.NAME_META_ALIAS_IN_URI);
    if (index > 2) {
        role = pathInfo.substring(1, index - 1);
    }
    String samlAuthorityMetaAlias = SAML2MetaUtils.getMetaAliasByUri(req.getRequestURI());
    String samlAuthorityEntityID = null;
    String realm = null;
    try {
        samlAuthorityEntityID = SAML2Utils.getSAML2MetaManager().getEntityByMetaAlias(samlAuthorityMetaAlias);
        realm = SAML2MetaUtils.getRealmByMetaAlias(samlAuthorityMetaAlias);
    } catch (SAML2Exception sme) {
        SAML2Utils.debug.error("AssertionIDRequestServiceSOAP.doGetPost", sme);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "invalidMetaAlias", sme.getMessage());
        return;
    }
    if (!SAML2Utils.isIDPProfileBindingSupported(realm, samlAuthorityEntityID, SAML2Constants.ASSERTION_ID_REQUEST_SERVICE, SAML2Constants.SOAP)) {
        SAML2Utils.debug.error("AssertionIDRequestServiceSOAP.doGetPost:Assertion ID request" + " service SOAP binding is not supported for " + samlAuthorityEntityID);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_BAD_REQUEST, "unsupportedBinding", SAML2Utils.bundle.getString("unsupportedBinding"));
        return;
    }
    AssertionIDRequest assertionIDRequest = null;
    try {
        SOAPMessage msg = SOAPCommunicator.getInstance().getSOAPMessage(req);
        Element elem = SOAPCommunicator.getInstance().getSamlpElement(msg, SAML2Constants.ASSERTION_ID_REQUEST);
        assertionIDRequest = ProtocolFactory.getInstance().createAssertionIDRequest(elem);
    } catch (Exception ex) {
        SAML2Utils.debug.error("AssertionIDRequestServiceSOAP.doGetPost:", ex);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failedToCreateAssertionIDRequest", ex.getMessage());
        return;
    }
    SOAPMessage replymsg = null;
    try {
        Response samlResp = AssertionIDRequestUtil.processAssertionIDRequest(assertionIDRequest, req, resp, samlAuthorityEntityID, role, realm);
        replymsg = SOAPCommunicator.getInstance().createSOAPMessage(samlResp.toXMLString(true, true), false);
    } catch (Throwable t) {
        SAML2Utils.debug.error("AssertionIDRequestServiceSOAP.doGetPost: " + "Unable to create SOAP message:", t);
        replymsg = SOAPCommunicator.getInstance().createSOAPFault(SAML2Constants.SERVER_FAULT, "unableToCreateSOAPMessage", null);
    }
    try {
        if (replymsg.saveRequired()) {
            replymsg.saveChanges();
        }
        resp.setStatus(HttpServletResponse.SC_OK);
        SAML2Utils.putHeaders(replymsg.getMimeHeaders(), resp);
        OutputStream os = resp.getOutputStream();
        replymsg.writeTo(os);
        os.flush();
    } catch (SOAPException soap) {
        SAML2Utils.debug.error("AssertionIDRequestServiceSOAP.doGetPost", soap);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "soapError", soap.getMessage());
        return;
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.sun.identity.saml2.protocol.Response) AssertionIDRequest(com.sun.identity.saml2.protocol.AssertionIDRequest) Element(org.w3c.dom.Element) OutputStream(java.io.OutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage) ServletException(javax.servlet.ServletException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception)

Example 28 with SOAPException

use of javax.xml.soap.SOAPException in project OpenAM by OpenRock.

the class AttributeServiceSOAP method doGetPost.

private void doGetPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // handle DOS attack
    SAMLUtils.checkHTTPContentLength(req);
    AttributeQuery attrQuery = null;
    try {
        SOAPMessage msg = SOAPCommunicator.getInstance().getSOAPMessage(req);
        Element elem = SOAPCommunicator.getInstance().getSamlpElement(msg, SAML2Constants.ATTRIBUTE_QUERY);
        attrQuery = ProtocolFactory.getInstance().createAttributeQuery(elem);
    } catch (Exception ex) {
        SAML2Utils.debug.error("AttributeServiceSOAP.doGetPost:", ex);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failedToCreateAttributeQuery", ex.getMessage());
        return;
    }
    String pathInfo = req.getPathInfo();
    if (pathInfo == null) {
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AttributeServiceSOAP.doGetPost: " + "pathInfo is null.");
        }
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "nullPathInfo", SAML2Utils.bundle.getString("nullPathInfo"));
        return;
    }
    String attrQueryProfileAlias = null;
    int index = pathInfo.indexOf(SAML2MetaManager.NAME_META_ALIAS_IN_URI);
    if (index > 2) {
        attrQueryProfileAlias = pathInfo.substring(1, index - 1);
    }
    String attrAuthorityMetaAlias = SAML2MetaUtils.getMetaAliasByUri(req.getRequestURI());
    String attrAuthorityEntityID = null;
    String realm = null;
    try {
        attrAuthorityEntityID = SAML2Utils.getSAML2MetaManager().getEntityByMetaAlias(attrAuthorityMetaAlias);
        realm = SAML2MetaUtils.getRealmByMetaAlias(attrAuthorityMetaAlias);
    } catch (SAML2Exception sme) {
        SAML2Utils.debug.error("AttributeServiceSOAP.doGetPost", sme);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "invalidMetaAlias", sme.getMessage());
        return;
    }
    SOAPMessage replymsg = null;
    try {
        Response samlResp = AttributeQueryUtil.processAttributeQuery(attrQuery, req, resp, attrAuthorityEntityID, realm, attrQueryProfileAlias);
        replymsg = SOAPCommunicator.getInstance().createSOAPMessage(samlResp.toXMLString(true, true), false);
    } catch (Throwable t) {
        SAML2Utils.debug.error("AttributeServiceSOAP.doGetPost: " + "Unable to create SOAP message:", t);
        replymsg = SOAPCommunicator.getInstance().createSOAPFault(SAML2Constants.SERVER_FAULT, "unableToCreateSOAPMessage", null);
    }
    try {
        if (replymsg.saveRequired()) {
            replymsg.saveChanges();
        }
        resp.setStatus(HttpServletResponse.SC_OK);
        SAML2Utils.putHeaders(replymsg.getMimeHeaders(), resp);
        OutputStream os = resp.getOutputStream();
        replymsg.writeTo(os);
        os.flush();
    } catch (SOAPException soap) {
        SAML2Utils.debug.error("AttributeServiceSOAP.doGetPost", soap);
        SAMLUtils.sendError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "soapError", soap.getMessage());
        return;
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(com.sun.identity.saml2.protocol.Response) AttributeQuery(com.sun.identity.saml2.protocol.AttributeQuery) Element(org.w3c.dom.Element) OutputStream(java.io.OutputStream) SOAPException(javax.xml.soap.SOAPException) SOAPMessage(javax.xml.soap.SOAPMessage) ServletException(javax.servlet.ServletException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception)

Example 29 with SOAPException

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

the class ReliableCheckHandler method handleContext.

private synchronized void handleContext(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    SOAPMessage message = smc.getMessage();
    if (outboundProperty.booleanValue()) {
        log.debug("Outgoing message:");
    } else {
        log.debug("Incoming message:");
    }
    log.debug("-----------");
    try {
        JBossLoggingOutputStream os = new JBossLoggingOutputStream(log, Level.DEBUG);
        message.writeTo(os);
        os.flush();
        log.debug("");
    } catch (Exception e) {
        log.debug("Exception in handler: " + e);
    }
    log.debug("-----------");
    SOAPElement firstBodyElement;
    try {
        switch(status % 4) {
            case 0:
                @SuppressWarnings("unchecked") Iterator<SOAPElement> it = (Iterator<SOAPElement>) message.getSOAPBody().getChildElements();
                if (it.hasNext()) {
                    firstBodyElement = it.next();
                    final QName createSequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequence");
                    if (!createSequenceQName.equals(firstBodyElement.getElementQName())) {
                        throw new WebServiceException("CreateSequence in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
                    }
                    status++;
                } else {
                    //we could get multiple acknowledments
                    verifySequenceAcknowledgement(message);
                }
                break;
            case 1:
                firstBodyElement = (SOAPElement) message.getSOAPBody().getChildElements().next();
                final QName createSequenceResponseQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequenceResponse");
                if (!createSequenceResponseQName.equals(firstBodyElement.getElementQName())) {
                    throw new WebServiceException("CreateSequenceResponse in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
                }
                status++;
                break;
            case 2:
                Iterator headerElements = message.getSOAPHeader().getChildElements();
                boolean found = false;
                final QName sequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "Sequence");
                while (headerElements.hasNext()) {
                    SOAPElement soapElement = (SOAPElement) headerElements.next();
                    if (sequenceQName.equals(soapElement.getElementQName())) {
                        found = true;
                    }
                }
                if (!found) {
                    throw new WebServiceException("wsrm:Sequence is not present in soap header");
                }
                status++;
                break;
            case 3:
                if (verifySequenceAcknowledgement(message)) {
                    status++;
                }
                break;
        }
    } catch (SOAPException ex) {
        throw new WebServiceException(ex.getMessage(), ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Example 30 with SOAPException

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

the class TestHandler method ensureInjectionsAndInitialization.

private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
    if (!this.correctState) {
        throw new WebServiceException("Unfunctional injections");
    }
    try {
        SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
        SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
        soapElement = (SOAPElement) soapElement.getChildElements().next();
        String oldValue = soapElement.getValue();
        String newValue = oldValue + ":" + direction + ":TestHandler";
        soapElement.setValue(newValue);
        log.debug("oldValue: " + oldValue);
        log.debug("newValue: " + newValue);
        return true;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage)

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