Search in sources :

Example 11 with SPDescriptorType

use of com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType in project OpenAM by OpenRock.

the class FSSSOAndFedHandler method sendProxyAuthnRequest.

/**
     * Sends a new AuthnRequest to the authenticating provider. 
     * @param authnRequest original AuthnRequest sent by the service provider.
     * @param preferredIDP IDP to be proxied.
     * @exception FSException for any federation failure.
     * @exception IOException if there is a failure in redirection.
     */
protected void sendProxyAuthnRequest(FSAuthnRequest authnRequest, String preferredIDP) throws FSException, IOException {
    FSAuthnRequest newAuthnRequest = getNewAuthnRequest(authnRequest);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSSSOAndFedHandler.sendProxyAuthnRequest:" + "New Authentication request:" + newAuthnRequest.toXMLString());
    }
    FSSessionManager sessManager = FSSessionManager.getInstance(IDFFMetaUtils.getMetaAlias(realm, hostedEntityId, IFSConstants.SP, null));
    String requestID = newAuthnRequest.getRequestID();
    sessManager.setAuthnRequest(requestID, newAuthnRequest);
    sessManager.setProxySPDescriptor(requestID, spDescriptor);
    sessManager.setProxySPAuthnRequest(requestID, authnRequest);
    sessManager.setIDPEntityID(requestID, preferredIDP);
    String targetURL = null;
    SPDescriptorType localDescriptor = null;
    BaseConfigType localDescriptorConfig = null;
    try {
        IDPDescriptorType idpDescriptor = metaManager.getIDPDescriptor(realm, preferredIDP);
        targetURL = idpDescriptor.getSingleSignOnServiceURL();
        if (targetURL == null) {
            FSUtils.debug.error("FSSSOAndFedHandler.sendProxyAuthnRequest: Single " + "Sign-on service is not found for the proxying IDP");
            return;
        }
        localDescriptor = metaManager.getSPDescriptor(realm, hostedEntityId);
        localDescriptorConfig = metaManager.getSPDescriptorConfig(realm, hostedEntityId);
    } catch (Exception e) {
        FSUtils.debug.error("FSSSOAndFedHandler.sendProxyAuthnRequest:", e);
        return;
    }
    String queryString = newAuthnRequest.toURLEncodedQueryString();
    if (FSServiceUtils.isSigningOn()) {
        String certAlias = IDFFMetaUtils.getFirstAttributeValueFromConfig(localDescriptorConfig, IFSConstants.SIGNING_CERT_ALIAS);
        if (localDescriptor.isAuthnRequestsSigned()) {
            queryString = FSSignatureUtil.signAndReturnQueryString(queryString, certAlias);
        }
    }
    StringBuffer tmpURL = new StringBuffer(1000);
    if (targetURL.indexOf("?") != -1) {
        tmpURL.append(targetURL).append("&").append(queryString);
    } else {
        tmpURL.append(targetURL).append("?").append(queryString);
    }
    String redirectURL = tmpURL.toString();
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSSSOAndFedHandler.sendProxyAuthnRequest:" + "SSO URL to be redirected" + redirectURL);
    }
    response.setStatus(response.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", redirectURL);
    response.sendRedirect(redirectURL);
}
Also used : BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) IDPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType) FSAuthnRequest(com.sun.identity.federation.message.FSAuthnRequest) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) SPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType) SessionException(com.sun.identity.plugin.session.SessionException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSAccountMgmtException(com.sun.identity.federation.accountmgmt.FSAccountMgmtException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) FSRedirectException(com.sun.identity.federation.common.FSRedirectException)

Example 12 with SPDescriptorType

use of com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType in project OpenAM by OpenRock.

the class FSAssertionConsumerService method doGet.

/**
     * Handles artifact profile.
     * @param request <code>HttpServletRequest</code> object
     * @param response <code>HttpServletResponse</code> object
     * @exception ServletException, IOException if error occurrs.
     */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if ((request == null) || (response == null)) {
        response.sendError(response.SC_INTERNAL_SERVER_ERROR, FSUtils.bundle.getString("nullInputParameter"));
        return;
    }
    FSUtils.debug.message("FSAssertionConsumerService.doGet(): called");
    String relayState = request.getParameter(IFSConstants.LRURL);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionConsumerService.doGet():Resource URL: " + relayState);
    }
    String metaAlias = FSServiceUtils.getMetaAlias(request);
    String realm = IDFFMetaUtils.getRealmByMetaAlias(metaAlias);
    String baseURL = FSServiceUtils.getBaseURL(request);
    String framedPageURL = FSServiceUtils.getCommonLoginPageURL(metaAlias, relayState, null, request, baseURL);
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSAssertionConsumerService: CommonLoginPage: " + framedPageURL);
    }
    SPDescriptorType hostDesc = null;
    BaseConfigType hostConfig = null;
    String hostEntityId = null;
    try {
        hostEntityId = metaManager.getEntityIDByMetaAlias(metaAlias);
        hostDesc = metaManager.getSPDescriptor(realm, hostEntityId);
        hostConfig = metaManager.getSPDescriptorConfig(realm, hostEntityId);
    } catch (Exception e) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", e);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
    FSRequest samlRequest = null;
    String firstSourceID = null;
    String artifactName = IFSConstants.ARTIFACT_NAME_DEFAULT;
    String[] arti = (String[]) request.getParameterValues(artifactName);
    if ((arti == null) || (arti.length < 0) || (arti[0] == null)) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "AuthnRequest Processing Failed at the IDP " + "Redirecting to the Framed Login Page");
        FSUtils.forwardRequest(request, response, framedPageURL);
    }
    List al = new ArrayList();
    try {
        FSAssertionArtifact firstArtifact = new FSAssertionArtifact(arti[0]);
        firstSourceID = firstArtifact.getSourceID();
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "SourceID within the Artifact is " + firstSourceID);
        }
        al.add(firstArtifact);
        for (int k = 1; k < arti.length; k++) {
            // check all artifacts coming from the same source id
            FSAssertionArtifact assertArtifact = new FSAssertionArtifact(arti[k]);
            String dest = assertArtifact.getSourceID();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "SourceID within the Artifact is " + dest);
            }
            if (!dest.equals(firstSourceID)) {
                FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "Received multiple artifacts have different source id");
                FSUtils.forwardRequest(request, response, framedPageURL);
                return;
            }
            al.add(assertArtifact);
        }
        samlRequest = new FSRequest(null, al);
    } catch (SAMLException se) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", se);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    } catch (FSMsgException se) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: ", se);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
    try {
        // handle sso
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "Trying to get BrowserArtifactHandler");
        }
        FSServiceManager sm = FSServiceManager.getInstance();
        FSAssertionArtifactHandler handler = sm.getBrowserArtifactHandler(request, response, realm, firstSourceID, samlRequest, relayState);
        if (handler == null) {
            FSUtils.debug.error("FSAssertionConsumerService.doGet: " + FSUtils.bundle.getString("internalError"));
            FSUtils.forwardRequest(request, response, framedPageURL);
            return;
        }
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSAssertionConsumerService.doGet: " + "BrowserArtifactHandler created");
        }
        handler.setRealm(realm);
        handler.setHostEntityId(hostEntityId);
        handler.setMetaAlias(metaAlias);
        handler.setHostDescriptor(hostDesc);
        handler.setHostDescriptorConfig(hostConfig);
        handler.processSAMLRequest();
        return;
    } catch (Exception e) {
        FSUtils.debug.error("FSAssertionConsumerService.doGet: " + "Exception occurred :", e);
        FSUtils.forwardRequest(request, response, framedPageURL);
        return;
    }
}
Also used : FSMsgException(com.sun.identity.federation.message.common.FSMsgException) ArrayList(java.util.ArrayList) SPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType) SAMLException(com.sun.identity.saml.common.SAMLException) ServletException(javax.servlet.ServletException) SAMLException(com.sun.identity.saml.common.SAMLException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) FSServiceManager(com.sun.identity.federation.services.FSServiceManager) ArrayList(java.util.ArrayList) List(java.util.List) FSAssertionArtifact(com.sun.identity.federation.message.FSAssertionArtifact) FSRequest(com.sun.identity.federation.message.FSRequest)

Aggregations

SPDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.SPDescriptorType)12 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)8 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)7 IDPDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType)7 IDFFMetaManager (com.sun.identity.federation.meta.IDFFMetaManager)6 FSException (com.sun.identity.federation.common.FSException)5 FSAuthnRequest (com.sun.identity.federation.message.FSAuthnRequest)5 FSSessionManager (com.sun.identity.federation.services.FSSessionManager)5 SAMLException (com.sun.identity.saml.common.SAMLException)5 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)4 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)3 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Set (java.util.Set)3 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)2 COTException (com.sun.identity.cot.COTException)2 FSRedirectException (com.sun.identity.federation.common.FSRedirectException)2 FSServiceManager (com.sun.identity.federation.services.FSServiceManager)2