diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java index 1809250cf0cc..95177cc8f655 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanAuthenticationSessionProvider.java @@ -56,7 +56,7 @@ public class InfinispanAuthenticationSessionProvider implements AuthenticationSe protected final SessionEventsSenderTransaction clusterEventsSenderTx; public InfinispanAuthenticationSessionProvider(KeycloakSession session, InfinispanKeyGenerator keyGenerator, - Cache cache, int authSessionsLimit) { + Cache cache, int authSessionsLimit) { this.session = session; this.cache = cache; this.keyGenerator = keyGenerator; @@ -75,7 +75,6 @@ public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel return createRootAuthenticationSession(realm, id); } - @Override public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel realm, String id) { RootAuthenticationSessionEntity entity = new RootAuthenticationSessionEntity(); @@ -89,12 +88,11 @@ public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel return wrap(realm, entity); } - private RootAuthenticationSessionAdapter wrap(RealmModel realm, RootAuthenticationSessionEntity entity) { - return entity==null ? null : new RootAuthenticationSessionAdapter(session, this, cache, realm, entity, authSessionsLimit); + return entity == null ? null + : new RootAuthenticationSessionAdapter(session, this, cache, realm, entity, authSessionsLimit); } - private RootAuthenticationSessionEntity getRootAuthenticationSessionEntity(String authSessionId) { // Chance created in this transaction RootAuthenticationSessionEntity entity = tx.get(cache, authSessionId); @@ -103,19 +101,24 @@ private RootAuthenticationSessionEntity getRootAuthenticationSessionEntity(Strin @Override public void removeAllExpired() { - // Rely on expiration of cache entries provided by infinispan. Nothing needed here + // Rely on expiration of cache entries provided by infinispan. Nothing needed + // here } @Override public void removeExpired(RealmModel realm) { - // Rely on expiration of cache entries provided by infinispan. Nothing needed here + // Rely on expiration of cache entries provided by infinispan. Nothing needed + // here } @Override public void onRealmRemoved(RealmModel realm) { - // Send message to all DCs. The remoteCache will notify client listeners on all DCs for remove authentication sessions + // Send message to all DCs. The remoteCache will notify client listeners on all + // DCs for remove authentication sessions clusterEventsSenderTx.addEvent( - RealmRemovedSessionEvent.createEvent(RealmRemovedSessionEvent.class, InfinispanAuthenticationSessionProviderFactory.REALM_REMOVED_AUTHSESSION_EVENT, session, realm.getId(), false), + RealmRemovedSessionEvent.createEvent(RealmRemovedSessionEvent.class, + InfinispanAuthenticationSessionProviderFactory.REALM_REMOVED_AUTHSESSION_EVENT, session, + realm.getId(), false), ClusterProvider.DCNotify.ALL_DCS); } @@ -132,46 +135,49 @@ protected void onRealmRemovedEvent(String realmId) { } } - @Override public void onClientRemoved(RealmModel realm, ClientModel client) { - // No update anything on clientRemove for now. AuthenticationSessions of removed client will be handled at runtime if needed. + // No update anything on clientRemove for now. AuthenticationSessions of removed + // client will be handled at runtime if needed. -// clusterEventsSenderTx.addEvent( -// ClientRemovedSessionEvent.create(session, InfinispanAuthenticationSessionProviderFactory.CLIENT_REMOVED_AUTHSESSION_EVENT, realm.getId(), false, client.getId()), -// ClusterProvider.DCNotify.ALL_DCS); + // clusterEventsSenderTx.addEvent( + // ClientRemovedSessionEvent.create(session, + // InfinispanAuthenticationSessionProviderFactory.CLIENT_REMOVED_AUTHSESSION_EVENT, + // realm.getId(), false, client.getId()), + // ClusterProvider.DCNotify.ALL_DCS); } protected void onClientRemovedEvent(String realmId, String clientUuid) { } - @Override - public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, Map authNotesFragment) { + public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, + Map authNotesFragment) { if (compoundId == null) { return; } ClusterProvider cluster = session.getProvider(ClusterProvider.class); cluster.notify( - InfinispanAuthenticationSessionProviderFactory.AUTHENTICATION_SESSION_EVENTS, - AuthenticationSessionAuthNoteUpdateEvent.create(compoundId.getRootSessionId(), compoundId.getTabId(), compoundId.getClientUUID(), authNotesFragment), - true, - ClusterProvider.DCNotify.ALL_BUT_LOCAL_DC - ); + InfinispanAuthenticationSessionProviderFactory.AUTHENTICATION_SESSION_EVENTS, + AuthenticationSessionAuthNoteUpdateEvent.create(compoundId.getRootSessionId(), compoundId.getTabId(), + compoundId.getClientUUID(), authNotesFragment), + true, + ClusterProvider.DCNotify.ALL_BUT_LOCAL_DC); } - @Override - public RootAuthenticationSessionModel getRootAuthenticationSession(RealmModel realm, String authenticationSessionId) { + public RootAuthenticationSessionModel getRootAuthenticationSession(RealmModel realm, + String authenticationSessionId) { RootAuthenticationSessionEntity entity = getRootAuthenticationSessionEntity(authenticationSessionId); + log.info("IN INFINISPAN"); return wrap(realm, entity); } - @Override - public void removeRootAuthenticationSession(RealmModel realm, RootAuthenticationSessionModel authenticationSession) { + public void removeRootAuthenticationSession(RealmModel realm, + RootAuthenticationSessionModel authenticationSession) { tx.remove(cache, authenticationSession.getId()); } @@ -184,7 +190,6 @@ public Cache getCache() { return cache; } - protected String generateTabId() { return Base64Url.encode(SecretGenerator.getInstance().randomBytes(8)); } diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java index 1011df57487e..f09ff05a771e 100644 --- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java +++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java @@ -54,14 +54,16 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi private final KeycloakSession session; protected final MapKeycloakTransaction tx; - public MapRootAuthenticationSessionProvider(KeycloakSession session, MapStorage sessionStore) { + public MapRootAuthenticationSessionProvider(KeycloakSession session, + MapStorage sessionStore) { this.session = session; this.tx = sessionStore.createTransaction(session); session.getTransactionManager().enlistAfterCompletion(tx); } - private Function entityToAdapterFunc(RealmModel realm) { + private Function entityToAdapterFunc( + RealmModel realm) { return origEntity -> { if (isExpired(origEntity, true)) { tx.delete(origEntity.getId()); @@ -111,13 +113,15 @@ public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel } @Override - public RootAuthenticationSessionModel getRootAuthenticationSession(RealmModel realm, String authenticationSessionId) { + public RootAuthenticationSessionModel getRootAuthenticationSession(RealmModel realm, + String authenticationSessionId) { Objects.requireNonNull(realm, "The provided realm can't be null!"); if (authenticationSessionId == null) { return null; } - - LOG.tracef("getRootAuthenticationSession(%s, %s)%s", realm.getName(), authenticationSessionId, getShortStackTrace()); + LOG.info("IN MAPROOT"); + LOG.tracef("getRootAuthenticationSession(%s, %s)%s", realm.getName(), authenticationSessionId, + getShortStackTrace()); MapRootAuthenticationSessionEntity entity = tx.read(authenticationSessionId); return (entity == null || !entityRealmFilter(realm.getId()).test(entity)) @@ -126,7 +130,8 @@ public RootAuthenticationSessionModel getRootAuthenticationSession(RealmModel re } @Override - public void removeRootAuthenticationSession(RealmModel realm, RootAuthenticationSessionModel authenticationSession) { + public void removeRootAuthenticationSession(RealmModel realm, + RootAuthenticationSessionModel authenticationSession) { Objects.requireNonNull(authenticationSession, "The provided root authentication session can't be null!"); tx.delete(authenticationSession.getId()); } @@ -134,13 +139,15 @@ public void removeRootAuthenticationSession(RealmModel realm, RootAuthentication @Override public void removeAllExpired() { LOG.tracef("removeAllExpired()%s", getShortStackTrace()); - LOG.warnf("Clearing expired entities should not be triggered manually. It is responsibility of the store to clear these."); + LOG.warnf( + "Clearing expired entities should not be triggered manually. It is responsibility of the store to clear these."); } @Override public void removeExpired(RealmModel realm) { LOG.tracef("removeExpired(%s)%s", realm, getShortStackTrace()); - LOG.warnf("Clearing expired entities should not be triggered manually. It is responsibility of the store to clear these."); + LOG.warnf( + "Clearing expired entities should not be triggered manually. It is responsibility of the store to clear these."); } @Override @@ -158,7 +165,8 @@ public void onClientRemoved(RealmModel realm, ClientModel client) { } @Override - public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, Map authNotesFragment) { + public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, + Map authNotesFragment) { if (compoundId == null) { return; }