Search in sources :

Example 1 with ECPResponse

use of com.sun.identity.saml2.ecp.ECPResponse in project OpenAM by OpenRock.

the class IDPSSOUtil method sendResponseECP.

/**
     * This method sends SAML Response back to ECP.
     *
     * @param request The servlet request.
     * @param response The servlet response.
     * @param out The print writer for writing out presentation.
     * @param idpEntityID the entity id of the identity provider
     * @param realm       the realm name of the identity provider
     * @param acsURL      the assertion consumer service <code>URL</code>
     * @param res         the <code>SAML Response</code> object
     * @throws SAML2Exception if the operation is not successful
     */
public static void sendResponseECP(HttpServletRequest request, HttpServletResponse response, PrintWriter out, String idpEntityID, String realm, String acsURL, Response res) throws SAML2Exception {
    ECPFactory ecpFactory = ECPFactory.getInstance();
    ECPResponse ecpResponse = ecpFactory.createECPResponse();
    ecpResponse.setMustUnderstand(Boolean.TRUE);
    ecpResponse.setActor(SAML2Constants.SOAP_ACTOR_NEXT);
    ecpResponse.setAssertionConsumerServiceURL(acsURL);
    String header = ecpResponse.toXMLString(true, true);
    String body = res.toXMLString(true, true);
    try {
        SOAPMessage reply = SOAPCommunicator.getInstance().createSOAPMessage(header, body, false);
        String[] logdata = { idpEntityID, realm, acsURL, "" };
        if (LogUtil.isAccessLoggable(Level.FINE)) {
            logdata[3] = SOAPCommunicator.getInstance().soapMessageToString(reply);
        }
        LogUtil.access(Level.INFO, LogUtil.SEND_ECP_RESPONSE, logdata, null);
        // are generated as part of the save.
        if (reply.saveRequired()) {
            reply.saveChanges();
        }
        response.setStatus(HttpServletResponse.SC_OK);
        SAML2Utils.putHeaders(reply.getMimeHeaders(), response);
        // Write out the message on the response stream
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        reply.writeTo(stream);
        out.println(stream.toString());
        out.flush();
    } catch (Exception ex) {
        SAML2Utils.debug.error("IDPSSOUtil.sendResponseECP", ex);
        String[] data = { idpEntityID, realm, acsURL };
        LogUtil.error(Level.INFO, LogUtil.SEND_ECP_RESPONSE_FAILED, data, null);
        SAMLUtils.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failedToSendECPResponse", ex.getMessage());
        return;
    }
}
Also used : ECPResponse(com.sun.identity.saml2.ecp.ECPResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) ECPFactory(com.sun.identity.saml2.ecp.ECPFactory) SAML2InvalidNameIDPolicyException(com.sun.identity.saml2.common.SAML2InvalidNameIDPolicyException) SessionException(com.sun.identity.plugin.session.SessionException) COTException(com.sun.identity.cot.COTException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException) IOException(java.io.IOException) SAML2Exception(com.sun.identity.saml2.common.SAML2Exception)

Aggregations

COTException (com.sun.identity.cot.COTException)1 SessionException (com.sun.identity.plugin.session.SessionException)1 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)1 SAML2InvalidNameIDPolicyException (com.sun.identity.saml2.common.SAML2InvalidNameIDPolicyException)1 ECPFactory (com.sun.identity.saml2.ecp.ECPFactory)1 ECPResponse (com.sun.identity.saml2.ecp.ECPResponse)1 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 SAML2TokenRepositoryException (org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)1