Search in sources :

Example 1 with SessionContextCacheEntry

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

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

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

use of org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheEntry 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)

Example 5 with SessionContextCacheEntry

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

the class SessionExtenderProcessor method process.

@Override
public IdentityResponse.IdentityResponseBuilder process(IdentityRequest identityRequest) throws SessionExtenderClientException {
    if (log.isDebugEnabled()) {
        log.debug("Request processing started by SessionExtenderProcessor.");
    }
    SessionExtenderRequest sessionExtenderRequest = (SessionExtenderRequest) identityRequest;
    String tenantDomain = sessionExtenderRequest.getTenantDomain();
    String sessionKey = getSessionKey(sessionExtenderRequest);
    SessionContextCacheKey sessionContextCacheKey = new SessionContextCacheKey(sessionKey);
    SessionContextCacheEntry sessionContextCacheEntry = SessionContextCache.getInstance().getSessionContextCacheEntry(sessionContextCacheKey, tenantDomain);
    if (sessionContextCacheEntry == null) {
        if (log.isDebugEnabled()) {
            log.debug("No session available for requested session identifier: " + sessionKey);
        }
        throw new SessionExtenderClientException(SessionExtenderConstants.Error.SESSION_NOT_AVAILABLE.getCode(), SessionExtenderConstants.Error.SESSION_NOT_AVAILABLE.getMessage(), "No session available for requested session identifier.");
    }
    SessionContext sessionContext = sessionContextCacheEntry.getContext();
    long currentTime = System.currentTimeMillis();
    FrameworkUtils.updateSessionLastAccessTimeMetadata(sessionKey, currentTime);
    FrameworkUtils.addSessionContextToCache(sessionKey, sessionContext, tenantDomain, tenantDomain);
    String traceId = FrameworkUtils.getCorrelation();
    fireEvent(sessionKey, sessionContext, tenantDomain, traceId);
    addAuditLogs(sessionKey, tenantDomain, traceId);
    SessionExtenderResponse.SessionExtenderResponseBuilder responseBuilder = new SessionExtenderResponse.SessionExtenderResponseBuilder();
    responseBuilder.setTraceId(traceId);
    return responseBuilder;
}
Also used : SessionExtenderResponse(org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponse) SessionExtenderClientException(org.wso2.carbon.identity.application.authentication.framework.session.extender.exception.SessionExtenderClientException) 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) SessionExtenderRequest(org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequest)

Aggregations

SessionContextCacheKey (org.wso2.carbon.identity.application.authentication.framework.cache.SessionContextCacheKey)5 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