Merge branch 'main' into add-map-endpoint
Some checks failed
/ Verify (pull_request) Failing after 39s
/ Verify (push) Failing after 40s

This commit is contained in:
Stefan Bethke 2026-07-18 14:20:22 +02:00
commit 9073ef086a
8 changed files with 2486 additions and 23 deletions

View file

@ -86,7 +86,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.5</version>
<version>3.5.6</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
@ -104,7 +104,7 @@
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.21.0</version>
<version>3.22.0</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>

View file

@ -3,6 +3,13 @@ package de.ccc.hamburg.keycloak.attribute_endpoints;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.jboss.logging.Logger;
import org.keycloak.component.ComponentModel;
import org.keycloak.models.*;
@ -198,13 +205,33 @@ public class AttributeEndpointsResourceProvider implements RealmResourceProvider
.map(a -> a.getName())
.toList();
userProvider = session.users();
// getRoleMembersStream only returns users with matchRole assigned directly; it misses
// users who have the role via group membership (incl. parent groups) or composite roles.
// hasRole() resolves the role the same way authUser.hasRole(authRole) does above.
users = userProvider.searchForUserStream(realm, Map.of())
.filter(user -> user.hasRole(matchRole));
}
UserProvider userProvider = session.users();
Stream<UserModel> users = userProvider.searchForUserStream(realm, Map.of())
.filter(user -> user.hasRole(matchRole));
List<String> attribute_list = users
.map(user -> {
Stream<String> attributeStream = attributeNames.stream()
.map(attributeName -> user.getAttributeStream(attributeName).toList())
.flatMap(Collection::stream);
return attributeStream
.filter(attribute -> !attribute.isEmpty())
.toList();
})
.flatMap(List::stream)
.filter(attribute -> {
if (regexIsBlank) {
return true;
}
final Pattern pattern = Pattern.compile(configAttributeRegex);
final Matcher matcher = pattern.matcher(attribute);
return matcher.find();
})
.toList();
return Response.ok(attribute_list).build();
}
private static Auth getAuth(KeycloakSession session) {