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");
|
||||
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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue