Search in sources :

Example 1 with SessionContextCache

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCache 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 2 with SessionContextCache

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

the class SessionExtenderProcessorTest method testProcessWithSessionKey.

@Test(expectedExceptions = NullPointerException.class)
public void testProcessWithSessionKey() throws Exception {
    mockStatic(SessionContextCache.class);
    SessionExtenderRequest sessionExtenderRequest = mock(SessionExtenderRequest.class);
    SessionContextCache sessionContextCache = mock(SessionContextCache.class);
    SessionContextCacheKey sessionContextCacheKey = mock(SessionContextCacheKey.class);
    SessionContextCacheEntry sessionContextCacheEntry = mock(SessionContextCacheEntry.class);
    SessionContext sessionContext = mock(SessionContext.class);
    whenNew(SessionContextCacheKey.class).withArguments(anyString()).thenReturn(sessionContextCacheKey);
    when(sessionExtenderRequest.getTenantDomain()).thenReturn(TENANT_DOMAIN);
    when(sessionExtenderRequest.getSessionKey()).thenReturn(IDP_SESSION_KEY);
    when(SessionContextCache.getInstance()).thenReturn(sessionContextCache);
    when(sessionContextCache.getSessionContextCacheEntry(anyObject(), anyString())).thenReturn(sessionContextCacheEntry);
    when(sessionContextCacheEntry.getContext()).thenReturn(sessionContext);
    SessionExtenderResponse.SessionExtenderResponseBuilder responseBuilder = (SessionExtenderResponse.SessionExtenderResponseBuilder) sessionExtenderProcessor.process(sessionExtenderRequest);
    SessionExtenderResponse response = responseBuilder.build();
    assertNotNull(response.getTraceId(), "Error creating successful response.");
}
Also used : SessionExtenderResponse(org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponse) 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) SessionExtenderRequest(org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequest) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SessionContextCache (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCache)2 SessionContextCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry)2 SessionContextCacheKey (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey)2 SessionContext (org.wso2.carbon.identity.application.authentication.framework.context.SessionContext)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 SessionExtenderRequest (org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequest)1 SessionExtenderResponse (org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponse)1