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]));
}
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();
}
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);
}
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;
}
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;
}
Aggregations