Skip to content

Commit

Permalink
Add key/value suffix for schema filtering on LITERAL ACL on v3 claim (#…
Browse files Browse the repository at this point in the history
…328)

* Add key/value suffix for schema filtering on LITERAL ACL on v3 claim

* Updating literal/prefixed tests
  • Loading branch information
AlexisSouquiere authored Oct 3, 2023
1 parent a27dc3d commit a1764e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,25 @@ public AkhqClaimResponseV3 generateClaimV3(@Valid @Body AkhqClaimRequest request

// Add the same pattern and cluster filtering for SCHEMA as the TOPIC ones
result.addAll(result.stream()
.filter(g -> g.role.equals(config.getRoles().get(AccessControlEntry.ResourceType.TOPIC)))
.map(g -> AkhqClaimResponseV3.Group.builder()
.role(config.getRoles().get(AccessControlEntry.ResourceType.SCHEMA))
.patterns(g.getPatterns())
.clusters(g.getClusters())
.build()
).toList());
.filter(g -> g.role.equals(config.getRoles().get(AccessControlEntry.ResourceType.TOPIC)))
.map(g -> {
// Takes all the PREFIXED patterns as-is
List<String> patterns = new ArrayList<>(
g.getPatterns().stream().filter(p -> p.endsWith("\\E.*$")).toList());

// Add -key or -value prefix to the schema pattern for LITERAL patterns
patterns.addAll(g.getPatterns().stream()
.filter(p -> p.endsWith("\\E$"))
.map(p -> p.replace("\\E$", "-\\E(key|value)$"))
.toList());

return AkhqClaimResponseV3.Group.builder()
.role(config.getRoles().get(AccessControlEntry.ResourceType.SCHEMA))
.patterns(patterns)
.clusters(g.getClusters())
.build();
}
).toList());

return AkhqClaimResponseV3.builder()
.groups(result.isEmpty() ? null : Map.of("group", result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ void generateClaimAndOptimizePatterns() {
);
Assertions.assertEquals("registry-read", groups.get(2).getRole());
Assertions.assertEquals(
List.of("^\\Qproject1.\\E.*$", "^\\Qproject2.topic2\\E$", "^\\Qproject2.topic2a\\E$",
"^\\Qproject2.topic3\\E$", "^\\Qproject3.\\E.*$"),
List.of("^\\Qproject1.\\E.*$", "^\\Qproject3.\\E.*$", "^\\Qproject2.topic2-\\E(key|value)$",
"^\\Qproject2.topic2a-\\E(key|value)$", "^\\Qproject2.topic3-\\E(key|value)$"),
groups.get(2).getPatterns()
);
}
Expand Down

0 comments on commit a1764e0

Please sign in to comment.