use of org.wso2.carbon.identity.application.authentication.framework.context.SessionContext in project carbon-identity-framework by wso2.
the class ServerSessionManagementServiceImpl method terminateSession.
/**
* Terminate the session by sessionId
*
* @param sessionContext - session context for the sessionId
* @param sessionId - Session id of the federated user
*/
private void terminateSession(SessionContext sessionContext, String sessionId) {
if (FrameworkServiceDataHolder.getInstance().getAuthnDataPublisherProxy() != null && FrameworkServiceDataHolder.getInstance().getAuthnDataPublisherProxy().isEnabled(null) && sessionContext != null) {
Object authenticatedUserObj = sessionContext.getProperty(FrameworkConstants.AUTHENTICATED_USER);
AuthenticatedUser authenticatedUser = new AuthenticatedUser();
if (authenticatedUserObj != null) {
authenticatedUser = (AuthenticatedUser) authenticatedUserObj;
}
FrameworkUtils.publishSessionEvent(sessionId, null, null, sessionContext, authenticatedUser, FrameworkConstants.AnalyticsAttributes.SESSION_TERMINATE);
}
if (sessionContext == null) {
if (log.isDebugEnabled()) {
log.debug("The session context is not available for " + sessionId);
}
return;
}
Object tenantDomainObj = sessionContext.getProperty(FrameworkUtils.TENANT_DOMAIN);
if (tenantDomainObj != null) {
SessionContextCache.getInstance().clearCacheEntry(sessionId, (String) tenantDomainObj);
} else {
SessionContextCache.getInstance().clearCacheEntry(sessionId);
}
}
use of org.wso2.carbon.identity.application.authentication.framework.context.SessionContext in project carbon-identity-framework by wso2.
the class ServerSessionManagementServiceImpl method removeSession.
@Override
public boolean removeSession(String sessionId) {
if (StringUtils.isBlank(sessionId)) {
return false;
}
// Retrieve session information from cache in order to publish event
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionId, FrameworkUtils.getLoginTenantDomainFromContext());
terminateSession(sessionContext, sessionId);
return true;
}
use of org.wso2.carbon.identity.application.authentication.framework.context.SessionContext in project carbon-identity-framework by wso2.
the class UserSessionManagementServiceImpl method getActiveSessionList.
/**
* Returns the active sessions from given list of session IDs.
*
* @param sessionIdList list of sessionIds
* @return list of user sessions
* @throws SessionManagementServerException if an error occurs when retrieving the UserSessions.
*/
private List<UserSession> getActiveSessionList(List<String> sessionIdList) throws SessionManagementServerException {
List<UserSession> sessionsList = new ArrayList<>();
for (String sessionId : sessionIdList) {
if (sessionId != null) {
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionId, FrameworkUtils.getLoginTenantDomainFromContext());
if (sessionContext != null) {
UserSessionDAO userSessionDTO = new UserSessionDAOImpl();
UserSession userSession = userSessionDTO.getSession(sessionId);
if (userSession != null) {
sessionsList.add(userSession);
}
}
}
}
return sessionsList;
}
use of org.wso2.carbon.identity.application.authentication.framework.context.SessionContext in project carbon-identity-framework by wso2.
the class FrameworkUtilsTest method testGetSessionContextFromCacheExpiredSession.
@Test
public void testGetSessionContextFromCacheExpiredSession() throws FrameworkException {
cacheEntry.setContext(context);
setMockedSessionContextCache();
when(mockedSessionContextCache.getValueFromCache(cacheKey)).thenReturn(cacheEntry);
when(mockedSessionContextCache.isSessionExpired(any(SessionContextCacheKey.class), any(SessionContextCacheEntry.class))).thenReturn(true);
IdentityEventService identityEventService = new IdentityEventServiceImpl(Collections.EMPTY_LIST, 1);
FrameworkServiceDataHolder.getInstance().setIdentityEventService(identityEventService);
AuthenticationContext authenticationContext = new AuthenticationContext();
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(request, authenticationContext, DUMMY_CACHE_KEY);
assertNull(sessionContext);
}
use of org.wso2.carbon.identity.application.authentication.framework.context.SessionContext in project carbon-identity-framework by wso2.
the class FrameworkUtilsTest method testGetSessionContextFromCacheValidCacheEntry.
@Test
public void testGetSessionContextFromCacheValidCacheEntry() {
cacheEntry.setContext(context);
setMockedSessionContextCache();
when(mockedSessionContextCache.getValueFromCache(cacheKey, "abc")).thenReturn(cacheEntry);
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(DUMMY_CACHE_KEY, "abc");
assertEquals(sessionContext, context);
}
Aggregations