use of org.keycloak.models.session.UserSessionPersisterProvider in project keycloak by keycloak.
the class PersistSessionsCommand method doRunCommand.
@Override
public void doRunCommand(KeycloakSession sess) {
final int count = getIntArg(0);
final int batchCount = getIntArg(1);
int remaining = count;
while (remaining > 0) {
int createInThisBatch = Math.min(batchCount, remaining);
createSessionsBatch(createInThisBatch);
remaining = remaining - createInThisBatch;
}
// Write some summary
KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() {
@Override
public void run(KeycloakSession session) {
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
log.info("Command finished. Total number of sessions in persister: " + persister.getUserSessionsCount(true));
}
});
}
use of org.keycloak.models.session.UserSessionPersisterProvider in project keycloak by keycloak.
the class InfinispanUserSessionProvider method getUserSessionsStream.
protected Stream<UserSessionModel> getUserSessionsStream(final RealmModel realm, ClientModel client, Integer firstResult, Integer maxResults, final boolean offline) {
if (offline && loadOfflineSessionsFromDatabase) {
// fetch the actual offline user session count from the database
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
return persister.loadUserSessionsStream(realm, client, true, firstResult, maxResults);
}
final String clientUuid = client.getId();
UserSessionPredicate predicate = UserSessionPredicate.create(realm.getId()).client(clientUuid);
return getUserSessionModels(realm, firstResult, maxResults, offline, predicate);
}
use of org.keycloak.models.session.UserSessionPersisterProvider in project keycloak by keycloak.
the class InfinispanUserSessionProvider method getUserSessionsCount.
protected long getUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) {
if (offline && loadOfflineSessionsFromDatabase) {
// fetch the actual offline user session count from the database
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
return persister.getUserSessionsCount(realm, client, true);
}
Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline);
cache = CacheDecorators.skipCacheLoaders(cache);
final String clientUuid = client.getId();
return cache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).client(clientUuid)).count();
}
use of org.keycloak.models.session.UserSessionPersisterProvider in project keycloak by keycloak.
the class UserSessionPersisterProviderTest method testNoSessions.
// KEYCLOAK-1999
@Test
public void testNoSessions() {
inComittedTransaction(session -> {
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
Stream<UserSessionModel> sessions = persister.loadUserSessionsStream(0, 1, true, "00000000-0000-0000-0000-000000000000");
Assert.assertEquals(0, sessions.count());
});
}
use of org.keycloak.models.session.UserSessionPersisterProvider in project keycloak by keycloak.
the class UserSessionPersisterProviderTest method persistUserSession.
private void persistUserSession(KeycloakSession session, UserSessionModel userSession, boolean offline) {
UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class);
persister.createUserSession(userSession, offline);
for (AuthenticatedClientSessionModel clientSession : userSession.getAuthenticatedClientSessions().values()) {
persister.createClientSession(clientSession, offline);
}
}
Aggregations