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