Search in sources :

Example 26 with SessionIndex

use of com.sun.identity.saml2.protocol.SessionIndex 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)

Example 27 with SessionIndex

use of com.sun.identity.saml2.protocol.SessionIndex in project OpenAM by OpenRock.

the class SAML2PostAuthenticationPlugin method createLogoutRequest.

private LogoutRequest createLogoutRequest(String metaAlias, String realm, String idpEntityId, EndpointType logoutEndpoint, NameID nameId, String sessionIndex) throws SAML2Exception, SessionException {
    // generate unique request ID
    final String requestID = SAML2Utils.generateID();
    if ((requestID == null) || (requestID.length() == 0)) {
        DEBUG.warning("SAML2 PAP :: Unable to perform single logout, unable to generate request ID - {}", SAML2Utils.bundle.getString("cannotGenerateID"));
        throw new SAML2Exception(SAML2Utils.BUNDLE_NAME, "cannotGenerateID", new Object[0]);
    }
    final String spEntityID = META_MANAGER.getEntityByMetaAlias(metaAlias);
    final Issuer issuer = SAML2Utils.createIssuer(spEntityID);
    final LogoutRequest logoutReq = ProtocolFactory.getInstance().createLogoutRequest();
    logoutReq.setID(requestID);
    logoutReq.setVersion(SAML2Constants.VERSION_2_0);
    logoutReq.setIssueInstant(new Date());
    logoutReq.setIssuer(issuer);
    if (sessionIndex != null) {
        logoutReq.setSessionIndex(Collections.singletonList(sessionIndex));
    }
    String location = logoutEndpoint.getLocation();
    logoutReq.setDestination(XMLUtils.escapeSpecialCharacters(location));
    LogoutUtil.setNameIDForSLORequest(logoutReq, nameId, realm, spEntityID, SAML2Constants.SP_ROLE, idpEntityId);
    return logoutReq;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) Issuer(com.sun.identity.saml2.assertion.Issuer) LogoutRequest(com.sun.identity.saml2.protocol.LogoutRequest) Date(java.util.Date)

Aggregations

SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)23 List (java.util.List)14 SessionException (com.sun.identity.plugin.session.SessionException)13 Iterator (java.util.Iterator)10 SAML2TokenRepositoryException (org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)10 ArrayList (java.util.ArrayList)9 NameID (com.sun.identity.saml2.assertion.NameID)8 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)7 SessionProvider (com.sun.identity.plugin.session.SessionProvider)6 Date (java.util.Date)6 Issuer (com.sun.identity.saml2.assertion.Issuer)5 BaseConfigType (com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType)5 LogoutRequest (com.sun.identity.saml2.protocol.LogoutRequest)5 HashMap (java.util.HashMap)5 Assertion (com.sun.identity.saml2.assertion.Assertion)4 AuthnStatement (com.sun.identity.saml2.assertion.AuthnStatement)4 SPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.SPSSOConfigElement)4 IDPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.IDPSSODescriptorElement)4 IDPSession (com.sun.identity.saml2.profile.IDPSession)4 Response (com.sun.identity.saml2.protocol.Response)4