Search in sources :

Example 1 with Message

use of com.sun.identity.liberty.ws.soapbinding.Message in project OpenAM by OpenRock.

the class SPACSUtils method getResponseFromPostECP.

/**
     * Obtains <code>SAML Response</code> from <code>SOAPBody</code>.
     * Used by ECP profile.
     */
private static ResponseInfo getResponseFromPostECP(HttpServletRequest request, HttpServletResponse response, String orgName, String hostEntityId, SAML2MetaManager metaManager) throws SAML2Exception, IOException {
    Message message = null;
    try {
        message = new Message(SOAPCommunicator.getInstance().getSOAPMessage(request));
    } catch (SOAPException soapex) {
        String[] data = { hostEntityId };
        LogUtil.error(Level.INFO, LogUtil.CANNOT_INSTANTIATE_SOAP_MESSAGE_ECP, data, null);
        SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "failedToCreateSOAPMessage", soapex.getMessage());
        throw new SAML2Exception(soapex.getMessage());
    } catch (SOAPBindingException soapex) {
        String[] data = { hostEntityId };
        LogUtil.error(Level.INFO, LogUtil.CANNOT_INSTANTIATE_SOAP_MESSAGE_ECP, data, null);
        SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "failedToCreateSOAPMessage", soapex.getMessage());
        throw new SAML2Exception(soapex.getMessage());
    } catch (SOAPFaultException sfex) {
        String[] data = { hostEntityId };
        LogUtil.error(Level.INFO, LogUtil.RECEIVE_SOAP_FAULT_ECP, data, null);
        String faultString = sfex.getSOAPFaultMessage().getSOAPFault().getFaultString();
        SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "failedToCreateSOAPMessage", faultString);
        throw new SAML2Exception(faultString);
    }
    List soapHeaders = message.getOtherSOAPHeaders();
    ECPRelayState ecpRelayState = null;
    if ((soapHeaders != null) && (!soapHeaders.isEmpty())) {
        for (Iterator iter = soapHeaders.iterator(); iter.hasNext(); ) {
            Element headerEle = (Element) iter.next();
            try {
                ecpRelayState = ECPFactory.getInstance().createECPRelayState(headerEle);
                break;
            } catch (SAML2Exception saml2ex) {
            // not ECP RelayState
            }
        }
    }
    String relayState = null;
    if (ecpRelayState != null) {
        relayState = ecpRelayState.getValue();
    }
    List soapBodies = message.getBodies();
    if ((soapBodies == null) || (soapBodies.isEmpty())) {
        String[] data = { hostEntityId };
        LogUtil.error(Level.INFO, LogUtil.CANNOT_INSTANTIATE_SAML_RESPONSE_FROM_ECP, data, null);
        SAMLUtils.sendError(request, response, response.SC_BAD_REQUEST, "missingSAMLResponse", SAML2Utils.bundle.getString("missingSAMLResponse"));
        throw new SAML2Exception(SAML2Utils.bundle.getString("missingSAMLResponse"));
    }
    Element resElem = (Element) soapBodies.get(0);
    Response resp = null;
    try {
        resp = ProtocolFactory.getInstance().createResponse(resElem);
    } catch (SAML2Exception se) {
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("SPACSUtils.getResponseFromPostECP:" + "Couldn't create Response:", se);
        }
        String[] data = { hostEntityId };
        LogUtil.error(Level.INFO, LogUtil.CANNOT_INSTANTIATE_SAML_RESPONSE_FROM_ECP, data, null);
        SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "failedToCreateResponse", se.getMessage());
        throw se;
    }
    String idpEntityID = resp.getIssuer().getValue();
    IDPSSODescriptorElement idpDesc = null;
    try {
        idpDesc = metaManager.getIDPSSODescriptor(orgName, idpEntityID);
    } catch (SAML2MetaException se) {
        String[] data = { orgName, idpEntityID };
        LogUtil.error(Level.INFO, LogUtil.IDP_META_NOT_FOUND, data, null);
        SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "failedToGetIDPSSODescriptor", se.getMessage());
        throw se;
    }
    Set<X509Certificate> certificates = KeyUtil.getVerificationCerts(idpDesc, idpEntityID, SAML2Constants.IDP_ROLE);
    List assertions = resp.getAssertion();
    if ((assertions != null) && (!assertions.isEmpty())) {
        for (Iterator iter = assertions.iterator(); iter.hasNext(); ) {
            Assertion assertion = (Assertion) iter.next();
            if (!assertion.isSigned()) {
                if (SAML2Utils.debug.messageEnabled()) {
                    SAML2Utils.debug.message("SPACSUtils.getResponseFromPostECP: " + " Assertion is not signed.");
                }
                String[] data = { idpEntityID };
                LogUtil.error(Level.INFO, LogUtil.ECP_ASSERTION_NOT_SIGNED, data, null);
                SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "assertionNotSigned", SAML2Utils.bundle.getString("assertionNotSigned"));
                throw new SAML2Exception(SAML2Utils.bundle.getString("assertionNotSigned"));
            } else if (!assertion.isSignatureValid(certificates)) {
                if (SAML2Utils.debug.messageEnabled()) {
                    SAML2Utils.debug.message("SPACSUtils.getResponseFromPostECP: " + " Assertion signature is invalid.");
                }
                String[] data = { idpEntityID };
                LogUtil.error(Level.INFO, LogUtil.ECP_ASSERTION_INVALID_SIGNATURE, data, null);
                SAMLUtils.sendError(request, response, response.SC_INTERNAL_SERVER_ERROR, "invalidSignature", SAML2Utils.bundle.getString("invalidSignature"));
                throw new SAML2Exception(SAML2Utils.bundle.getString("invalidSignature"));
            }
        }
    }
    return new ResponseInfo(resp, SAML2Constants.PAOS, relayState);
}
Also used : Message(com.sun.identity.liberty.ws.soapbinding.Message) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBindingException(com.sun.identity.liberty.ws.soapbinding.SOAPBindingException) SPSSOConfigElement(com.sun.identity.saml2.jaxb.entityconfig.SPSSOConfigElement) SPSSODescriptorElement(com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement) IDPSSOConfigElement(com.sun.identity.saml2.jaxb.entityconfig.IDPSSOConfigElement) ArtifactResolutionServiceElement(com.sun.identity.saml2.jaxb.metadata.ArtifactResolutionServiceElement) Element(org.w3c.dom.Element) IDPSSODescriptorElement(com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement) Assertion(com.sun.identity.saml2.assertion.Assertion) SOAPFaultException(com.sun.identity.liberty.ws.soapbinding.SOAPFaultException) X509Certificate(java.security.cert.X509Certificate) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) Response(com.sun.identity.saml2.protocol.Response) ArtifactResponse(com.sun.identity.saml2.protocol.ArtifactResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) SOAPException(javax.xml.soap.SOAPException) ECPRelayState(com.sun.identity.saml2.ecp.ECPRelayState) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) IDPSSODescriptorElement(com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement)

Example 2 with Message

use of com.sun.identity.liberty.ws.soapbinding.Message in project OpenAM by OpenRock.

the class AuthnSvcClient method sendRequest.

/**
     * Sends a <code>SASL</code> request to the Authentication Service SOAP
     * endpoint and returns a <code>SASL</code> response.
     *
     * @param saslReq a <code>SASL</code> request
     * @param connectTo the SOAP endpoint URL
     * @return a <code>SASL</code> response from the Authentication Service
     * @exception AuthnSvcException if authentication service is not available
     *            or there is an error in <code>SASL</code> request
     */
public static SASLResponse sendRequest(SASLRequest saslReq, String connectTo) throws AuthnSvcException {
    Message req = new Message();
    req.setSOAPBody(saslReq.toElement());
    req.getCorrelationHeader().setRefToMessageID(saslReq.getRefToMessageID());
    Message resp = null;
    try {
        resp = Client.sendRequest(req, connectTo);
    } catch (Exception ex) {
        AuthnSvcUtils.debug.error("AuthnSvcClient.sendRequest:", ex);
        throw new AuthnSvcException(ex);
    }
    List list = resp.getBodies(AuthnSvcConstants.NS_AUTHN_SVC, AuthnSvcConstants.TAG_SASL_RESPONSE);
    if (list.isEmpty()) {
        throw new AuthnSvcException("missingSASLResponse");
    } else if (list.size() > 1) {
        throw new AuthnSvcException("tooManySASLResponse");
    }
    SASLResponse saslResp = new SASLResponse((Element) list.get(0));
    saslResp.setMessageID(resp.getCorrelationHeader().getMessageID());
    saslResp.setRefToMessageID(resp.getCorrelationHeader().getRefToMessageID());
    return saslResp;
}
Also used : Message(com.sun.identity.liberty.ws.soapbinding.Message) SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) List(java.util.List)

Example 3 with Message

use of com.sun.identity.liberty.ws.soapbinding.Message in project OpenAM by OpenRock.

the class AuthnSvcRequestHandlerImpl method processRequest.

/**
     * Extracts SASL request out of a SOAP Message and processes it.
     * @param request a SOAP Message containing a SASL request
     * @return a SOAP Message containing a SASL response
     * @exception AuthnSvcException if an error occurs while processing the
     *                              SOAP Message
     */
public Message processRequest(Message request) throws AuthnSvcException {
    List list = request.getBodies(AuthnSvcConstants.NS_AUTHN_SVC, AuthnSvcConstants.TAG_SASL_REQUEST);
    if (list.isEmpty()) {
        throw new AuthnSvcException("missingSASLRequet");
    } else if (list.size() > 1) {
        throw new AuthnSvcException("tooManySASLRequet");
    }
    SASLRequest saslReq = new SASLRequest((Element) list.get(0));
    saslReq.setMessageID(request.getCorrelationHeader().getMessageID());
    saslReq.setRefToMessageID(request.getCorrelationHeader().getRefToMessageID());
    Message message = new Message();
    String respMessageID = message.getCorrelationHeader().getMessageID();
    SASLResponse saslResp = processSASLRequest(saslReq, request, respMessageID);
    message.setSOAPBody(saslResp.toElement());
    return message;
}
Also used : SASLRequest(com.sun.identity.liberty.ws.authnsvc.protocol.SASLRequest) Message(com.sun.identity.liberty.ws.soapbinding.Message) SASLResponse(com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse) List(java.util.List)

Example 4 with Message

use of com.sun.identity.liberty.ws.soapbinding.Message in project OpenAM by OpenRock.

the class DiscoveryClient method getResponse.

private Element getResponse(Message req) throws DiscoveryException {
    Message resp = null;
    try {
        resp = Client.sendRequest(req, connectTo, certAlias, soapAction);
    } catch (Exception e) {
        DiscoSDKUtils.debug.error("DiscoveryClient.getResponse:", e);
        throw new DiscoveryException(e.getMessage());
    }
    List bodies = resp.getBodies();
    if (!(bodies.size() == 1)) {
        DiscoSDKUtils.debug.error("DiscoveryClient.getResponse: SOAP Response " + "didn't contain one SOAPBody.");
        throw new DiscoveryException(DiscoSDKUtils.bundle.getString("oneBody"));
    }
    return ((Element) bodies.iterator().next());
}
Also used : Message(com.sun.identity.liberty.ws.soapbinding.Message) ArrayList(java.util.ArrayList) List(java.util.List) SOAPBindingException(com.sun.identity.liberty.ws.soapbinding.SOAPBindingException)

Example 5 with Message

use of com.sun.identity.liberty.ws.soapbinding.Message in project OpenAM by OpenRock.

the class InteractionManager method resendRequest.

/**
     * Resends a SOAP request message to <code>WSP</code>.
     * This would be invoked at <code>WSC</code> side.
     *
     * @param returnToURL URL to which to redirect user agent after
     *                    <code>WSP</code> - resource owner interactions
     * @param httpRequest HTTP request object of current user agent request
     * @param httpResponse HTTP response object of current user agent request
     * @param requestMessage SOAP message to be resent.
     * @return response SOAP message sent by <code>WSP</code>.
     *
     * @throws InteractionException for generic interaction error
     * @throws InteractionRedirectException if user agent is redirected to 
     *                     <code>WSP</code> for resource owner interactions
     * @throws SOAPBindingException  for generic SOAP errors
     * @throws SOAPFaultException if the response message has SOAP fault
     *
     * @supported.api
     */
public Message resendRequest(String returnToURL, HttpServletRequest httpRequest, HttpServletResponse httpResponse, Message requestMessage) throws InteractionRedirectException, InteractionException, SOAPBindingException, SOAPFaultException {
    if (debug.messageEnabled()) {
        debug.message("InteractionManager.resendRequest():entering ");
    }
    //check for RESEND_MESSAGE parameter
    String messageID = httpRequest.getParameter(RESEND_MESSAGE);
    if (messageID == null) {
        debug.error("InteractionManager.resend():" + " request without " + RESEND_MESSAGE + " in requestURL=" + httpRequest.getRequestURL().toString());
        String[] objs = { RESEND_MESSAGE };
        throw new InteractionException(INTERACTION_RB_NAME, "missing_query_parameter", objs);
    }
    //check whether WSP advised not to resend
    if ((messageID == "0") || (messageID.equals("false"))) {
        debug.error("InteractionManager.resend():" + " resend not allowed in requestURL=" + httpRequest.getRequestURL().toString());
        throw new InteractionException(INTERACTION_RB_NAME, "wsp_advised_not_to_resend", null);
    }
    //check for original REQUEST_ID
    messageID = httpRequest.getParameter(REQUEST_ID);
    if (messageID == null) {
        debug.error("InteractionManager.resend():" + " request without " + REQUEST_ID + " in requestURL=" + httpRequest.getRequestURL().toString());
        String[] objs = { REQUEST_ID };
        throw new InteractionException(INTERACTION_RB_NAME, "request_missing_query_parameter", objs);
    }
    String connectTo = getConnectTo(messageID);
    if (connectTo == null) {
        debug.error("InteractionManager.resend():" + " old connectTo not  found for messageID=" + messageID);
        throw new InteractionException(INTERACTION_RB_NAME, "old_connectTo_not_found", null);
    }
    if (requestMessage == null) {
        if (debug.messageEnabled()) {
            debug.message("InteractionManager.resendRequest():" + "invoking with null requestMessage:" + "old cached message would be used");
        }
        Message oldMessage = getRequestMessage(messageID);
        if (oldMessage == null) {
            debug.error("InteractionManager.resend():" + " old message not  found for messageID=" + messageID);
            throw new InteractionException(INTERACTION_RB_NAME, "old_message_not_found", null);
        }
        requestMessage = oldMessage;
    } else {
        if (debug.messageEnabled()) {
            debug.message("InteractionManager.resendRequest():" + "invoking with non null requestMessage");
        }
    }
    CorrelationHeader ch = new CorrelationHeader();
    ch.setRefToMessageID(InteractionManager.getInstance().getRequestMessageID(messageID));
    requestMessage.setCorrelationHeader(ch);
    if (debug.messageEnabled()) {
        debug.message("InteractionManager.resendRequest():" + "invoking InteractionManager.sendRequest():" + "with requestMessage=" + requestMessage + ":returnToURL=" + returnToURL);
    }
    if (LogUtil.isLogEnabled()) {
        String[] objs = new String[2];
        objs[0] = messageID;
        objs[1] = ch.getMessageID();
        LogUtil.access(Level.INFO, LogUtil.IS_RESENDING_MESSAGE, objs);
    }
    Message responseMessage = sendRequest(requestMessage, connectTo, getClientCert(messageID), getSoapAction(messageID), returnToURL, httpRequest, httpResponse);
    if (debug.messageEnabled()) {
        debug.message("InteractionManager.resendRequest():" + " returning responseMessage=" + responseMessage);
    }
    return responseMessage;
}
Also used : Message(com.sun.identity.liberty.ws.soapbinding.Message) CorrelationHeader(com.sun.identity.liberty.ws.soapbinding.CorrelationHeader)

Aggregations

Message (com.sun.identity.liberty.ws.soapbinding.Message)16 List (java.util.List)8 SOAPFaultException (com.sun.identity.liberty.ws.soapbinding.SOAPFaultException)7 ArrayList (java.util.ArrayList)6 SOAPBindingException (com.sun.identity.liberty.ws.soapbinding.SOAPBindingException)4 SOAPFault (com.sun.identity.liberty.ws.soapbinding.SOAPFault)3 SOAPFaultDetail (com.sun.identity.liberty.ws.soapbinding.SOAPFaultDetail)3 JAXBException (javax.xml.bind.JAXBException)3 SASLResponse (com.sun.identity.liberty.ws.authnsvc.protocol.SASLResponse)2 RedirectRequestElement (com.sun.identity.liberty.ws.interaction.jaxb.RedirectRequestElement)2 StatusElement (com.sun.identity.liberty.ws.interaction.jaxb.StatusElement)2 CorrelationHeader (com.sun.identity.liberty.ws.soapbinding.CorrelationHeader)2 ProviderHeader (com.sun.identity.liberty.ws.soapbinding.ProviderHeader)2 Element (org.w3c.dom.Element)2 SASLRequest (com.sun.identity.liberty.ws.authnsvc.protocol.SASLRequest)1 DSTException (com.sun.identity.liberty.ws.dst.DSTException)1 InteractionException (com.sun.identity.liberty.ws.interaction.InteractionException)1 InteractionManager (com.sun.identity.liberty.ws.interaction.InteractionManager)1 InteractionRedirectException (com.sun.identity.liberty.ws.interaction.InteractionRedirectException)1 InteractionSOAPFaultException (com.sun.identity.liberty.ws.interaction.InteractionSOAPFaultException)1