Search in sources :

Example 6 with StatusCode

use of com.sun.identity.saml.protocol.StatusCode in project OpenAM by OpenRock.

the class FSNameRegistrationHandler method processSOAPRegistrationRequest.

/**
     * Processes the name registration request received from a
     * remote provider. Invoded when SOAP profile is used.
     * @param regisRequest the name registration request received from 
     *  remote provider
     */
public FSNameRegistrationResponse processSOAPRegistrationRequest(HttpServletRequest request, HttpServletResponse response, FSNameRegistrationRequest regisRequest) {
    relayState = regisRequest.getRelayState();
    try {
        boolean regisSucceed = false;
        FSNameRegistrationResponse regisResponse = null;
        StatusCode statusCode;
        FSUtils.debug.message("Entered FSNameRegistrationHandler::processRegistrationRequest");
        if (managerInst == null) {
            FSUtils.debug.error("FSNameRegistrationHandler Account Manager instance is null");
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSNameRegistrationHandler::handleNameRegistration" + "failed to get Account Manager instance");
            }
            statusCode = new StatusCode(IFSConstants.REGISTRATION_FAILURE_STATUS);
            try {
                regisResponse = new FSNameRegistrationResponse(null, regisRequest.getRequestID(), new Status(statusCode), hostedEntityId, relayState);
            } catch (FSMsgException e) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                }
                return null;
            }
            regisResponse.setID(IFSConstants.REGISTRATIONID);
            regisResponse.setMinorVersion(regisRequest.getMinorVersion());
            return regisResponse;
        }
        FSUtils.debug.message("Begin processRegistrationRequest SOAP profile...");
        if (regisRequest != null) {
            boolean bUserStatus = setUserDN(regisRequest);
            if (bUserStatus) {
                boolean retStatus = doCommonRegistration();
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("doCommonRegistration returns " + retStatus);
                }
                if (retStatus) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSNameRegistrationHandler::handleNameRegistra" + "tion:registration in DS completed " + "successfully");
                    }
                    try {
                        statusCode = new StatusCode(IFSConstants.SAML_SUCCESS);
                        regisResponse = new FSNameRegistrationResponse(null, regisRequest.getRequestID(), new Status(statusCode), hostedEntityId, relayState);
                        regisSucceed = true;
                    } catch (FSMsgException e) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                        }
                        return null;
                    } catch (SAMLException ex) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                        }
                        return null;
                    }
                } else {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSNameRegistrationHandler::handleNameRegis" + "tration: registration in DS failed");
                    }
                    try {
                        statusCode = new StatusCode(IFSConstants.REGISTRATION_FAILURE_STATUS);
                        regisResponse = new FSNameRegistrationResponse(null, regisRequest.getRequestID(), new Status(statusCode), hostedEntityId, relayState);
                    } catch (FSMsgException e) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                        }
                        return null;
                    } catch (SAMLException ex) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                        }
                        return null;
                    }
                }
            } else {
                FSUtils.debug.message("Failed to get UserDN. Invalid registration request");
                try {
                    statusCode = new StatusCode(IFSConstants.FEDERATION_NOT_EXISTS_STATUS);
                    regisResponse = new FSNameRegistrationResponse(null, regisRequest.getRequestID(), new Status(statusCode), hostedEntityId, relayState);
                } catch (FSMsgException e) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                    }
                    return null;
                } catch (SAMLException ex) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSNameRegistrationHandler::" + "failed to create registration response");
                    }
                    return null;
                }
            }
        } else {
            FSUtils.debug.error("FSNameRegistrationHandler::processRegistrationRequest " + "name registration request is improper");
            return null;
        }
        regisResponse.setID(IFSConstants.REGISTRATIONID);
        regisResponse.setMinorVersion(regisRequest.getMinorVersion());
        if (regisSucceed && hostedProviderRole != null && hostedProviderRole.equalsIgnoreCase(IFSConstants.SP)) {
            callPostRegisterNameIdentifierSuccess(request, response, userID, regisRequest, regisResponse, IFSConstants.NAME_REGISTRATION_IDP_SOAP_PROFILE);
        }
        return regisResponse;
    } catch (SAMLException e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSNameRegistrationHandler::SAMLException", e);
        }
        return null;
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) FSNameRegistrationResponse(com.sun.identity.federation.message.FSNameRegistrationResponse) StatusCode(com.sun.identity.saml.protocol.StatusCode) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 7 with StatusCode

use of com.sun.identity.saml.protocol.StatusCode in project OpenAM by OpenRock.

the class FSDefaultSPAdapter method postSSOFederationFailure.

/**
     * Invokes this method if the Single-Sign-On or Federation fails 
     * for some reason.
     * @param request servlet request
     * @param response servlet response
     * @param authnRequest the original authentication request sent from SP 
     * @param authnResponse response from IDP if Browser POST or LECP profile
     *        is used for the request, value will be null if Browser Artifact
     *        profile is used. 
     * @param samlResponse response from IDP if Browser Artifact profile is used
     *        for the request, value will be null if Browser POST or LECP 
     *        profile is used.
     * @param failureCode an integer specifies the failure code.
     * @return true if browser redirection happened, false otherwise.
     */
public boolean postSSOFederationFailure(String hostedEntityID, HttpServletRequest request, HttpServletResponse response, FSAuthnRequest authnRequest, FSAuthnResponse authnResponse, FSResponse samlResponse, int failureCode) {
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSDefaultSPAdapter.postFedFailure, " + "process " + hostedEntityID + "\nfailure code=" + failureCode);
    }
    String baseURL = FSServiceUtils.getBaseURL(request);
    String relayState = null;
    if (authnRequest != null) {
        relayState = authnRequest.getRelayState();
    }
    String framedLoginPageURL = FSServiceUtils.getCommonLoginPageURL(FSServiceUtils.getMetaAlias(request), relayState, null, request, baseURL);
    StringBuffer sb = new StringBuffer();
    sb.append(framedLoginPageURL).append("&").append(IFSConstants.FAILURE_CODE).append("=").append(failureCode);
    if (failureCode == INVALID_AUTHN_RESPONSE || failureCode == INVALID_RESPONSE) {
        Status status = null;
        if (failureCode == INVALID_AUTHN_RESPONSE) {
            status = authnResponse.getStatus();
        } else {
            status = samlResponse.getStatus();
        }
        StatusCode firstLevelStatusCode = status.getStatusCode();
        if (firstLevelStatusCode == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSDefaultSPAdapter.postSSO" + "FederationFailure: Status is null");
            }
            return false;
        }
        StatusCode secondLevelStatusCode = firstLevelStatusCode.getStatusCode();
        if (secondLevelStatusCode == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSDefaultSPAdapter.postSSO" + "FederationFailure: Second level status is empty");
            }
            return false;
        }
        String statusValue = URLEncDec.encode(secondLevelStatusCode.getValue());
        sb.append("&").append(IFSConstants.STATUS_CODE).append("=").append(statusValue);
    }
    String redirectURL = sb.toString();
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSDefaultSPAdapter.postSSOFederation" + "Failure. URL to be redirected: " + redirectURL);
    }
    try {
        response.setHeader("Location", redirectURL);
        response.sendRedirect(redirectURL);
    } catch (java.io.IOException io) {
        FSUtils.debug.error("FSDefaultSPAdapter.postSSOFedFailure", io);
        return false;
    }
    return true;
}
Also used : Status(com.sun.identity.saml.protocol.Status) StatusCode(com.sun.identity.saml.protocol.StatusCode)

Example 8 with StatusCode

use of com.sun.identity.saml.protocol.StatusCode in project OpenAM by OpenRock.

the class FSSSOAndFedHandler method doSingleSignOn.

protected boolean doSingleSignOn(Object ssoToken, String inResponseTo) {
    FSUtils.debug.message("FSSSOAndFedHandler.doSingleSignOn(2):  Called");
    try {
        String securityDomain = authnRequest.getProviderId();
        String affiliationID = authnRequest.getAffiliationID();
        if (affiliationID != null) {
            securityDomain = affiliationID;
        }
        SessionProvider sessionProvider = SessionManager.getProvider();
        String userID = sessionProvider.getPrincipalName(ssoToken);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSSOAndFedHandler.doSingleSignOn: " + "Initiating SSO for user with ID: " + userID);
        }
        FSAccountFedInfo accountInfo = accountManager.readAccountFedInfo(userID, securityDomain);
        if (accountInfo == null) {
            FSUtils.debug.error("FSSSOAndFedHandler.doSingleSignOn: Account Federation " + "Information not found for user with ID: " + userID);
            noFedStatus = new Status(new StatusCode("samlp:Responder", new StatusCode("lib:FederationDoesNotExist", null)), FSUtils.bundle.getString("AuthnRequestProcessingFailed"), null);
            String[] data = { userID };
            LogUtil.error(Level.INFO, LogUtil.USER_ACCOUNT_FEDERATION_INFO_NOT_FOUND, data, ssoToken);
            return false;
        }
        if (accountInfo != null && accountInfo.isFedStatusActive() && accountInfo.getLocalNameIdentifier() != null) {
            // Check if this is 6.2
            NameIdentifier localNI = accountInfo.getLocalNameIdentifier();
            String qualifier = localNI.getNameQualifier();
            if (qualifier != null && qualifier.equals(hostedEntityId)) {
                localNI = new NameIdentifier(localNI.getName(), securityDomain);
                NameIdentifier remoteNI = accountInfo.getRemoteNameIdentifier();
                if (remoteNI != null) {
                    remoteNI = new NameIdentifier(remoteNI.getName(), securityDomain);
                }
                FSAccountFedInfoKey newFedKey = new FSAccountFedInfoKey(securityDomain, localNI.getName());
                accountInfo = new FSAccountFedInfo(securityDomain, localNI, remoteNI, false);
                accountManager.writeAccountFedInfo(userID, newFedKey, accountInfo);
                FSAccountFedInfoKey oldFedKey = new FSAccountFedInfoKey(hostedEntityId, localNI.getName());
                accountManager.removeAccountFedInfoKey(userID, oldFedKey);
            }
        }
        NameIdentifier idpNI = accountInfo.getLocalNameIdentifier();
        if (idpNI == null) {
            idpNI = accountInfo.getRemoteNameIdentifier();
            if (idpNI == null) {
                FSUtils.debug.error("FSSSOAndFedHandler.doSingleSignOn: " + "NameIdentifier not found");
                return false;
            }
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.doSingleSignOn: " + "IDP generated opaque handle: " + idpNI.getName());
            }
        }
        NameIdentifier spNI = accountInfo.getRemoteNameIdentifier();
        if (spNI == null) {
            spNI = idpNI;
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.doSingleSignOn: " + "SP generated opaque handle: " + spNI.getName());
            }
        }
        return doSingleSignOn(ssoToken, inResponseTo, spNI, idpNI);
    } catch (Exception e) {
        FSUtils.debug.error("FSSSOAndFedHandler.doSingleSignOn: " + "Exception during Single Sign-On:", e);
        return false;
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) FSAccountFedInfo(com.sun.identity.federation.accountmgmt.FSAccountFedInfo) NameIdentifier(com.sun.identity.saml.assertion.NameIdentifier) FSAccountFedInfoKey(com.sun.identity.federation.accountmgmt.FSAccountFedInfoKey) StatusCode(com.sun.identity.saml.protocol.StatusCode) 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) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 9 with StatusCode

use of com.sun.identity.saml.protocol.StatusCode in project OpenAM by OpenRock.

the class FSSSOAndFedHandler method processPreAuthnSSO.

/**
     * Handles authentication request.
     * @param authnRequest <code>FSAuthnRequest</code> object
     * @return <code>true</code> if the request is handled successfully;
     *  <code>false</code> otherwise.
     */
public boolean processPreAuthnSSO(FSAuthnRequest authnRequest) {
    FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: Called");
    String loginURL = null;
    List authenticationContextClassRef = null;
    String currentAuthnContextRef = null;
    String authType = null;
    FSAuthContextResult authnResult = null;
    FSSessionManager sessionMgr = FSSessionManager.getInstance(metaAlias);
    if (authnRequest.getAuthnContext() != null) {
        authenticationContextClassRef = authnRequest.getAuthnContext().getAuthnContextClassRefList();
        if (authenticationContextClassRef == null) {
            String authCtxRefDefault = IFSConstants.DEFAULT_AUTHNCONTEXT_PASSWORD;
            authenticationContextClassRef = new ArrayList();
            authenticationContextClassRef.add(authCtxRefDefault);
        }
        authType = authnRequest.getAuthContextCompType();
        currentAuthnContextRef = null;
    }
    boolean authenticated = true;
    Object ssoToken = null;
    try {
        SessionProvider sessionProvider = SessionManager.getProvider();
        ssoToken = sessionProvider.getSession(request);
        if (ssoToken == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "session is null. User is not authenticated.");
            }
            authenticated = false;
        } else if (!sessionProvider.isValid(ssoToken)) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "session is not valid. User is not authenticated.");
            }
            authenticated = false;
        } else {
            FSSession ssoSession = sessionMgr.getSession(ssoToken);
            if (ssoSession != null) {
                currentAuthnContextRef = ssoSession.getAuthnContext();
                if (currentAuthnContextRef != null) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User has an existing " + "valid session with authnContext: " + currentAuthnContextRef);
                    }
                } else {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's authentication" + " context information not found using " + "default authentication context");
                    }
                    currentAuthnContextRef = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.DEFAULT_AUTHNCONTEXT);
                }
            } else {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSSOAndFedHandler.process" + "PreAuthnSSO: User's authenticated session " + "information is not present in FSSessionManager. " + "using default authentication context");
                }
                currentAuthnContextRef = IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.DEFAULT_AUTHNCONTEXT);
            }
            authenticated = true;
        }
        if (authenticated) {
            // added in case of multiple SPs
            try {
                sessionProvider.addListener(ssoToken, new FSTokenListener(metaAlias));
            } catch (Exception e) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "Couldn't add listener to session:", e);
                }
            }
        }
    } catch (SessionException se) {
        FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "SSOException Occured: User does not have session " + se.getMessage());
        authenticated = false;
    }
    //Initiate proxying
    if (!authenticated) {
        try {
            boolean isProxy = isIDPProxyEnabled(authnRequest);
            if (isProxy && !authnRequest.getFederate()) {
                String preferredIDP = getPreferredIDP(authnRequest);
                if (preferredIDP != null) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler.process" + "PreAuthnSSO:IDP to be proxied" + preferredIDP);
                    }
                    sendProxyAuthnRequest(authnRequest, preferredIDP);
                    return true;
                }
            //else continue for the local authentication.
            }
        } catch (FSRedirectException re) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandle.processPreAuthnSSO:" + "Redirecting for the proxy handling.");
            }
            return true;
        } catch (Exception ex) {
            FSUtils.debug.error("FSSSOAndFedHandler.processPreAuthnSSO:" + "Exception occured while processing for the proxy.", ex);
            return false;
        }
    }
    try {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "User's authentication status: " + authenticated);
        }
        FSAuthnDecisionHandler authnDecisionHandler = new FSAuthnDecisionHandler(realm, hostedEntityId, request);
        List defAuthnCxtList = new ArrayList();
        defAuthnCxtList.add(IDFFMetaUtils.getFirstAttributeValueFromConfig(hostedConfig, IFSConstants.DEFAULT_AUTHNCONTEXT));
        if (authnRequest.getIsPassive()) {
            if (authnRequest.getForceAuthn()) {
                if (FSUtils.debug.warningEnabled()) {
                    FSUtils.debug.warning("FSSSOAndFedHandler.PreAuthnSSO: " + "IDP is passive can't force authentication.");
                }
                return false;
            } else {
                if (authenticated) {
                    if (authenticationContextClassRef != null) {
                        authnResult = authnDecisionHandler.decideAuthnContext(authenticationContextClassRef, currentAuthnContextRef, authType);
                    } else {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's " + "authentication context is default");
                        }
                        authnResult = authnDecisionHandler.getURLForAuthnContext(defAuthnCxtList, authType);
                    }
                    if (authnResult == null) {
                        return false;
                    }
                    if (authnResult.getLoginURL() != null) {
                        // When it's not null.,
                        // we should show the login page
                        // may be it'asking for higher auth context.
                        loginURL = authnResult.getLoginURL();
                        loginURL = formatLoginURL(loginURL, authnResult.getAuthContextRef());
                        FSUtils.forwardRequest(request, response, loginURL);
                        return true;
                    } else {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's " + "authentication " + "context is evaluated to be valid");
                        }
                        return processPostAuthnSSO(authnRequest);
                    }
                } else {
                    if (FSUtils.debug.warningEnabled()) {
                        FSUtils.debug.warning("FSSSOAndFedHandler.processPreAuthnSSO: " + "IDP is passive and user is not authenticated");
                    }
                    noFedStatus = new Status(new StatusCode("samlp:Responder", new StatusCode("lib:NoPassive", null)), FSUtils.bundle.getString("AuthnRequestProcessingFailed"), null);
                    return false;
                }
            }
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: AuthnRequest is active");
            }
            if (authnRequest.getForceAuthn()) {
                if (authenticationContextClassRef != null) {
                    authnResult = authnDecisionHandler.getURLForAuthnContext(authenticationContextClassRef, authType);
                } else {
                    authnResult = authnDecisionHandler.getURLForAuthnContext(defAuthnCxtList);
                }
                if (authnResult == null || authnResult.getLoginURL() == null || authnResult.getLoginURL().length() == 0) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO:" + "AuthnDecision engine failed to take a " + "authn decision");
                    }
                    return false;
                } else {
                    if (ssoToken != null) {
                        try {
                            SessionManager.getProvider().invalidateSession(ssoToken, request, response);
                        } catch (SessionException ssoe) {
                            FSUtils.debug.error("FSSSOAndFedHandler.processPreAuthnSSO:" + "Unable to invalidate the sso session.");
                        }
                        ssoToken = null;
                    }
                    loginURL = authnResult.getLoginURL();
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "AuthnDecision engine returned: " + loginURL);
                    }
                }
                loginURL = formatLoginURL(loginURL, authnResult.getAuthContextRef());
                FSUtils.forwardRequest(request, response, loginURL);
                response.flushBuffer();
                return true;
            } else {
                if (authenticated) {
                    if (authenticationContextClassRef != null) {
                        authnResult = authnDecisionHandler.decideAuthnContext(authenticationContextClassRef, currentAuthnContextRef, authType);
                    } else {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's " + "authentication " + "context is default");
                        }
                        authnResult = authnDecisionHandler.getURLForAuthnContext(defAuthnCxtList, authType);
                    }
                    if (authnResult == null) {
                        return false;
                    } else if (authnResult.getLoginURL() == null) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's " + "authentication " + "context is evaluated to be valid");
                        }
                        return processPostAuthnSSO(authnRequest);
                    } else if (authnResult.getLoginURL().length() == 0) {
                        return false;
                    } else {
                        loginURL = authnResult.getLoginURL();
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO" + ": AuthnDecision engine returned: " + loginURL);
                        }
                    }
                    loginURL = formatLoginURL(loginURL, authnResult.getAuthContextRef());
                    FSUtils.forwardRequest(request, response, loginURL);
                    return true;
                } else {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: AuthnRequest is active");
                    }
                    //redirect for authentication authnContextRef
                    if (authenticationContextClassRef != null) {
                        authnResult = authnDecisionHandler.getURLForAuthnContext(authenticationContextClassRef, authType);
                    } else {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler." + "processPreAuthnSSO: User's " + "authentication " + "context is default");
                        }
                        authnResult = authnDecisionHandler.getURLForAuthnContext(defAuthnCxtList, authType);
                    }
                    if (authnResult == null || authnResult.getLoginURL() == null || authnResult.getLoginURL().length() == 0) {
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler. processPreAuthnSSO: " + " AuthnDecision engine" + " failed to take a decision");
                        }
                        noFedStatus = new Status(new StatusCode("samlp:Responder", new StatusCode("lib:NoAuthnContext", null)), FSUtils.bundle.getString("AuthnRequestProcessingFailed"), null);
                        return false;
                    } else {
                        loginURL = authnResult.getLoginURL();
                        if (FSUtils.debug.messageEnabled()) {
                            FSUtils.debug.message("FSSSOAndFedHandler.processPreAuthnSSO: " + "AuthnDecision engine returned: " + loginURL);
                        }
                    }
                    loginURL = formatLoginURL(loginURL, authnResult.getAuthContextRef());
                    FSUtils.forwardRequest(request, response, loginURL);
                    return true;
                }
            }
        }
    } catch (Exception e) {
        FSUtils.debug.error("FSSSOAndFedHandler.processPreAuthnSSO: " + "Exception occured");
        return processPostAuthnSSO(authnRequest);
    }
}
Also used : Status(com.sun.identity.saml.protocol.Status) ArrayList(java.util.ArrayList) FSSession(com.sun.identity.federation.services.FSSession) SessionException(com.sun.identity.plugin.session.SessionException) FSRedirectException(com.sun.identity.federation.common.FSRedirectException) StatusCode(com.sun.identity.saml.protocol.StatusCode) 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) FSAuthContextResult(com.sun.identity.federation.services.FSAuthContextResult) FSAuthnDecisionHandler(com.sun.identity.federation.services.FSAuthnDecisionHandler) List(java.util.List) ArrayList(java.util.ArrayList) FSTokenListener(com.sun.identity.federation.services.logout.FSTokenListener) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 10 with StatusCode

use of com.sun.identity.saml.protocol.StatusCode in project OpenAM by OpenRock.

the class FSSingleLogoutHandler method doSoapProfile.

/**
     * Initiates SOAP proifle logout.
     * @param providerId the first provider with SOAP as logout profile
     */
private FSLogoutStatus doSoapProfile(String providerId) {
    FSUtils.debug.message("Entered IDP's doSoapProfile");
    try {
        FSSessionManager sMgr = FSSessionManager.getInstance(metaAlias);
        FSSession session = sMgr.getSession(ssoToken);
        FSAccountFedInfo currentAccount = null;
        if (session != null) {
            currentAccount = session.getAccountFedInfo();
        }
        if (currentAccount == null && !session.getOneTime()) {
            currentAccount = FSLogoutUtil.getCurrentWorkingAccount(userID, providerId, metaAlias);
        }
        if (currentAccount == null) {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSSingleLogoutHandler. User's " + "account may have been terminated.");
            }
            return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
        }
        FSLogoutNotification reqLogout = createSingleLogoutRequest(currentAccount, sessionIndex);
        reqLogout.setMinorVersion(getMinorVersion(remoteDescriptor));
        if (reqLogout != null) {
            FSSOAPService instSOAP = FSSOAPService.getInstance();
            if (instSOAP != null) {
                FSUtils.debug.message("Signing suceeded. To call bindLogoutRequest");
                reqLogout.setID(IFSConstants.LOGOUTID);
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("logout request before sign: " + reqLogout.toXMLString(true, true));
                }
                SOAPMessage msgLogout = instSOAP.bind(reqLogout.toXMLString(true, true));
                if (msgLogout != null) {
                    SOAPMessage retSOAPMessage = null;
                    try {
                        if (FSServiceUtils.isSigningOn()) {
                            int minorVersion = reqLogout.getMinorVersion();
                            switch(minorVersion) {
                                case IFSConstants.FF_11_PROTOCOL_MINOR_VERSION:
                                    msgLogout = signLogoutRequest(msgLogout, IFSConstants.ID, reqLogout.getID());
                                    break;
                                case IFSConstants.FF_12_PROTOCOL_MINOR_VERSION:
                                    msgLogout = signLogoutRequest(msgLogout, IFSConstants.REQUEST_ID, reqLogout.getRequestID());
                                    break;
                                default:
                                    FSUtils.debug.message("invalid minor version.");
                                    break;
                            }
                        }
                        retSOAPMessage = instSOAP.sendMessage(msgLogout, remoteDescriptor.getSoapEndpoint());
                    } catch (Exception e) {
                        FSUtils.debug.error("FSSOAPException in doSOAPProfile" + " Cannot send request", e);
                        return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
                    }
                    if (retSOAPMessage != null) {
                        Element elt = instSOAP.parseSOAPMessage(retSOAPMessage);
                        if (FSServiceUtils.isSigningOn()) {
                            if (!verifyResponseSignature(retSOAPMessage)) {
                                if (FSUtils.debug.messageEnabled()) {
                                    FSUtils.debug.message("Response " + "signature verification failed");
                                }
                                FSServiceUtils.returnLocallyAfterOperation(response, LOGOUT_DONE_URL, false, IFSConstants.LOGOUT_SUCCESS, IFSConstants.LOGOUT_FAILURE);
                                return new FSLogoutStatus(IFSConstants.SAML_REQUESTER);
                            }
                        }
                        this.requestLogout = reqLogout;
                        respObj = new FSLogoutResponse(elt);
                        // Call SP Adapter preSingleLogout for SP/SOAP
                        if (hostedRole != null && hostedRole.equalsIgnoreCase(IFSConstants.SP)) {
                            FederationSPAdapter spAdapter = FSServiceUtils.getSPAdapter(hostedEntityId, hostedConfig);
                            if (spAdapter != null) {
                                if (FSUtils.debug.messageEnabled()) {
                                    FSUtils.debug.message("FSSLOHandler." + "preSingleLogoutProcess, SP/SOAP");
                                }
                                try {
                                    spAdapter.preSingleLogoutProcess(hostedEntityId, request, response, userID, reqLogout, respObj, IFSConstants.LOGOUT_SP_SOAP_PROFILE);
                                } catch (Exception e) {
                                    // ignore adapter error
                                    FSUtils.debug.error("spAdapter." + "preSingleLogoutProcess, SP/SOAP:", e);
                                }
                            }
                        }
                        Status status = respObj.getStatus();
                        StatusCode statusCode = status.getStatusCode();
                        StatusCode secondLevelStatus = statusCode.getStatusCode();
                        String statusString = statusCode.getValue();
                        if (statusString.equalsIgnoreCase(IFSConstants.SAML_SUCCESS)) {
                            if (FSUtils.debug.messageEnabled()) {
                                FSUtils.debug.message("FSSingleLogoutHandler: " + " doSoapProfile returning success");
                            }
                            return new FSLogoutStatus(IFSConstants.SAML_SUCCESS);
                        } else {
                            if (FSUtils.debug.messageEnabled()) {
                                FSUtils.debug.message("FSSingleLogoutHandler: " + "SOAP Profile failure " + statusString);
                            }
                            return new FSLogoutStatus(statusString);
                        }
                    }
                }
            }
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Unable to bindLogoutRequest." + "Current Provider cannot be processed");
            }
        } else {
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("Unable to create logout request" + " Current Provider cannot be processed");
            }
        }
    } catch (Exception e) {
        FSUtils.debug.error("In IOException of doSOAPProfile : ", e);
    }
    return new FSLogoutStatus(IFSConstants.SAML_RESPONDER);
}
Also used : Status(com.sun.identity.saml.protocol.Status) FSAccountFedInfo(com.sun.identity.federation.accountmgmt.FSAccountFedInfo) Element(org.w3c.dom.Element) FSSession(com.sun.identity.federation.services.FSSession) FSLogoutNotification(com.sun.identity.federation.message.FSLogoutNotification) FSSOAPService(com.sun.identity.federation.services.FSSOAPService) SOAPMessage(javax.xml.soap.SOAPMessage) FSLogoutResponse(com.sun.identity.federation.message.FSLogoutResponse) StatusCode(com.sun.identity.saml.protocol.StatusCode) ServletException(javax.servlet.ServletException) SAMLResponderException(com.sun.identity.saml.common.SAMLResponderException) SessionException(com.sun.identity.plugin.session.SessionException) SAMLException(com.sun.identity.saml.common.SAMLException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) IOException(java.io.IOException) FSMsgException(com.sun.identity.federation.message.common.FSMsgException) FSSessionManager(com.sun.identity.federation.services.FSSessionManager) FederationSPAdapter(com.sun.identity.federation.plugins.FederationSPAdapter)

Aggregations

Status (com.sun.identity.saml.protocol.Status)16 StatusCode (com.sun.identity.saml.protocol.StatusCode)16 SAMLException (com.sun.identity.saml.common.SAMLException)13 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)7 SessionException (com.sun.identity.plugin.session.SessionException)7 IOException (java.io.IOException)7 FSException (com.sun.identity.federation.common.FSException)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)4 SessionProvider (com.sun.identity.plugin.session.SessionProvider)4 ParseException (java.text.ParseException)4 ServletException (javax.servlet.ServletException)4 FSAccountMgmtException (com.sun.identity.federation.accountmgmt.FSAccountMgmtException)3 FSRedirectException (com.sun.identity.federation.common.FSRedirectException)3 FSAuthnResponse (com.sun.identity.federation.message.FSAuthnResponse)3 Assertion (com.sun.identity.saml.assertion.Assertion)3 SAMLResponderException (com.sun.identity.saml.common.SAMLResponderException)3 Response (com.sun.identity.saml.protocol.Response)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3