diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java index 4d5506bf139f..2949e43f81d4 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java @@ -373,11 +373,10 @@ protected Stream getUserSessionsStream(RealmModel realm, UserS attributes.put(UserModel.IDP_USER_ID, idpAliasSessionId[1]); UserProvider userProvider = session.getProvider(UserProvider.class); - UserModel userModel = userProvider.searchForUserStream(realm, attributes, 0, null).findFirst().orElse(null); - return userModel != null ? - persister.loadUserSessionsStream(realm, userModel, true, 0, null) - .filter(predicate.toModelPredicate()) : - Stream.empty(); + + return userProvider.searchForUserStream(realm, attributes, 0, null) + .flatMap((Function>) userModel -> persister.loadUserSessionsStream(realm, userModel, true, 0, null)) + .filter(predicate.toModelPredicate()); } throw new ModelException("For offline sessions, only lookup by userId and brokerUserId is supported"); diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java index 970b9e8c9625..8dddfcd18ef4 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/PersistentUserSessionProvider.java @@ -332,13 +332,12 @@ public String getId() { attributes.put(UserModel.IDP_USER_ID, idpAliasSessionId[1]); UserProvider userProvider = session.getProvider(UserProvider.class); - UserModel userModel = userProvider.searchForUserStream(realm, attributes, 0, null).findFirst().orElse(null); - return userModel != null ? - persister.loadUserSessionsStream(realm, userModel, offline, 0, null) - .filter(predicate.toModelPredicate()) - .map(s -> (UserSessionModel) getUserSession(realm, s.getId(), s, offline)) - .filter(Objects::nonNull) : - Stream.empty(); + + return userProvider.searchForUserStream(realm, attributes, 0, null) + .flatMap((Function>) userModel -> persister.loadUserSessionsStream(realm, userModel, offline, 0, null)) + .filter(predicate.toModelPredicate()) + .map(s -> (UserSessionModel) getUserSession(realm, s.getId(), s, offline)) + .filter(Objects::nonNull); } if (predicate.getClient() != null) {