UserSessionEntity getUserSessionEntity(UserSessionModel userSession, boolean offline) { if (userSession instanceof UserSessionAdapter) { return ((UserSessionAdapter) userSession).getEntity(); } else { return getUserSessionEntity(userSession.getId(), offline); } }
void attachSession(UserSessionAdapter userSession, ClientSessionModel clientSession) { UserSessionEntity entity = userSession.getEntity(); String clientSessionId = clientSession.getId(); if (entity.getClientSessions() == null) { entity.setClientSessions(new HashSet<String>()); } if (!entity.getClientSessions().contains(clientSessionId)) { entity.getClientSessions().add(clientSessionId); userSession.update(); } }
void dettachSession(UserSessionAdapter userSession, ClientSessionModel clientSession) { UserSessionEntity entity = userSession.getEntity(); String clientSessionId = clientSession.getId(); if (entity.getClientSessions() != null && entity.getClientSessions().contains(clientSessionId)) { entity.getClientSessions().remove(clientSessionId); if (entity.getClientSessions().isEmpty()) { entity.setClientSessions(null); } userSession.update(); } }
@Override public UserSessionModel createOfflineUserSession(UserSessionModel userSession) { UserSessionAdapter offlineUserSession = importUserSession(userSession, true); // started and lastSessionRefresh set to current time int currentTime = Time.currentTime(); offlineUserSession.getEntity().setStarted(currentTime); offlineUserSession.setLastSessionRefresh(currentTime); return offlineUserSession; }
@Override public UserSessionModel createOfflineUserSession(UserSessionModel userSession) { UserSessionAdapter offlineUserSession = importUserSession(userSession, true); // started and lastSessionRefresh set to current time int currentTime = Time.currentTime(); offlineUserSession.getEntity().setStarted(currentTime); offlineUserSession.setLastSessionRefresh(currentTime); return offlineUserSession; }
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 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()); }
private AuthenticatedClientSessionAdapter importClientSession(UserSessionAdapter sessionToImportInto, AuthenticatedClientSessionModel clientSession, InfinispanChangelogBasedTransaction<String, UserSessionEntity> userSessionUpdateTx, InfinispanChangelogBasedTransaction<UUID, AuthenticatedClientSessionEntity> clientSessionUpdateTx, boolean offline) { AuthenticatedClientSessionEntity entity = createAuthenticatedClientSessionInstance(clientSession, sessionToImportInto.getRealm().getId(), offline); final UUID clientSessionId = entity.getId(); SessionUpdateTask<AuthenticatedClientSessionEntity> createClientSessionTask = Tasks.addIfAbsentSync(); clientSessionUpdateTx.addTask(entity.getId(), createClientSessionTask, entity); AuthenticatedClientSessionStore clientSessions = sessionToImportInto.getEntity().getAuthenticatedClientSessions(); clientSessions.put(clientSession.getClient().getId(), clientSessionId); SessionUpdateTask registerClientSessionTask = new RegisterClientSessionTask(clientSession.getClient().getId(), clientSessionId); userSessionUpdateTx.addTask(sessionToImportInto.getId(), registerClientSessionTask); return new AuthenticatedClientSessionAdapter(session,this, entity, clientSession.getClient(), sessionToImportInto, userSessionUpdateTx, clientSessionUpdateTx, offline); }