diff --git a/src/main/java/com/michelin/ns4kafka/controller/acl/AclController.java b/src/main/java/com/michelin/ns4kafka/controller/acl/AclController.java index 90962b4b..07dfc6f4 100644 --- a/src/main/java/com/michelin/ns4kafka/controller/acl/AclController.java +++ b/src/main/java/com/michelin/ns4kafka/controller/acl/AclController.java @@ -76,14 +76,17 @@ public List list(String namespace, Optional 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 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(); } /** diff --git a/src/main/java/com/michelin/ns4kafka/service/AclService.java b/src/main/java/com/michelin/ns4kafka/service/AclService.java index af53e8cd..cb5508d2 100644 --- a/src/main/java/com/michelin/ns4kafka/service/AclService.java +++ b/src/main/java/com/michelin/ns4kafka/service/AclService.java @@ -276,6 +276,21 @@ public List 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 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. @@ -316,11 +331,8 @@ public List findByWildcardNameGrantedByNamespace(Namespace n */ public List findByWildcardNameRelatedToNamespace(Namespace namespace, String name) { List 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(); } diff --git a/src/test/java/com/michelin/ns4kafka/controller/AclControllerTest.java b/src/test/java/com/michelin/ns4kafka/controller/AclControllerTest.java index 25f6f4d4..9171e19a 100644 --- a/src/test/java/com/michelin/ns4kafka/controller/AclControllerTest.java +++ b/src/test/java/com/michelin/ns4kafka/controller/AclControllerTest.java @@ -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 result1 = accessControlListController.get("test", "ace6"); - assertTrue(result1.isEmpty()); + assertTrue(accessControlListController.get("test", "ace6").isEmpty()); // Not granted to or assigned by me - Optional result2 = accessControlListController.get("test", "ace4"); - assertTrue(result2.isEmpty()); + assertTrue(accessControlListController.get("test", "ace4").isEmpty()); // Assigned by me Optional result3 = accessControlListController.get("test", "ace3");