ignore regex filter when empty

This commit is contained in:
kritzl 2026-02-17 16:50:48 +01:00
commit 769fdd704a
Signed by: kritzl
SSH key fingerprint: SHA256:5BmINP9VjZWaUk5Z+2CTut1KFhwLtd0ZynMekKbtViM

View file

@ -91,15 +91,20 @@ public class AttributeEndpointsResourceProvider implements RealmResourceProvider
} }
String configAttributeRegex = component.getConfig().getFirst("attribute-regex"); String configAttributeRegex = component.getConfig().getFirst("attribute-regex");
Pattern attributeRegex; Boolean regexIsBlank = configAttributeRegex == null;
try {
attributeRegex = Pattern.compile(configAttributeRegex); if (!regexIsBlank) {
} catch (Exception e) { try {
throw new ServerErrorException( Pattern.compile(configAttributeRegex);
"Endpoint Configuration Error - attribute-regex is not a valid regex pattern.", 500); } catch (Exception e) {
throw new ServerErrorException(
"Endpoint Configuration Error - attribute-regex is not a valid regex pattern.", 500);
}
} }
try { try
{
UserModel user = auth.getUser(); UserModel user = auth.getUser();
if (!user.hasRole(authRole)) { if (!user.hasRole(authRole)) {
throw new UnauthorizedException("User does not have required auth role."); throw new UnauthorizedException("User does not have required auth role.");
@ -134,12 +139,14 @@ public class AttributeEndpointsResourceProvider implements RealmResourceProvider
.toList(); .toList();
}) })
.flatMap(List::stream) .flatMap(List::stream)
// TODO: Ignore regex when empty .filter(attribute -> {
.map(attribute -> { if (regexIsBlank) {
final Matcher matcher = attributeRegex.matcher(attribute); return true;
return matcher.find() ? attribute : null; }
final Pattern pattern = Pattern.compile(configAttributeRegex);
final Matcher matcher = pattern.matcher(attribute);
return matcher.find();
}) })
.filter(Objects::nonNull)
.toList(); .toList();
return Response.ok(attribute_list).build(); return Response.ok(attribute_list).build();