Handle non-existing client gracefully (#32151)

Closes #32150

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-08-15 16:08:40 +02:00 committed by GitHub
parent aeb1951aba
commit 80d235fffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View file

@ -75,6 +75,10 @@ public class SessionsResource {
Stream<SessionRepresentation> result = sessionIdStream.flatMap((clientIdSessionType) -> { Stream<SessionRepresentation> result = sessionIdStream.flatMap((clientIdSessionType) -> {
ClientModel clientModel = realm.getClientById(clientIdSessionType.getClientId()); ClientModel clientModel = realm.getClientById(clientIdSessionType.getClientId());
if (clientModel == null) {
// client has been removed in the meantime
return Stream.empty();
}
switch (clientIdSessionType.getType()) { switch (clientIdSessionType.getType()) {
case REGULAR: case REGULAR:
return session.sessions().getUserSessionsStream(realm, clientModel) return session.sessions().getUserSessionsStream(realm, clientModel)

View file

@ -172,10 +172,12 @@ public class SessionResource {
for (String clientUUID : s.getAuthenticatedClientSessions().keySet()) { for (String clientUUID : s.getAuthenticatedClientSessions().keySet()) {
ClientModel client = realm.getClientById(clientUUID); ClientModel client = realm.getClientById(clientUUID);
ClientRepresentation clientRep = new ClientRepresentation(); if (client != null) {
clientRep.setClientId(client.getClientId()); ClientRepresentation clientRep = new ClientRepresentation();
clientRep.setClientName(client.getName()); clientRep.setClientId(client.getClientId());
sessionRep.getClients().add(clientRep); clientRep.setClientName(client.getName());
sessionRep.getClients().add(clientRep);
}
} }
return sessionRep; return sessionRep;
} }