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