Search in sources :

Example 1 with PersistentUserSessionModel

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

the class JpaUserSessionPersisterProvider method createUserSession.

@Override
public void createUserSession(UserSessionModel userSession, boolean offline) {
    PersistentUserSessionAdapter adapter = new PersistentUserSessionAdapter(userSession);
    PersistentUserSessionModel model = adapter.getUpdatedModel();
    PersistentUserSessionEntity entity = new PersistentUserSessionEntity();
    entity.setUserSessionId(model.getUserSessionId());
    entity.setCreatedOn(model.getStarted());
    entity.setRealmId(adapter.getRealm().getId());
    entity.setUserId(adapter.getUser().getId());
    String offlineStr = offlineToString(offline);
    entity.setOffline(offlineStr);
    entity.setLastSessionRefresh(model.getLastSessionRefresh());
    entity.setData(model.getData());
    em.persist(entity);
    em.flush();
}
Also used : PersistentUserSessionAdapter(org.keycloak.models.session.PersistentUserSessionAdapter) PersistentUserSessionModel(org.keycloak.models.session.PersistentUserSessionModel)

Example 2 with PersistentUserSessionModel

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

the class JpaUserSessionPersisterProvider method toAdapter.

private PersistentUserSessionAdapter toAdapter(RealmModel realm, PersistentUserSessionEntity entity) {
    PersistentUserSessionModel model = new PersistentUserSessionModel();
    model.setUserSessionId(entity.getUserSessionId());
    model.setStarted(entity.getCreatedOn());
    model.setLastSessionRefresh(entity.getLastSessionRefresh());
    model.setData(entity.getData());
    model.setOffline(offlineFromString(entity.getOffline()));
    Map<String, AuthenticatedClientSessionModel> clientSessions = new HashMap<>();
    return new PersistentUserSessionAdapter(session, model, realm, entity.getUserId(), clientSessions);
}
Also used : PersistentUserSessionAdapter(org.keycloak.models.session.PersistentUserSessionAdapter) HashMap(java.util.HashMap) PersistentUserSessionModel(org.keycloak.models.session.PersistentUserSessionModel) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel)

Aggregations

PersistentUserSessionAdapter (org.keycloak.models.session.PersistentUserSessionAdapter)2 PersistentUserSessionModel (org.keycloak.models.session.PersistentUserSessionModel)2 HashMap (java.util.HashMap)1 AuthenticatedClientSessionModel (org.keycloak.models.AuthenticatedClientSessionModel)1