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) -> {
ClientModel clientModel = realm.getClientById(clientIdSessionType.getClientId());
if (clientModel == null) {
// client has been removed in the meantime
return Stream.empty();
}
switch (clientIdSessionType.getType()) {
case REGULAR:
return session.sessions().getUserSessionsStream(realm, clientModel)

View file

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