public UserSessionPredicate readObjectVersion1(ObjectInput input) throws IOException, ClassNotFoundException { UserSessionPredicate res = new UserSessionPredicate(MarshallUtil.unmarshallString(input)); res.user(MarshallUtil.unmarshallString(input)); res.client(MarshallUtil.unmarshallString(input)); res.expired(KeycloakMarshallUtil.unmarshallInteger(input), KeycloakMarshallUtil.unmarshallInteger(input)); res.brokerSessionId(MarshallUtil.unmarshallString(input)); res.brokerUserId(MarshallUtil.unmarshallString(input)); return res; }
@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); }
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); } } }
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); }
/** * Creates a user session predicate. If using the {@link #client(java.lang.String)} method, see its warning. * @param realm * @return */ public static UserSessionPredicate create(String realm) { return new UserSessionPredicate(realm); }
public UserSessionPredicate expired(Integer expired, Integer expiredRefresh) { return this.expired(expired, expiredRefresh, null, null); }
@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 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); } } } }
@Override public List<UserSessionModel> getUserSessionByBrokerUserId(RealmModel realm, String brokerUserId) { return getUserSessions(realm, UserSessionPredicate.create(realm.getId()).brokerUserId(brokerUserId), false); }
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(); }
public static UserSessionPredicate create(String realm) { return new UserSessionPredicate(realm); }
public UserSessionPredicate readObjectVersion2(ObjectInput input) throws IOException, ClassNotFoundException { UserSessionPredicate res = new UserSessionPredicate(MarshallUtil.unmarshallString(input)); res.user(MarshallUtil.unmarshallString(input)); res.client(MarshallUtil.unmarshallString(input)); res.expired(KeycloakMarshallUtil.unmarshallInteger(input), KeycloakMarshallUtil.unmarshallInteger(input), KeycloakMarshallUtil.unmarshallInteger(input), KeycloakMarshallUtil.unmarshallInteger(input)); res.brokerSessionId(MarshallUtil.unmarshallString(input)); res.brokerUserId(MarshallUtil.unmarshallString(input)); return res; } }
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); } }
@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<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; }