Search in sources :

Example 16 with NameIDInfo

use of com.sun.identity.saml2.common.NameIDInfo in project OpenAM by OpenRock.

the class SAML2 method linkAccount.

/**
     * Links SAML2 accounts once all local auth steps have completed and we have a local principalId,
     * sets the local principal to a new SAML2Pricipal with that ID.
     */
private void linkAccount(final String principalId, final NameID nameId) throws SAML2MetaException, AuthenticationException {
    final String spEntityId = metaManager.getEntityByMetaAlias(metaAlias);
    try {
        NameIDInfo info = new NameIDInfo(spEntityId, entityName, nameId, SAML2Constants.SP_ROLE, false);
        DEBUG.message("SAML2 :: Local User {} Linked to Federation Account - {}", principalId, nameId.getValue());
        if (shouldPersistNameID(spEntityId)) {
            AccountUtils.setAccountFederation(info, principalId);
        }
        principal = new SAML2Principal(principalId);
    } catch (SAML2Exception e) {
        // exception logged later
        throw new AuthenticationException(BUNDLE_NAME, "localLinkError", new Object[0]);
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException)

Example 17 with NameIDInfo

use of com.sun.identity.saml2.common.NameIDInfo in project OpenAM by OpenRock.

the class SAML2 method handleReturnFromRedirect.

/**
     * Once we're back from the ACS, we need to validate that we have not errored during the proxying process.
     * Then we detect if we need to perform a local linking authentication chain, or if the user is already
     * locally linked, we need to look up the already-linked username.
     */
private int handleReturnFromRedirect(final int state, final HttpServletRequest request, final String spName, final HttpServletResponse response) throws AuthLoginException {
    //first make sure to delete the cookie
    removeCookiesForRedirects(request, response);
    if (Boolean.parseBoolean(request.getParameter(SAML2Proxy.ERROR_PARAM_KEY))) {
        return handleRedirectError(request);
    }
    final String key;
    if (request.getParameter("jsonContent") != null) {
        key = JsonValueBuilder.toJsonValue(request.getParameter("jsonContent")).get("responsekey").asString();
    } else {
        key = request.getParameter(SAML2Proxy.RESPONSE_KEY);
    }
    final String username;
    SAML2ResponseData data = null;
    if (!StringUtils.isBlank(key)) {
        data = (SAML2ResponseData) SAML2Store.getTokenFromStore(key);
    }
    if (data == null && SAML2FailoverUtils.isSAML2FailoverEnabled() && !StringUtils.isBlank(key)) {
        try {
            data = (SAML2ResponseData) SAML2FailoverUtils.retrieveSAML2Token(key);
        } catch (SAML2TokenRepositoryException e) {
            return processError(bundle.getString("samlFailoverError"), "SAML2.handleReturnFromRedirect : Error reading from failover map.", e);
        }
    }
    if (data == null) {
        return processError(bundle.getString("localLinkError"), "SAML2 :: handleReturnFromRedirect() : " + "Unable to perform local linking - response data key not found");
    }
    storageKey = key;
    assertionSubject = data.getSubject();
    authnAssertion = data.getAssertion();
    sessionIndex = data.getSessionIndex();
    respInfo = data.getResponseInfo();
    try {
        //you're already linked or we auto looked up user
        username = SPACSUtils.getPrincipalWithoutLogin(assertionSubject, authnAssertion, realm, spName, metaManager, entityName, storageKey);
        if (SAML2PluginsUtils.isDynamicProfile(realm)) {
            String spEntityId = SPSSOFederate.getSPEntityId(metaAlias);
            if (shouldPersistNameID(spEntityId)) {
                NameIDInfo info = new NameIDInfo(spEntityId, entityName, getNameId(), SAML2Constants.SP_ROLE, false);
                setUserAttributes(AccountUtils.convertToAttributes(info, null));
            }
        }
        if (username != null) {
            principal = new SAML2Principal(username);
            return success(authnAssertion, getNameId(), username);
        }
    } catch (SAML2Exception e) {
        return processError(e, null, "SAML2.handleReturnFromRedirect : Unable to perform user lookup.");
    }
    if (StringUtils.isBlank(localChain)) {
        return processError(bundle.getString("localLinkError"), "SAML2 :: handleReturnFromRedirect() : " + "Unable to perform local linking - local auth chain not found.");
    }
    //generate a sub-login context, owned by this module, and start login sequence to it
    authenticationContext = new AuthContext(realm);
    authenticationContext.login(AuthContext.IndexType.SERVICE, localChain, null, null, null, null);
    return injectCallbacks(null, state);
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) AuthContext(com.sun.identity.authentication.AuthContext) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)

Example 18 with NameIDInfo

use of com.sun.identity.saml2.common.NameIDInfo in project OpenAM by OpenRock.

the class SAML2PostAuthenticationPlugin method onLoginSuccess.

/**
     * If enabled, performs the first-stage of SLO - by recording the currently logged in user.
     * The information relating to a remote user is stored alongside their local information, and upon
     * active-logout is used to trigger a call to the IdP requesting their logout.
     *
     * @param requestParamsMap map containing <code>HttpServletRequest</code>
     *        parameters
     * @param request <code>HttpServletRequest</code> object.
     * @param response <code>HttpServletResponse</code> object.
     * @param ssoToken authenticated user's single sign token.
     */
@Override
public void onLoginSuccess(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) {
    try {
        final String metaAlias = ssoToken.getProperty(SAML2Constants.METAALIAS);
        final String sessionIndex = ssoToken.getProperty(SAML2Constants.SESSION_INDEX);
        final String spEntityId = ssoToken.getProperty(SAML2Constants.SPENTITYID);
        final String idpEntityId = ssoToken.getProperty(SAML2Constants.IDPENTITYID);
        final String nameIdXML = ssoToken.getProperty(SAML2Constants.NAMEID);
        final NameID nameId = new NameIDImplWithoutSPNameQualifier(nameIdXML);
        final boolean isTransient = Boolean.parseBoolean(ssoToken.getProperty(Constants.IS_TRANSIENT));
        final String requestId = ssoToken.getProperty(Constants.REQUEST_ID);
        final SessionProvider sessionProvider = SessionManager.getProvider();
        final NameIDInfo info = new NameIDInfo(spEntityId, idpEntityId, nameId, SAML2Constants.SP_ROLE, false);
        final String ssOutEnabled = ssoToken.getProperty(SAML2Constants.SINGLE_LOGOUT);
        final String cacheKey = ssoToken.getProperty(Constants.CACHE_KEY);
        final String realm = DNMapper.orgNameToRealmName(ssoToken.getProperty(com.sun.identity.shared.Constants.ORGANIZATION));
        SAML2ResponseData data = (SAML2ResponseData) SAML2Store.getTokenFromStore(cacheKey);
        if (data == null && SAML2FailoverUtils.isSAML2FailoverEnabled()) {
            data = (SAML2ResponseData) SAML2FailoverUtils.retrieveSAML2Token(cacheKey);
        }
        if (data == null) {
            throw new SAML2Exception("Unable to retrieve response map from data cache.");
        }
        if (Boolean.parseBoolean(ssOutEnabled)) {
            setupSingleLogOut(ssoToken, metaAlias, sessionIndex, spEntityId, idpEntityId, nameId);
        }
        configureIdpInitSLO(sessionProvider, ssoToken, sessionIndex, metaAlias, info, isTransient, requestId);
        configurePostSSO(spEntityId, realm, request, response, ssoToken, sessionProvider, data.getResponseInfo(), cacheKey);
        clearSession(ssoToken);
    } catch (SAML2Exception | SessionException | SSOException | SAML2TokenRepositoryException e) {
        //debug warning and fall through
        DEBUG.warning("Error saving SAML assertion information in memory. SLO not configured for this session.", e);
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) NameID(com.sun.identity.saml2.assertion.NameID) NameIDImplWithoutSPNameQualifier(com.sun.identity.saml2.assertion.impl.NameIDImplWithoutSPNameQualifier) SessionException(com.sun.identity.plugin.session.SessionException) SSOException(com.iplanet.sso.SSOException) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Aggregations

SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)15 NameIDInfo (com.sun.identity.saml2.common.NameIDInfo)13 NameID (com.sun.identity.saml2.assertion.NameID)11 SessionException (com.sun.identity.plugin.session.SessionException)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 Map (java.util.Map)5 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)4 NameIDInfoKey (com.sun.identity.saml2.common.NameIDInfoKey)4 SSOException (com.iplanet.sso.SSOException)3 AffiliationDescriptorType (com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType)3 NameIDPolicy (com.sun.identity.saml2.protocol.NameIDPolicy)3 ArrayList (java.util.ArrayList)3 SAML2TokenRepositoryException (org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)3 CLIException (com.sun.identity.cli.CLIException)2 IOutput (com.sun.identity.cli.IOutput)2 AMIdentity (com.sun.identity.idm.AMIdentity)2