ClientSessionAdapter wrap(RealmModel realm, ClientSessionEntity entity, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); return entity != null ? new ClientSessionAdapter(session, this, cache, realm, entity, offline) : null; }
UserSessionAdapter wrap(RealmModel realm, UserSessionEntity entity, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); return entity != null ? new UserSessionAdapter(session, this, cache, realm, entity, offline) : null; }
ClientInitialAccessAdapter wrap(RealmModel realm, ClientInitialAccessEntity entity) { Cache<String, SessionEntity> cache = getCache(false); return entity != null ? new ClientInitialAccessAdapter(session, this, cache, realm, entity) : null; }
@Override public void removeClientInitialAccessModel(RealmModel realm, String id) { tx.remove(getCache(false), id); }
protected List<UserSessionModel> getUserSessions(RealmModel realm, Predicate<Map.Entry<String, SessionEntity>> predicate, boolean offline) { CacheStream<Map.Entry<String, SessionEntity>> cacheStream = getCache(offline).entrySet().stream(); Iterator<Map.Entry<String, SessionEntity>> itr = cacheStream.filter(predicate).iterator(); List<UserSessionModel> sessions = new LinkedList<>(); while (itr.hasNext()) { UserSessionEntity e = (UserSessionEntity) itr.next().getValue(); sessions.add(wrap(realm, e, offline)); } return sessions; }
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 ClientSessionModel getClientSession(RealmModel realm, String id, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); ClientSessionEntity entity = (ClientSessionEntity) cache.get(id); // Chance created in this transaction if (entity == null) { entity = (ClientSessionEntity) tx.get(cache, id); } return wrap(realm, entity, offline); }
protected UserSessionAdapter getUserSession(RealmModel realm, String id, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); UserSessionEntity entity = (UserSessionEntity) cache.get(id); // Chance created in this transaction if (entity == null) { entity = (UserSessionEntity) tx.get(cache, id); } return wrap(realm, entity, offline); }
@Override public ClientInitialAccessModel getClientInitialAccessModel(RealmModel realm, String id) { Cache<String, SessionEntity> cache = getCache(false); ClientInitialAccessEntity entity = (ClientInitialAccessEntity) cache.get(id); // If created in this transaction if (entity == null) { entity = (ClientInitialAccessEntity) tx.get(cache, id); } return wrap(realm, entity); }
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()); } }
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); } }
private void onClientRemoved(RealmModel realm, ClientModel client, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); Iterator<Map.Entry<String, SessionEntity>> itr = cache.entrySet().stream().filter(ClientSessionPredicate.create(realm.getId()).client(client.getId())).iterator(); while (itr.hasNext()) { ClientSessionEntity entity = (ClientSessionEntity) itr.next().getValue(); ClientSessionAdapter adapter = wrap(realm, entity, offline); adapter.setUserSession(null); tx.remove(cache, entity.getId()); } }
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(); }
protected void removeUserSession(RealmModel realm, String userSessionId, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); tx.remove(cache, userSessionId); UserSessionEntity sessionEntity = (UserSessionEntity) cache.get(userSessionId); if (sessionEntity.getClientSessions() != null) { for (String clientSessionId : sessionEntity.getClientSessions()) { tx.remove(cache, clientSessionId); } } }
@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()) ) ); }
protected void removeClientSession(RealmModel realm, ClientSessionModel clientSession, boolean offline) { Cache<String, SessionEntity> cache = getCache(offline); UserSessionModel userSession = clientSession.getUserSession(); if (userSession != null) { UserSessionEntity entity = ((UserSessionAdapter) userSession).getEntity(); if (entity.getClientSessions() != null) { entity.getClientSessions().remove(clientSession.getId()); } tx.replace(cache, entity.getId(), entity); } tx.remove(cache, clientSession.getId()); }
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(); }
@Override public UserSessionAdapter importUserSession(UserSessionModel userSession, boolean offline) { UserSessionEntity entity = new UserSessionEntity(); entity.setId(userSession.getId()); entity.setRealm(userSession.getRealm().getId()); entity.setAuthMethod(userSession.getAuthMethod()); entity.setBrokerSessionId(userSession.getBrokerSessionId()); entity.setBrokerUserId(userSession.getBrokerUserId()); entity.setIpAddress(userSession.getIpAddress()); entity.setLoginUsername(userSession.getLoginUsername()); entity.setNotes(userSession.getNotes()); entity.setRememberMe(userSession.isRememberMe()); entity.setState(userSession.getState()); entity.setUser(userSession.getUser().getId()); entity.setStarted(userSession.getStarted()); entity.setLastSessionRefresh(userSession.getLastSessionRefresh()); Cache<String, SessionEntity> cache = getCache(offline); tx.put(cache, userSession.getId(), entity); return wrap(userSession.getRealm(), entity, offline); }
@Override public ClientSessionAdapter importClientSession(ClientSessionModel clientSession, boolean offline) { ClientSessionEntity entity = new ClientSessionEntity(); entity.setId(clientSession.getId()); entity.setRealm(clientSession.getRealm().getId()); entity.setAction(clientSession.getAction()); entity.setAuthenticatorStatus(clientSession.getExecutionStatus()); entity.setAuthMethod(clientSession.getAuthMethod()); if (clientSession.getAuthenticatedUser() != null) { entity.setAuthUserId(clientSession.getAuthenticatedUser().getId()); } entity.setClient(clientSession.getClient().getId()); entity.setNotes(clientSession.getNotes()); entity.setProtocolMappers(clientSession.getProtocolMappers()); entity.setRedirectUri(clientSession.getRedirectUri()); entity.setRoles(clientSession.getRoles()); entity.setTimestamp(clientSession.getTimestamp()); entity.setUserSessionNotes(clientSession.getUserSessionNotes()); Cache<String, SessionEntity> cache = getCache(offline); tx.put(cache, clientSession.getId(), entity); return wrap(clientSession.getRealm(), entity, offline); }