Search in sources :

Example 1 with OfflineUserSessionModel

use of org.keycloak.models.OfflineUserSessionModel in project keycloak by keycloak.

the class InfinispanUserSessionProvider method createUserSessionEntityInstance.

private UserSessionEntity createUserSessionEntityInstance(UserSessionModel userSession) {
    UserSessionEntity entity = new UserSessionEntity();
    entity.setId(userSession.getId());
    entity.setRealmId(userSession.getRealm().getId());
    entity.setAuthMethod(userSession.getAuthMethod());
    entity.setBrokerSessionId(userSession.getBrokerSessionId());
    entity.setBrokerUserId(userSession.getBrokerUserId());
    entity.setIpAddress(userSession.getIpAddress());
    entity.setNotes(userSession.getNotes() == null ? new ConcurrentHashMap<>() : userSession.getNotes());
    entity.setAuthenticatedClientSessions(new AuthenticatedClientSessionStore());
    entity.setRememberMe(userSession.isRememberMe());
    entity.setState(userSession.getState());
    if (userSession instanceof OfflineUserSessionModel) {
        // this is a hack so that UserModel doesn't have to be available when offline token is imported.
        // see related JIRA - KEYCLOAK-5350 and corresponding test
        OfflineUserSessionModel oline = (OfflineUserSessionModel) userSession;
        entity.setUser(oline.getUserId());
    // NOTE: Hack
    // We skip calling entity.setLoginUsername(userSession.getLoginUsername())
    } else {
        entity.setLoginUsername(userSession.getLoginUsername());
        entity.setUser(userSession.getUser().getId());
    }
    entity.setStarted(userSession.getStarted());
    entity.setLastSessionRefresh(userSession.getLastSessionRefresh());
    return entity;
}
Also used : OfflineUserSessionModel(org.keycloak.models.OfflineUserSessionModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AuthenticatedClientSessionStore(org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionStore) UserSessionEntity(org.keycloak.models.sessions.infinispan.entities.UserSessionEntity)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 OfflineUserSessionModel (org.keycloak.models.OfflineUserSessionModel)1 AuthenticatedClientSessionStore (org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionStore)1 UserSessionEntity (org.keycloak.models.sessions.infinispan.entities.UserSessionEntity)1