Search in sources :

Example 1 with SessionContextCacheKey

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey in project carbon-identity-framework by wso2.

the class FrameworkUtils method removeSessionContextFromCache.

/**
 * @param key
 * @param loginTenantDomain
 */
public static void removeSessionContextFromCache(String key, String loginTenantDomain) {
    if (key != null) {
        SessionContextCacheKey cacheKey = new SessionContextCacheKey(key);
        SessionContextCache.getInstance().clearCacheEntry(cacheKey, loginTenantDomain);
    }
}
Also used : SessionContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey)

Example 2 with SessionContextCacheKey

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey in project carbon-identity-framework by wso2.

the class FrameworkUtils method addSessionContextToCache.

/**
 * @deprecated Use the {@link #addSessionContextToCache(String, SessionContext, String)}
 *
 * @param key
 * @param sessionContext
 */
@Deprecated
public static void addSessionContextToCache(String key, SessionContext sessionContext) {
    SessionContextCacheKey cacheKey = new SessionContextCacheKey(key);
    SessionContextCacheEntry cacheEntry = new SessionContextCacheEntry();
    Map<String, SequenceConfig> seqData = sessionContext.getAuthenticatedSequences();
    if (seqData != null) {
        for (Entry<String, SequenceConfig> entry : seqData.entrySet()) {
            if (entry.getValue() != null) {
                entry.getValue().getAuthenticatedUser().setUserAttributes(null);
                entry.getValue().setAuthenticationGraph(null);
            }
        }
    }
    Object authenticatedUserObj = sessionContext.getProperty(FrameworkConstants.AUTHENTICATED_USER);
    if (authenticatedUserObj instanceof AuthenticatedUser) {
        AuthenticatedUser authenticatedUser = (AuthenticatedUser) authenticatedUserObj;
        cacheEntry.setLoggedInUser(authenticatedUser.getAuthenticatedSubjectIdentifier());
    }
    cacheEntry.setContext(sessionContext);
    SessionContextCache.getInstance().addToCache(cacheKey, cacheEntry);
}
Also used : SessionContextCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry) SessionContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) JSONObject(org.json.JSONObject) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 3 with SessionContextCacheKey

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey in project carbon-identity-framework by wso2.

the class FrameworkUtils method getSessionContextFromCache.

/**
 * Retrieve session context from the session cache.
 *
 * @param request           HttpServletRequest.
 * @param context           Authentication context.
 * @param sessionContextKey Session context key.
 * @return Session context key.
 * @throws FrameworkException Error in triggering session expire event.
 */
public static SessionContext getSessionContextFromCache(HttpServletRequest request, AuthenticationContext context, String sessionContextKey) throws FrameworkException {
    SessionContext sessionContext = null;
    if (StringUtils.isNotBlank(sessionContextKey)) {
        SessionContextCacheKey cacheKey = new SessionContextCacheKey(sessionContextKey);
        SessionContextCache sessionContextCache = SessionContextCache.getInstance();
        SessionContextCacheEntry cacheEntry = sessionContextCache.getSessionContextCacheEntry(cacheKey, context.getLoginTenantDomain());
        if (cacheEntry != null) {
            sessionContext = cacheEntry.getContext();
            boolean isSessionExpired = sessionContextCache.isSessionExpired(cacheKey, cacheEntry);
            if (isSessionExpired) {
                triggerSessionExpireEvent(request, context, sessionContext);
                if (log.isDebugEnabled()) {
                    log.debug("A SESSION_EXPIRE event was fired for the expired session found corresponding " + "to the key: " + cacheKey.getContextId());
                }
                return null;
            }
        }
    }
    return sessionContext;
}
Also used : SessionContextCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry) SessionContext(org.wso2.carbon.identity.application.authentication.framework.context.SessionContext) SessionContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey) SessionContextCache(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCache)

Example 4 with SessionContextCacheKey

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey in project carbon-identity-framework by wso2.

the class FrameworkUtils method getSessionContextFromCache.

/**
 * @param key
 * @param loginTenantDomain
 * @return
 */
public static SessionContext getSessionContextFromCache(String key, String loginTenantDomain) {
    SessionContext sessionContext = null;
    if (StringUtils.isNotBlank(key)) {
        SessionContextCacheKey cacheKey = new SessionContextCacheKey(key);
        Object cacheEntryObj = SessionContextCache.getInstance().getValueFromCache(cacheKey, loginTenantDomain);
        if (cacheEntryObj != null) {
            sessionContext = ((SessionContextCacheEntry) cacheEntryObj).getContext();
        }
    }
    return sessionContext;
}
Also used : SessionContext(org.wso2.carbon.identity.application.authentication.framework.context.SessionContext) SessionContextCacheKey(org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey) JSONObject(org.json.JSONObject)

Example 5 with SessionContextCacheKey

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey in project carbon-identity-framework by wso2.

the class SessionContextCache method getSessionFromDB.

/**
 * Retrieve session from the database.
 *
 * @param key Session context cache key.
 * @return Session context cache entry.
 */
private SessionContextCacheEntry getSessionFromDB(SessionContextCacheKey key) {
    SessionContextCacheEntry cacheEntry = null;
    SessionContextDO sessionContextDO = SessionDataStore.getInstance().getSessionContextData(key.getContextId(), SESSION_CONTEXT_CACHE_NAME);
    if (sessionContextDO != null) {
        cacheEntry = new SessionContextCacheEntry(sessionContextDO);
    }
    return cacheEntry;
}
Also used : SessionContextDO(org.wso2.carbon.identity.application.authentication.framework.store.SessionContextDO)

Aggregations

SessionContextCacheKey (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey)6 SessionContextCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry)4 SessionContext (org.wso2.carbon.identity.application.authentication.framework.context.SessionContext)4 JSONObject (org.json.JSONObject)2 SessionContextCache (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCache)2 SessionExtenderRequest (org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequest)2 SessionExtenderResponse (org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponse)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 SessionExtenderClientException (org.wso2.carbon.identity.application.authentication.framework.session.extender.exception.SessionExtenderClientException)1 SessionContextDO (org.wso2.carbon.identity.application.authentication.framework.store.SessionContextDO)1