@Override public UserSessionModel getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) { List<UserSessionModel> userSessions = getUserSessions(realm, UserSessionPredicate.create(realm.getId()).brokerSessionId(brokerSessionId), false); return userSessions.isEmpty() ? null : userSessions.get(0); }
@Override public UserSessionModel getUserSessionByBrokerSessionId(RealmModel realm, String brokerSessionId) { List<UserSessionModel> userSessions = getUserSessions(realm, UserSessionPredicate.create(realm.getId()).brokerSessionId(brokerSessionId), false); return userSessions.isEmpty() ? null : userSessions.get(0); }
@Override public List<UserSessionModel> getUserSessionByBrokerUserId(RealmModel realm, String brokerUserId) { return getUserSessions(realm, UserSessionPredicate.create(realm.getId()).brokerUserId(brokerUserId), false); }
@Override public List<UserSessionModel> getUserSessionByBrokerUserId(RealmModel realm, String brokerUserId) { return getUserSessions(realm, UserSessionPredicate.create(realm.getId()).brokerUserId(brokerUserId), false); }
@Override public List<ClientSessionModel> getOfflineClientSessions(RealmModel realm, UserModel user) { Iterator<Map.Entry<String, SessionEntity>> itr = offlineSessionCache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).user(user.getId())).iterator(); List<ClientSessionModel> clientSessions = new LinkedList<>(); while(itr.hasNext()) { UserSessionEntity entity = (UserSessionEntity) itr.next().getValue(); Set<String> currClientSessions = entity.getClientSessions(); for (String clientSessionId : currClientSessions) { ClientSessionEntity cls = (ClientSessionEntity) offlineSessionCache.get(clientSessionId); if (cls != null) { clientSessions.add(wrap(realm, cls, true)); } } } return clientSessions; }
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 List<UserSessionModel> getUserSessions(final RealmModel realm, ClientModel client, int firstResult, int maxResults, final boolean offline) { final String clientUuid = client.getId(); UserSessionPredicate predicate = UserSessionPredicate.create(realm.getId()).client(clientUuid); return getUserSessionModels(realm, firstResult, maxResults, offline, predicate); }
@Override public List<UserSessionModel> getUserSessions(final RealmModel realm, UserModel user) { return getUserSessions(realm, UserSessionPredicate.create(realm.getId()).user(user.getId()), false); }
@Override public List<UserSessionModel> getUserSessions(final RealmModel realm, UserModel user) { return getUserSessions(realm, UserSessionPredicate.create(realm.getId()).user(user.getId()), false); }
@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; }
@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()) ) ); }
private void removeExpiredOfflineUserSessions(RealmModel realm) { UserSessionPersisterProvider persister = session.getProvider(UserSessionPersisterProvider.class); int expiredOffline = Time.currentTime() - realm.getOfflineSessionIdleTimeout(); Iterator<Map.Entry<String, SessionEntity>> itr = offlineSessionCache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).expired(null, expiredOffline)).iterator(); while (itr.hasNext()) { UserSessionEntity entity = (UserSessionEntity) itr.next().getValue(); tx.remove(offlineSessionCache, entity.getId()); persister.removeUserSession(entity.getId(), true); for (String clientSessionId : entity.getClientSessions()) { tx.remove(offlineSessionCache, clientSessionId); } } }
private void removeExpiredUserSessions(RealmModel realm) { int expired = Time.currentTime() - realm.getSsoSessionMaxLifespan(); int expiredRefresh = Time.currentTime() - realm.getSsoSessionIdleTimeout(); Iterator<Map.Entry<String, SessionEntity>> itr = sessionCache.entrySet().stream().filter(UserSessionPredicate.create(realm.getId()).expired(expired, expiredRefresh)).iterator(); while (itr.hasNext()) { UserSessionEntity entity = (UserSessionEntity) itr.next().getValue(); tx.remove(sessionCache, entity.getId()); if (entity.getClientSessions() != null) { for (String clientSessionId : entity.getClientSessions()) { tx.remove(sessionCache, clientSessionId); } } } }
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); } }
protected long getUserSessionsCount(RealmModel realm, ClientModel client, boolean offline) { 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(); }
UserSessionPredicate predicate = UserSessionPredicate.create(realm.getId()).expired(null, expiredOffline);
.entrySet() .stream() .filter(UserSessionPredicate.create(realm.getId()).expired(expired, expiredRefresh, expiredRememberMe, expiredRefreshRememberMe)) .map(Mappers.userSessionEntity()) .forEach(new Consumer<UserSessionEntity>() {