Search in sources :

Example 11 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserSessionPersisterProvider method getUserSessionsCountsByClients.

@Override
public Map<String, Long> getUserSessionsCountsByClients(RealmModel realm, boolean offline) {
    String offlineStr = offlineToString(offline);
    TypedQuery<Object[]> query = em.createNamedQuery("findClientSessionsClientIds", Object[].class);
    query.setParameter("offline", offlineStr);
    query.setParameter("realmId", realm.getId());
    return closing(query.getResultStream()).collect(Collectors.toMap(row -> {
        String clientId = row[0].toString();
        if (clientId.equals(PersistentClientSessionEntity.EXTERNAL)) {
            final String externalClientId = row[1].toString();
            final String clientStorageProvider = row[2].toString();
            clientId = new StorageId(clientStorageProvider, externalClientId).getId();
        }
        return clientId;
    }, row -> (Long) row[3]));
}
Also used : ClientModel(org.keycloak.models.ClientModel) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) TypedQuery(javax.persistence.TypedQuery) Function(java.util.function.Function) StorageId(org.keycloak.storage.StorageId) HashSet(java.util.HashSet) UserModel(org.keycloak.models.UserModel) AuthenticatedClientSessionModel(org.keycloak.models.AuthenticatedClientSessionModel) Map(java.util.Map) PersistentAuthenticatedClientSessionAdapter(org.keycloak.models.session.PersistentAuthenticatedClientSessionAdapter) PersistentUserSessionModel(org.keycloak.models.session.PersistentUserSessionModel) Time(org.keycloak.common.util.Time) RealmModel(org.keycloak.models.RealmModel) UserSessionPersisterProvider(org.keycloak.models.session.UserSessionPersisterProvider) Collection(java.util.Collection) StreamsUtil.closing(org.keycloak.utils.StreamsUtil.closing) KeycloakSession(org.keycloak.models.KeycloakSession) Set(java.util.Set) UserSessionModel(org.keycloak.models.UserSessionModel) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) PersistentClientSessionModel(org.keycloak.models.session.PersistentClientSessionModel) Objects(java.util.Objects) PaginationUtils.paginateQuery(org.keycloak.models.jpa.PaginationUtils.paginateQuery) Query(javax.persistence.Query) List(java.util.List) PersistentUserSessionAdapter(org.keycloak.models.session.PersistentUserSessionAdapter) Stream(java.util.stream.Stream) SessionTimeoutHelper(org.keycloak.models.utils.SessionTimeoutHelper) LockModeType(javax.persistence.LockModeType) Collections(java.util.Collections) StorageId(org.keycloak.storage.StorageId)

Example 12 with StorageId

use of org.keycloak.storage.StorageId 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 13 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class JpaUserSessionPersisterProvider method loadUserSessionsStream.

@Override
public Stream<UserSessionModel> loadUserSessionsStream(RealmModel realm, ClientModel client, boolean offline, Integer firstResult, Integer maxResults) {
    String offlineStr = offlineToString(offline);
    TypedQuery<PersistentUserSessionEntity> query;
    StorageId clientStorageId = new StorageId(client.getId());
    if (clientStorageId.isLocal()) {
        query = paginateQuery(em.createNamedQuery("findUserSessionsByClientId", PersistentUserSessionEntity.class), firstResult, maxResults);
        query.setParameter("clientId", client.getId());
    } else {
        query = paginateQuery(em.createNamedQuery("findUserSessionsByExternalClientId", PersistentUserSessionEntity.class), firstResult, maxResults);
        query.setParameter("clientStorageProvider", clientStorageId.getProviderId());
        query.setParameter("externalClientId", clientStorageId.getExternalId());
    }
    query.setParameter("offline", offlineStr);
    query.setParameter("realmId", realm.getId());
    return loadUserSessionsWithClientSessions(query, offlineStr);
}
Also used : StorageId(org.keycloak.storage.StorageId)

Example 14 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class HardcodedClientScopeStorageProvider method getClientScopeById.

@Override
public ClientScopeModel getClientScopeById(RealmModel realm, String id) {
    StorageId storageId = new StorageId(id);
    final String scopeName = storageId.getExternalId();
    if (this.clientScopeName.equals(scopeName))
        return new HardcodedClientScopeAdapter(realm);
    return null;
}
Also used : StorageId(org.keycloak.storage.StorageId)

Example 15 with StorageId

use of org.keycloak.storage.StorageId in project keycloak by keycloak.

the class HardcodedGroupStorageProvider method getGroupById.

@Override
public GroupModel getGroupById(RealmModel realm, String id) {
    StorageId storageId = new StorageId(id);
    final String groupName = storageId.getExternalId();
    if (this.groupName.equals(groupName))
        return new HardcodedGroupAdapter(realm);
    return null;
}
Also used : StorageId(org.keycloak.storage.StorageId)

Aggregations

StorageId (org.keycloak.storage.StorageId)44 UserModel (org.keycloak.models.UserModel)7 RealmModel (org.keycloak.models.RealmModel)6 ComponentModel (org.keycloak.component.ComponentModel)5 ClientModel (org.keycloak.models.ClientModel)5 ClientScopeModel (org.keycloak.models.ClientScopeModel)5 List (java.util.List)3 Objects (java.util.Objects)3 Stream (java.util.stream.Stream)3 Test (org.junit.Test)3 KeycloakSession (org.keycloak.models.KeycloakSession)3 ModelException (org.keycloak.models.ModelException)3 UserConsentModel (org.keycloak.models.UserConsentModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2