@Override public void removeAllUserLoginFailures(RealmModel realm) { Iterator<LoginFailureKey> itr = loginFailureCache.entrySet().stream().filter(UserLoginFailurePredicate.create(realm.getId())).map(Mappers.loginFailureId()).iterator(); while (itr.hasNext()) { LoginFailureKey key = itr.next(); tx.remove(loginFailureCache, key); } }
protected long getUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) { return getCache(offline).entrySet().stream().filter(ClientSessionPredicate.create(realm.getId()).client(client.getId()).requireUserSession()).map(Mappers.clientSessionToUserSessionId()).distinct().count(); }
.map(Mappers.clientSessionToUserSessionTimestamp()) .iterator();
.stream() .filter(predicate) .map(Mappers.userSessionEntity()) .forEach(new Consumer<UserSessionEntity>() { .stream() .filter(AuthenticatedClientSessionPredicate.create(realm.getId()).expired(expiredOffline)) .map(Mappers.clientSessionEntity()) .forEach(new Consumer<AuthenticatedClientSessionEntity>() {
protected List<UserSessionModel> getUserSessions(RealmModel realm, Predicate<Map.Entry<String, SessionEntityWrapper<UserSessionEntity>>> predicate, boolean offline) { Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline); cache = CacheDecorators.skipCacheLoaders(cache); Stream<Map.Entry<String, SessionEntityWrapper<UserSessionEntity>>> cacheStream = cache.entrySet().stream(); List<UserSessionModel> resultSessions = new LinkedList<>(); Iterator<UserSessionEntity> itr = cacheStream.filter(predicate) .map(Mappers.userSessionEntity()) .iterator(); while (itr.hasNext()) { UserSessionEntity userSessionEntity = itr.next(); resultSessions.add(wrap(realm, userSessionEntity, offline)); } return resultSessions; }
protected void removeUserSessions(RealmModel realm, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Iterator<String> itr = cache.entrySet().stream().filter(SessionPredicate.create(realm.getId())).map(Mappers.sessionId()).iterator(); while (itr.hasNext()) { cache.remove(itr.next()); } }
@Override public Map<String, Long> getActiveClientSessionStats(RealmModel realm, boolean offline) { Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline); cache = CacheDecorators.skipCacheLoaders(cache); return cache.entrySet().stream() .filter(UserSessionPredicate.create(realm.getId())) .map(Mappers.authClientSessionSetMapper()) .flatMap((Serializable & Function<Set<String>, Stream<? extends String>>)Mappers::toStream) .collect( CacheCollectors.serializableCollector( () -> Collectors.groupingBy(Function.identity(), Collectors.counting()) ) ); }
.stream() .filter(UserSessionPredicate.create(realm.getId()).expired(expired, expiredRefresh, expiredRememberMe, expiredRefreshRememberMe)) .map(Mappers.userSessionEntity()) .forEach(new Consumer<UserSessionEntity>() { .stream() .filter(AuthenticatedClientSessionPredicate.create(realm.getId()).expired(expired)) .map(Mappers.clientSessionEntity()) .forEach(new Consumer<AuthenticatedClientSessionEntity>() {
protected List<UserSessionModel> getUserSessionModels(RealmModel realm, int firstResult, int maxResults, boolean offline, UserSessionPredicate predicate) { Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline); cache = CacheDecorators.skipCacheLoaders(cache); Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache = getClientSessionCache(offline); Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCacheDecorated = CacheDecorators.skipCacheLoaders(clientSessionCache); Stream<UserSessionEntity> stream = cache.entrySet().stream() .filter(predicate) .map(Mappers.userSessionEntity()) .sorted(Comparators.userSessionLastSessionRefresh()); if (firstResult > 0) { stream = stream.skip(firstResult); } if (maxResults > 0) { stream = stream.limit(maxResults); } final List<UserSessionModel> sessions = new LinkedList<>(); Iterator<UserSessionEntity> itr = stream.iterator(); while (itr.hasNext()) { UserSessionEntity userSessionEntity = itr.next(); sessions.add(wrap(realm, userSessionEntity, offline)); } return sessions; }
private void removeExpiredClientInitialAccess(RealmModel realm) { Iterator<String> itr = sessionCache.entrySet().stream().filter(ClientInitialAccessPredicate.create(realm.getId()).expired(Time.currentTime())).map(Mappers.sessionId()).iterator(); while (itr.hasNext()) { tx.remove(sessionCache, itr.next()); } }
private void removeAllLocalUserLoginFailuresEvent(String realmId) { FuturesHelper futures = new FuturesHelper(); Cache<LoginFailureKey, SessionEntityWrapper<LoginFailureEntity>> localCache = CacheDecorators.localCache(loginFailureCache); Cache<LoginFailureKey, SessionEntityWrapper<LoginFailureEntity>> localCacheStoreIgnore = CacheDecorators.skipCacheLoaders(localCache); localCacheStoreIgnore .entrySet() .stream() .filter(UserLoginFailurePredicate.create(realmId)) .map(Mappers.loginFailureId()) .forEach(loginFailureKey -> { // Remove loginFailure from remoteCache too. Use removeAsync for better perf Future future = localCache.removeAsync(loginFailureKey); futures.addTask(future); }); futures.waitForAllToFinish(); log.debugf("Removed %d login failures in realm %s", futures.size(), realmId); }
@Override public List<UserSessionModel> getOfflineUserSessions(RealmModel realm, UserModel user) { List<UserSessionModel> userSessions = new LinkedList<>(); Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = CacheDecorators.skipCacheLoaders(offlineSessionCache); Iterator<UserSessionEntity> itr = cache.entrySet().stream() .filter(UserSessionPredicate.create(realm.getId()).user(user.getId())) .map(Mappers.userSessionEntity()) .iterator(); while (itr.hasNext()) { UserSessionEntity userSessionEntity = itr.next(); UserSessionModel userSession = wrap(realm, userSessionEntity, true); userSessions.add(userSession); } return userSessions; }
protected void removeUserSessions(RealmModel realm, UserModel user, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Iterator<String> itr = cache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).user(user.getId())).map(Mappers.sessionId()).iterator(); while (itr.hasNext()) { removeUserSession(realm, itr.next(), offline); } }
protected void removeUserSessions(RealmModel realm, UserModel user, boolean offline) { Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline); cache = CacheDecorators.skipCacheLoaders(cache); Iterator<UserSessionEntity> itr = cache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).user(user.getId())).map(Mappers.userSessionEntity()).iterator(); while (itr.hasNext()) { UserSessionEntity userSessionEntity = itr.next(); removeUserSession(userSessionEntity, offline); } }
private void removeExpiredOfflineClientSessions(RealmModel realm) { UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class); int expiredOffline = Time.currentTime() - realm.getOfflineSessionIdleTimeout(); Iterator<String> itr = offlineSessionCache.entrySet().stream().filter(ClientSessionPredicate.create(realm.getId()).expiredRefresh(expiredOffline)).map(Mappers.sessionId()).iterator(); while (itr.hasNext()) { String sessionId = itr.next(); tx.remove(offlineSessionCache, sessionId); persister.removeClientSession(sessionId, true); } }
private void removeLocalUserSessions(String realmId, boolean offline) { FuturesHelper futures = new FuturesHelper(); Cache<String, SessionEntityWrapper<UserSessionEntity>> cache = getCache(offline); Cache<String, SessionEntityWrapper<UserSessionEntity>> localCache = CacheDecorators.localCache(cache); Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> clientSessionCache = getClientSessionCache(offline); Cache<UUID, SessionEntityWrapper<AuthenticatedClientSessionEntity>> localClientSessionCache = CacheDecorators.localCache(clientSessionCache); Cache<String, SessionEntityWrapper<UserSessionEntity>> localCacheStoreIgnore = CacheDecorators.skipCacheLoaders(localCache); final AtomicInteger userSessionsSize = new AtomicInteger(); localCacheStoreIgnore .entrySet() .stream() .filter(SessionPredicate.create(realmId)) .map(Mappers.userSessionEntity()) .forEach(new Consumer<UserSessionEntity>() { @Override public void accept(UserSessionEntity userSessionEntity) { userSessionsSize.incrementAndGet(); // Remove session from remoteCache too. Use removeAsync for better perf Future future = localCache.removeAsync(userSessionEntity.getId()); futures.addTask(future); userSessionEntity.getAuthenticatedClientSessions().forEach((clientUUID, clientSessionId) -> { Future f = localClientSessionCache.removeAsync(clientSessionId); futures.addTask(f); }); } }); futures.waitForAllToFinish(); log.debugf("Removed %d sessions in realm %s. Offline: %b", (Object) userSessionsSize.get(), realmId, offline); }