Search in sources :

Example 1 with SessionUpdateTask

use of org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask in project keycloak by keycloak.

the class InfinispanUserSessionProvider method importClientSession.

private AuthenticatedClientSessionAdapter importClientSession(UserSessionAdapter sessionToImportInto, AuthenticatedClientSessionModel clientSession, InfinispanChangelogBasedTransaction<String, UserSessionEntity> userSessionUpdateTx, InfinispanChangelogBasedTransaction<UUID, AuthenticatedClientSessionEntity> clientSessionUpdateTx, boolean offline) {
    AuthenticatedClientSessionEntity entity = createAuthenticatedClientSessionInstance(clientSession, sessionToImportInto.getRealm().getId(), offline);
    final UUID clientSessionId = entity.getId();
    SessionUpdateTask<AuthenticatedClientSessionEntity> createClientSessionTask = Tasks.addIfAbsentSync();
    clientSessionUpdateTx.addTask(entity.getId(), createClientSessionTask, entity, UserSessionModel.SessionPersistenceState.PERSISTENT);
    AuthenticatedClientSessionStore clientSessions = sessionToImportInto.getEntity().getAuthenticatedClientSessions();
    clientSessions.put(clientSession.getClient().getId(), clientSessionId);
    SessionUpdateTask registerClientSessionTask = new RegisterClientSessionTask(clientSession.getClient().getId(), clientSessionId);
    userSessionUpdateTx.addTask(sessionToImportInto.getId(), registerClientSessionTask);
    return new AuthenticatedClientSessionAdapter(session, this, entity, clientSession.getClient(), sessionToImportInto, clientSessionUpdateTx, offline);
}
Also used : AuthenticatedClientSessionEntity(org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionEntity) UUID(java.util.UUID) SessionUpdateTask(org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask) AuthenticatedClientSessionStore(org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionStore)

Example 2 with SessionUpdateTask

use of org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask in project keycloak by keycloak.

the class InfinispanUserSessionProvider method createClientSession.

@Override
public AuthenticatedClientSessionModel createClientSession(RealmModel realm, ClientModel client, UserSessionModel userSession) {
    final UUID clientSessionId = keyGenerator.generateKeyUUID(session, clientSessionCache);
    AuthenticatedClientSessionEntity entity = new AuthenticatedClientSessionEntity(clientSessionId);
    entity.setRealmId(realm.getId());
    entity.setTimestamp(Time.currentTime());
    entity.getNotes().put(AuthenticatedClientSessionModel.STARTED_AT_NOTE, String.valueOf(entity.getTimestamp()));
    InfinispanChangelogBasedTransaction<String, UserSessionEntity> userSessionUpdateTx = getTransaction(false);
    InfinispanChangelogBasedTransaction<UUID, AuthenticatedClientSessionEntity> clientSessionUpdateTx = getClientSessionTransaction(false);
    AuthenticatedClientSessionAdapter adapter = new AuthenticatedClientSessionAdapter(session, this, entity, client, userSession, clientSessionUpdateTx, false);
    // For now, the clientSession is considered transient in case that userSession was transient
    UserSessionModel.SessionPersistenceState persistenceState = (userSession instanceof UserSessionAdapter && ((UserSessionAdapter) userSession).getPersistenceState() != null) ? ((UserSessionAdapter) userSession).getPersistenceState() : UserSessionModel.SessionPersistenceState.PERSISTENT;
    SessionUpdateTask<AuthenticatedClientSessionEntity> createClientSessionTask = Tasks.addIfAbsentSync();
    clientSessionUpdateTx.addTask(clientSessionId, createClientSessionTask, entity, persistenceState);
    SessionUpdateTask registerClientSessionTask = new RegisterClientSessionTask(client.getId(), clientSessionId);
    userSessionUpdateTx.addTask(userSession.getId(), registerClientSessionTask);
    return adapter;
}
Also used : OfflineUserSessionModel(org.keycloak.models.OfflineUserSessionModel) UserSessionModel(org.keycloak.models.UserSessionModel) SessionUpdateTask(org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask) AuthenticatedClientSessionEntity(org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionEntity) UUID(java.util.UUID) UserSessionEntity(org.keycloak.models.sessions.infinispan.entities.UserSessionEntity)

Aggregations

UUID (java.util.UUID)2 SessionUpdateTask (org.keycloak.models.sessions.infinispan.changes.SessionUpdateTask)2 AuthenticatedClientSessionEntity (org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionEntity)2 OfflineUserSessionModel (org.keycloak.models.OfflineUserSessionModel)1 UserSessionModel (org.keycloak.models.UserSessionModel)1 AuthenticatedClientSessionStore (org.keycloak.models.sessions.infinispan.entities.AuthenticatedClientSessionStore)1 UserSessionEntity (org.keycloak.models.sessions.infinispan.entities.UserSessionEntity)1