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;
}
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.");
}
Aggregations