Skip to content

Commit

Permalink
update get ACL endpoint to not handle wildcard for old client
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasCAI-mlv authored and loicgreffier committed Aug 9, 2024
1 parent 1ef6cb7 commit adf0587
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ public List<AccessControlEntry> list(String namespace, Optional<AclLimit> limit,
* Get an ACL by namespace and name.
*
* @param namespace The name
* @param acl The ACL name
* @param acl The ACL name
* @return The ACL
* @deprecated use list(String, Optional, String name) instead.
* @deprecated use list(String, Optional ALL, String name) instead.
*/
@Get("/{acl}")
@Deprecated(since = "1.12.0")
public Optional<AccessControlEntry> get(String namespace, String acl) {
return list(namespace, Optional.of(AclLimit.ALL), acl).stream().findFirst();
return aclService.findAllRelatedToNamespace(getNamespace(namespace))
.stream()
.filter(accessControlEntry -> accessControlEntry.getMetadata().getName().equals(acl))
.findFirst();
}

/**
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/michelin/ns4kafka/service/AclService.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,21 @@ public List<AccessControlEntry> findAllGrantedByNamespace(Namespace namespace) {
.toList();
}

/**
* Find all ACLs that a given namespace granted to other namespaces.
*
* @param namespace The namespace
* @return A list of ACLs
*/
public List<AccessControlEntry> findAllRelatedToNamespace(Namespace namespace) {
return accessControlEntryRepository.findAll()
.stream()
.filter(acl -> acl.getMetadata().getNamespace().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(PUBLIC_GRANTED_TO))
.toList();
}

/**
* Find all ACLs granted to given namespace, filtered by name parameter.
* Will also return public granted ACLs.
Expand Down Expand Up @@ -316,11 +331,8 @@ public List<AccessControlEntry> findByWildcardNameGrantedByNamespace(Namespace n
*/
public List<AccessControlEntry> findByWildcardNameRelatedToNamespace(Namespace namespace, String name) {
List<String> nameFilterPatterns = RegexUtils.wildcardStringsToRegexPatterns(List.of(name));
return accessControlEntryRepository.findAll()
return findAllRelatedToNamespace(namespace)
.stream()
.filter(acl -> acl.getMetadata().getNamespace().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(namespace.getMetadata().getName())
|| acl.getSpec().getGrantedTo().equals(PUBLIC_GRANTED_TO))
.filter(acl -> RegexUtils.filterByPattern(acl.getMetadata().getName(), nameFilterPatterns))
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,14 @@ void shouldGetAcl() {
.build();

when(namespaceService.findByName("test")).thenReturn(Optional.of(namespace));
when(aclService.findByWildcardNameRelatedToNamespace(namespace, "ace6"))
.thenReturn(List.of());
when(aclService.findByWildcardNameRelatedToNamespace(namespace, "ace4"))
.thenReturn(List.of());
when(aclService.findByWildcardNameRelatedToNamespace(namespace, "ace3"))
.thenReturn(List.of(aceTopicPrefixedReadTestToNamespaceOther));
when(aclService.findByWildcardNameRelatedToNamespace(namespace, "ace5"))
.thenReturn(List.of(aceTopicPrefixedReadNamespaceOtherToTest));
when(aclService.findAllRelatedToNamespace(namespace)).thenReturn(
List.of(aceTopicPrefixedReadTestToNamespaceOther, aceTopicPrefixedReadNamespaceOtherToTest));

// Name not in list
Optional<AccessControlEntry> result1 = accessControlListController.get("test", "ace6");
assertTrue(result1.isEmpty());
assertTrue(accessControlListController.get("test", "ace6").isEmpty());

// Not granted to or assigned by me
Optional<AccessControlEntry> result2 = accessControlListController.get("test", "ace4");
assertTrue(result2.isEmpty());
assertTrue(accessControlListController.get("test", "ace4").isEmpty());

// Assigned by me
Optional<AccessControlEntry> result3 = accessControlListController.get("test", "ace3");
Expand Down

0 comments on commit adf0587

Please sign in to comment.