Search in sources :

Example 1 with PersistentAuthenticatedClientSessionAdapter

use of org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter in project keycloak by keycloak.

the class JpaUserSessionPersisterProvider method createClientSession.

@Override
public void createClientSession(AuthenticatedClientSessionModel clientSession, boolean offline) {
    PersistentAuthenticatedClientSessionAdapter adapter = new PersistentAuthenticatedClientSessionAdapter(session, clientSession);
    PersistentClientSessionModel model = adapter.getUpdatedModel();
    PersistentClientSessionEntity entity = new PersistentClientSessionEntity();
    StorageId clientStorageId = new StorageId(clientSession.getClient().getId());
    if (clientStorageId.isLocal()) {
        entity.setClientId(clientStorageId.getId());
        entity.setClientStorageProvider(PersistentClientSessionEntity.LOCAL);
        entity.setExternalClientId(PersistentClientSessionEntity.LOCAL);
    } else {
        entity.setClientId(PersistentClientSessionEntity.EXTERNAL);
        entity.setClientStorageProvider(clientStorageId.getProviderId());
        entity.setExternalClientId(clientStorageId.getExternalId());
    }
    entity.setTimestamp(clientSession.getTimestamp());
    String offlineStr = offlineToString(offline);
    entity.setOffline(offlineStr);
    entity.setUserSessionId(clientSession.getUserSession().getId());
    entity.setData(model.getData());
    em.persist(entity);
    em.flush();
}
Also used : PersistentAuthenticatedClientSessionAdapter(org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter) PersistentClientSessionModel(org.keycloak.models.session.PersistentClientSessionModel) StorageId(org.keycloak.storage.StorageId)

Example 2 with PersistentAuthenticatedClientSessionAdapter

use of org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter in project keycloak by keycloak.

the class JpaUserSessionPersisterProvider method addClientSessionToAuthenticatedClientSessionsIfPresent.

private boolean addClientSessionToAuthenticatedClientSessionsIfPresent(PersistentUserSessionAdapter userSession, PersistentClientSessionEntity clientSessionEntity) {
    PersistentAuthenticatedClientSessionAdapter clientSessAdapter = toAdapter(userSession.getRealm(), userSession, clientSessionEntity);
    if (clientSessAdapter.getClient() == null) {
        return false;
    }
    String clientId = clientSessionEntity.getClientId();
    if (isExternalClient(clientSessionEntity)) {
        clientId = getExternalClientId(clientSessionEntity);
    }
    userSession.getAuthenticatedClientSessions().put(clientId, clientSessAdapter);
    return true;
}
Also used : PersistentAuthenticatedClientSessionAdapter(org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter)

Example 3 with PersistentAuthenticatedClientSessionAdapter

use of org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter in project keycloak by keycloak.

the class JpaUserSessionPersisterProvider method toAdapter.

private PersistentAuthenticatedClientSessionAdapter toAdapter(RealmModel realm, PersistentUserSessionAdapter userSession, PersistentClientSessionEntity entity) {
    String clientId = entity.getClientId();
    if (isExternalClient(entity)) {
        clientId = getExternalClientId(entity);
    }
    ClientModel client = realm.getClientById(clientId);
    PersistentClientSessionModel model = new PersistentClientSessionModel();
    model.setClientId(clientId);
    model.setUserSessionId(userSession.getId());
    model.setUserId(userSession.getUserId());
    model.setTimestamp(entity.getTimestamp());
    model.setData(entity.getData());
    return new PersistentAuthenticatedClientSessionAdapter(session, model, realm, client, userSession);
}
Also used : ClientModel(org.keycloak.models.ClientModel) PersistentAuthenticatedClientSessionAdapter(org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter) PersistentClientSessionModel(org.keycloak.models.session.PersistentClientSessionModel)

Aggregations

PersistentAuthenticatedClientSessionAdapter (org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter)3 PersistentClientSessionModel (org.keycloak.models.session.PersistentClientSessionModel)2 ClientModel (org.keycloak.models.ClientModel)1 StorageId (org.keycloak.storage.StorageId)1