Skip to content

Commit

Permalink
debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
tozny-migal committed Dec 17, 2024
1 parent 62ab0f6 commit df63a79
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class InfinispanAuthenticationSessionProvider implements AuthenticationSe
protected final SessionEventsSenderTransaction clusterEventsSenderTx;

public InfinispanAuthenticationSessionProvider(KeycloakSession session, InfinispanKeyGenerator keyGenerator,
Cache<String, RootAuthenticationSessionEntity> cache, int authSessionsLimit) {
Cache<String, RootAuthenticationSessionEntity> cache, int authSessionsLimit) {
this.session = session;
this.cache = cache;
this.keyGenerator = keyGenerator;
Expand All @@ -75,7 +75,6 @@ public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel
return createRootAuthenticationSession(realm, id);
}


@Override
public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel realm, String id) {
RootAuthenticationSessionEntity entity = new RootAuthenticationSessionEntity();
Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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<String, String> authNotesFragment) {
public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId,
Map<String, String> 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());
}

Expand All @@ -184,7 +190,6 @@ public Cache<String, RootAuthenticationSessionEntity> getCache() {
return cache;
}


protected String generateTabId() {
return Base64Url.encode(SecretGenerator.getInstance().randomBytes(8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
private final KeycloakSession session;
protected final MapKeycloakTransaction<MapRootAuthenticationSessionEntity, RootAuthenticationSessionModel> tx;

public MapRootAuthenticationSessionProvider(KeycloakSession session, MapStorage<MapRootAuthenticationSessionEntity, RootAuthenticationSessionModel> sessionStore) {
public MapRootAuthenticationSessionProvider(KeycloakSession session,
MapStorage<MapRootAuthenticationSessionEntity, RootAuthenticationSessionModel> sessionStore) {
this.session = session;
this.tx = sessionStore.createTransaction(session);

session.getTransactionManager().enlistAfterCompletion(tx);
}

private Function<MapRootAuthenticationSessionEntity, RootAuthenticationSessionModel> entityToAdapterFunc(RealmModel realm) {
private Function<MapRootAuthenticationSessionEntity, RootAuthenticationSessionModel> entityToAdapterFunc(
RealmModel realm) {
return origEntity -> {
if (isExpired(origEntity, true)) {
tx.delete(origEntity.getId());
Expand Down Expand Up @@ -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))
Expand All @@ -126,21 +130,24 @@ 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());
}

@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
Expand All @@ -158,7 +165,8 @@ public void onClientRemoved(RealmModel realm, ClientModel client) {
}

@Override
public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId, Map<String, String> authNotesFragment) {
public void updateNonlocalSessionAuthNotes(AuthenticationSessionCompoundId compoundId,
Map<String, String> authNotesFragment) {
if (compoundId == null) {
return;
}
Expand Down

0 comments on commit df63a79

Please sign in to comment.