ignore regex filter when empty
This commit is contained in:
parent
1381bf6b2a
commit
769fdd704a
1 changed files with 19 additions and 12 deletions
|
|
@ -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;
|
||||||
|
|
||||||
|
if (!regexIsBlank) {
|
||||||
try {
|
try {
|
||||||
attributeRegex = Pattern.compile(configAttributeRegex);
|
Pattern.compile(configAttributeRegex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServerErrorException(
|
throw new ServerErrorException(
|
||||||
"Endpoint Configuration Error - attribute-regex is not a valid regex pattern.", 500);
|
"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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue