Search in sources :

Example 1 with PersistentClientSessionModel

use of org.keycloak.models.session.PersistentClientSessionModel 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 PersistentClientSessionModel

use of org.keycloak.models.session.PersistentClientSessionModel 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)2 PersistentClientSessionModel (org.keycloak.models.session.PersistentClientSessionModel)2 ClientModel (org.keycloak.models.ClientModel)1 StorageId (org.keycloak.storage.StorageId)1