Search in sources :

Example 1 with SPAuthnContextMapper

use of com.sun.identity.saml2.plugins.SPAuthnContextMapper in project OpenAM by OpenRock.

the class SPSSOFederate method createReqAuthnContext.

/* Creates RequestedAuthnContext Object */
private static RequestedAuthnContext createReqAuthnContext(String realmName, String spEntityID, Map paramsMap, Map spConfigMap) {
    RequestedAuthnContext reqCtx = null;
    String className = null;
    if ((spConfigMap != null) && (!spConfigMap.isEmpty())) {
        List listVal = (List) spConfigMap.get(SAML2Constants.SP_AUTHCONTEXT_MAPPER);
        if (listVal != null && listVal.size() != 0) {
            className = ((String) listVal.iterator().next()).trim();
        }
    }
    SPAuthnContextMapper spAuthnContextMapper = SAML2Utils.getSPAuthnContextMapper(realmName, spEntityID, className);
    try {
        reqCtx = spAuthnContextMapper.getRequestedAuthnContext(realmName, spEntityID, paramsMap);
    } catch (SAML2Exception e) {
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("SPSSOFederate:Error creating " + "RequestedAuthnContext", e);
        }
    }
    return reqCtx;
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) RequestedAuthnContext(com.sun.identity.saml2.protocol.RequestedAuthnContext) List(java.util.List) IDPList(com.sun.identity.saml2.protocol.IDPList) ArrayList(java.util.ArrayList) SPAuthnContextMapper(com.sun.identity.saml2.plugins.SPAuthnContextMapper)

Example 2 with SPAuthnContextMapper

use of com.sun.identity.saml2.plugins.SPAuthnContextMapper in project OpenAM by OpenRock.

the class SAML2Utils method fillMap.

private static Map fillMap(final List authnStmts, final Subject subject, final Assertion assertion, final List assertions, final AuthnRequestInfo reqInfo, final String inRespToResp, final String orgName, final String hostEntityId, final String idpEntityId, final SPSSOConfigElement spConfig, final Date notOnOrAfterTime) throws SAML2Exception {
    // use the first AuthnStmt
    AuthnStatement authnStmt = (AuthnStatement) authnStmts.get(0);
    int authLevel = -1;
    String mapperClass = getAttributeValueFromSPSSOConfig(spConfig, SAML2Constants.SP_AUTHCONTEXT_MAPPER);
    SPAuthnContextMapper mapper = getSPAuthnContextMapper(orgName, hostEntityId, mapperClass);
    RequestedAuthnContext reqContext = null;
    AuthnRequest authnRequest = null;
    if (reqInfo != null) {
        reqContext = (reqInfo.getAuthnRequest()).getRequestedAuthnContext();
        authnRequest = reqInfo.getAuthnRequest();
    }
    authLevel = mapper.getAuthLevel(reqContext, authnStmt.getAuthnContext(), orgName, hostEntityId, idpEntityId);
    String sessionIndex = authnStmt.getSessionIndex();
    Date sessionNotOnOrAfter = authnStmt.getSessionNotOnOrAfter();
    Map smap = new HashMap();
    smap.put(SAML2Constants.SUBJECT, subject);
    smap.put(SAML2Constants.POST_ASSERTION, assertion);
    smap.put(SAML2Constants.ASSERTIONS, assertions);
    if (authnRequest != null) {
        smap.put(SAML2Constants.AUTHN_REQUEST, authnRequest);
    }
    String[] data = { assertion.getID(), "", "" };
    if (LogUtil.isAccessLoggable(Level.FINE)) {
        data[1] = subject.toXMLString();
    }
    if (sessionIndex != null && sessionIndex.length() != 0) {
        data[2] = sessionIndex;
        smap.put(SAML2Constants.SESSION_INDEX, sessionIndex);
    }
    if (authLevel >= 0) {
        smap.put(SAML2Constants.AUTH_LEVEL, new Integer(authLevel));
    }
    // SessionNotOnOrAfter
    if (sessionNotOnOrAfter != null) {
        long maxSessionTime = (sessionNotOnOrAfter.getTime() - System.currentTimeMillis()) / 60000;
        if (maxSessionTime > 0) {
            smap.put(SAML2Constants.MAX_SESSION_TIME, new Long(maxSessionTime));
        }
    }
    if (inRespToResp != null && inRespToResp.length() != 0) {
        smap.put(SAML2Constants.IN_RESPONSE_TO, inRespToResp);
    }
    if (debug.messageEnabled()) {
        debug.message("SAML2Utils.fillMap: Found valid authentication " + "assertion.");
    }
    if (notOnOrAfterTime != null) {
        smap.put(SAML2Constants.NOTONORAFTER, new Long(notOnOrAfterTime.getTime()));
    }
    LogUtil.access(Level.INFO, LogUtil.FOUND_AUTHN_ASSERTION, data, null);
    return smap;
}
Also used : HashMap(java.util.HashMap) Date(java.util.Date) RequestedAuthnContext(com.sun.identity.saml2.protocol.RequestedAuthnContext) AuthnRequest(com.sun.identity.saml2.protocol.AuthnRequest) AuthnStatement(com.sun.identity.saml2.assertion.AuthnStatement) SPAuthnContextMapper(com.sun.identity.saml2.plugins.SPAuthnContextMapper) DefaultSPAuthnContextMapper(com.sun.identity.saml2.plugins.DefaultSPAuthnContextMapper) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with SPAuthnContextMapper

use of com.sun.identity.saml2.plugins.SPAuthnContextMapper in project OpenAM by OpenRock.

the class SAML2Utils method getSPAuthnContextMapper.

/**
     * Returns the Service Provider AuthnContext Mapper Object.
     *
     * @param authnCtxClassName Service Provider AuthnContext Mapper Class Name.
     * @return SPAuthnContextMapper Object.
     */
public static SPAuthnContextMapper getSPAuthnContextMapper(String realm, String hostEntityID, String authnCtxClassName) {
    SPAuthnContextMapper spAuthnCtx = (SPAuthnContextMapper) SPCache.authCtxObjHash.get(hostEntityID + "|" + realm);
    if (debug.messageEnabled()) {
        debug.message("AuthContext Class Name is :" + authnCtxClassName);
    }
    if ((spAuthnCtx == null) && ((authnCtxClassName != null) && (authnCtxClassName.length() != 0))) {
        try {
            spAuthnCtx = (SPAuthnContextMapper) Class.forName(authnCtxClassName).newInstance();
            SPCache.authCtxObjHash.put(hostEntityID + "|" + realm, spAuthnCtx);
        } catch (ClassNotFoundException ce) {
            if (debug.messageEnabled()) {
                debug.message("SAML2Utils: Mapper not configured" + " using Default AuthnContext Mapper");
            }
        } catch (InstantiationException ie) {
            if (debug.messageEnabled()) {
                debug.message("SAML2Utils: Instantiation ");
                debug.message("SAML2Utils:Error instantiating : " + " using Default AuthnContext Mapper");
            }
        } catch (IllegalAccessException iae) {
            if (debug.messageEnabled()) {
                debug.message("SAML2Utils: illegalaccess");
                debug.message("SAML2Utils:Error : " + " using Default AuthnContext Mapper");
            }
        } catch (Exception e) {
            if (debug.messageEnabled()) {
                debug.message("SAML2Utils:Error : " + " using Default AuthnContext Mapper");
            }
        }
    }
    if (spAuthnCtx == null) {
        spAuthnCtx = new DefaultSPAuthnContextMapper();
        SPCache.authCtxObjHash.put(hostEntityID + "|" + realm, spAuthnCtx);
    }
    return spAuthnCtx;
}
Also used : DefaultSPAuthnContextMapper(com.sun.identity.saml2.plugins.DefaultSPAuthnContextMapper) SPAuthnContextMapper(com.sun.identity.saml2.plugins.SPAuthnContextMapper) DefaultSPAuthnContextMapper(com.sun.identity.saml2.plugins.DefaultSPAuthnContextMapper) SystemConfigurationException(com.sun.identity.common.SystemConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) IOException(java.io.IOException) ServletException(javax.servlet.ServletException) SessionException(com.sun.identity.plugin.session.SessionException) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) COTException(com.sun.identity.cot.COTException) SAML2TokenRepositoryException(org.forgerock.openam.federation.saml2.SAML2TokenRepositoryException)

Aggregations

SPAuthnContextMapper (com.sun.identity.saml2.plugins.SPAuthnContextMapper)3 DefaultSPAuthnContextMapper (com.sun.identity.saml2.plugins.DefaultSPAuthnContextMapper)2 RequestedAuthnContext (com.sun.identity.saml2.protocol.RequestedAuthnContext)2 SystemConfigurationException (com.sun.identity.common.SystemConfigurationException)1 COTException (com.sun.identity.cot.COTException)1 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)1 SessionException (com.sun.identity.plugin.session.SessionException)1 AuthnStatement (com.sun.identity.saml2.assertion.AuthnStatement)1 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)1 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)1 AuthnRequest (com.sun.identity.saml2.protocol.AuthnRequest)1 IDPList (com.sun.identity.saml2.protocol.IDPList)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1