@Test public void searchAcls_returnsMatchedAcls() { expect( aclManager.searchAcls( CLUSTER_ID, Acl.ResourceType.TOPIC, "topic-1", Acl.PatternType.MATCH, null, null, Acl.Operation.ANY, Acl.Permission.ALLOW)) .andReturn(completedFuture(Arrays.asList(ACL_1, ACL_2))); replay(aclManager); FakeAsyncResponse response = new FakeAsyncResponse(); aclsResource.searchAcls( response, CLUSTER_ID, Acl.ResourceType.TOPIC, "topic-1", Acl.PatternType.MATCH, "", "", Acl.Operation.ANY, Acl.Permission.ALLOW); SearchAclsResponse expected = SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=topic-1" + "&pattern_type=MATCH" + "&principal=" + "&host=" + "&operation=ANY" + "&permission=ALLOW") .build()) .setData( Arrays.asList( AclData.builder() .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=*" + "&pattern_type=LITERAL" + "&principal=User:alice" + "&host=*" + "&operation=READ" + "&permission=ALLOW") .build()) .setClusterId(CLUSTER_ID) .setResourceType(Acl.ResourceType.TOPIC) .setResourceName("*") .setPatternType(Acl.PatternType.LITERAL) .setPrincipal("User:alice") .setHost("*") .setOperation(Acl.Operation.READ) .setPermission(Acl.Permission.ALLOW) .build(), AclData.builder() .setMetadata( Resource.Metadata.builder() .setSelf( "/v3/clusters/cluster-1/acls" + "?resource_type=TOPIC" + "&resource_name=topic-" + "&pattern_type=PREFIXED" + "&principal=User:bob" + "&host=1.2.3.4" + "&operation=WRITE" + "&permission=ALLOW") .build()) .setClusterId(CLUSTER_ID) .setResourceType(Acl.ResourceType.TOPIC) .setResourceName("topic-") .setPatternType(Acl.PatternType.PREFIXED) .setPrincipal("User:bob") .setHost("1.2.3.4") .setOperation(Acl.Operation.WRITE) .setPermission(Acl.Permission.ALLOW) .build())) .build()); assertEquals(expected, response.getValue()); }
@GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") public void searchAcls( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType, @QueryParam("resource_name") @DefaultValue("") String resourceName, @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType, @QueryParam("principal") @DefaultValue("") String principal, @QueryParam("host") @DefaultValue("") String host, @QueryParam("operation") @DefaultValue("any") Operation operation, @QueryParam("permission") @DefaultValue("any") Permission permission ) { if (resourceType == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (patternType == Acl.PatternType.UNKNOWN) { throw new BadRequestException("pattern_type cannot be UNKNOWN"); } if (operation == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (permission == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<SearchAclsResponse> response = aclManager.get() .searchAcls( clusterId, resourceType, resourceName.isEmpty() ? null : resourceName, patternType, principal.isEmpty() ? null : principal, host.isEmpty() ? null : host, operation, permission) .thenApply( acls -> SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", resourceType.name()) .putQueryParameter("resource_name", resourceName) .putQueryParameter("pattern_type", patternType.name()) .putQueryParameter("principal", principal) .putQueryParameter("host", host) .putQueryParameter("operation", operation.name()) .putQueryParameter("permission", permission.name()) .build()) .build()) .setData( acls.stream() .map(this::toAclData) .sorted( Comparator.comparing(AclData::getResourceType) .thenComparing(AclData::getResourceName) .thenComparing(AclData::getPatternType) .thenComparing(AclData::getPrincipal) .thenComparing(AclData::getHost) .thenComparing(AclData::getOperation) .thenComparing(AclData::getPermission)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); }
AclsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") public void searchAcls( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType, @QueryParam("resource_name") @DefaultValue("") String resourceName, @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType, @QueryParam("principal") @DefaultValue("") String principal, @QueryParam("host") @DefaultValue("") String host, @QueryParam("operation") @DefaultValue("any") Operation operation, @QueryParam("permission") @DefaultValue("any") Permission permission ) { if (resourceType == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (patternType == Acl.PatternType.UNKNOWN) { throw new BadRequestException("pattern_type cannot be UNKNOWN"); } if (operation == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (permission == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<SearchAclsResponse> response = aclManager.get() .searchAcls( clusterId, resourceType, resourceName.isEmpty() ? null : resourceName, patternType, principal.isEmpty() ? null : principal, host.isEmpty() ? null : host, operation, permission) .thenApply( acls -> SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", resourceType.name()) .putQueryParameter("resource_name", resourceName) .putQueryParameter("pattern_type", patternType.name()) .putQueryParameter("principal", principal) .putQueryParameter("host", host) .putQueryParameter("operation", operation.name()) .putQueryParameter("permission", permission.name()) .build()) .build()) .setData( acls.stream() .map(this::toAclData) .sorted( Comparator.comparing(AclData::getResourceType) .thenComparing(AclData::getResourceName) .thenComparing(AclData::getPatternType) .thenComparing(AclData::getPrincipal) .thenComparing(AclData::getHost) .thenComparing(AclData::getOperation) .thenComparing(AclData::getPermission)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } }
AclsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") public void searchAcls( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType, @QueryParam("resource_name") @DefaultValue("") String resourceName, @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType, @QueryParam("principal") @DefaultValue("") String principal, @QueryParam("host") @DefaultValue("") String host, @QueryParam("operation") @DefaultValue("any") Operation operation, @QueryParam("permission") @DefaultValue("any") Permission permission ) { if (resourceType == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (patternType == Acl.PatternType.UNKNOWN) { throw new BadRequestException("pattern_type cannot be UNKNOWN"); } if (operation == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (permission == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<SearchAclsResponse> response = aclManager.get() .searchAcls( clusterId, resourceType, resourceName.isEmpty() ? null : resourceName, patternType, principal.isEmpty() ? null : principal, host.isEmpty() ? null : host, operation, permission) .thenApply( acls -> SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", resourceType.name()) .putQueryParameter("resource_name", resourceName) .putQueryParameter("pattern_type", patternType.name()) .putQueryParameter("principal", principal) .putQueryParameter("host", host) .putQueryParameter("operation", operation.name()) .putQueryParameter("permission", permission.name()) .build()) .build()) .setData( acls.stream() .map(this::toAclData) .sorted( Comparator.comparing(AclData::getResourceType) .thenComparing(AclData::getResourceName) .thenComparing(AclData::getPatternType) .thenComparing(AclData::getPrincipal) .thenComparing(AclData::getHost) .thenComparing(AclData::getOperation) .thenComparing(AclData::getPermission)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  AclsResource(Provider<AclManager> aclManager, UrlFactory urlFactory); }
AclsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") public void searchAcls( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType, @QueryParam("resource_name") @DefaultValue("") String resourceName, @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType, @QueryParam("principal") @DefaultValue("") String principal, @QueryParam("host") @DefaultValue("") String host, @QueryParam("operation") @DefaultValue("any") Operation operation, @QueryParam("permission") @DefaultValue("any") Permission permission ) { if (resourceType == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (patternType == Acl.PatternType.UNKNOWN) { throw new BadRequestException("pattern_type cannot be UNKNOWN"); } if (operation == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (permission == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<SearchAclsResponse> response = aclManager.get() .searchAcls( clusterId, resourceType, resourceName.isEmpty() ? null : resourceName, patternType, principal.isEmpty() ? null : principal, host.isEmpty() ? null : host, operation, permission) .thenApply( acls -> SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", resourceType.name()) .putQueryParameter("resource_name", resourceName) .putQueryParameter("pattern_type", patternType.name()) .putQueryParameter("principal", principal) .putQueryParameter("host", host) .putQueryParameter("operation", operation.name()) .putQueryParameter("permission", permission.name()) .build()) .build()) .setData( acls.stream() .map(this::toAclData) .sorted( Comparator.comparing(AclData::getResourceType) .thenComparing(AclData::getResourceName) .thenComparing(AclData::getPatternType) .thenComparing(AclData::getPrincipal) .thenComparing(AclData::getHost) .thenComparing(AclData::getOperation) .thenComparing(AclData::getPermission)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  AclsResource(Provider<AclManager> aclManager, UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") void searchAcls(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType,
      @QueryParam("resource_name") @DefaultValue("") String resourceName,
      @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType,
      @QueryParam("principal") @DefaultValue("") String principal,
      @QueryParam("host") @DefaultValue("") String host,
      @QueryParam("operation") @DefaultValue("any") Operation operation,
      @QueryParam("permission") @DefaultValue("any") Permission permission
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") void createAcl(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateAclRequest request
  ); @DELETE @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.delete") void deleteAcls(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType,
      @QueryParam("resource_name") @DefaultValue("") String resourceName,
      @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType,
      @QueryParam("principal") @DefaultValue("") String principal,
      @QueryParam("host") @DefaultValue("") String host,
      @QueryParam("operation") @DefaultValue("any") Operation operation,
      @QueryParam("permission") @DefaultValue("any") Permission permission
  ); AclData toAclData(Acl acl); }
AclsResource { @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") public void searchAcls( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType, @QueryParam("resource_name") @DefaultValue("") String resourceName, @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType, @QueryParam("principal") @DefaultValue("") String principal, @QueryParam("host") @DefaultValue("") String host, @QueryParam("operation") @DefaultValue("any") Operation operation, @QueryParam("permission") @DefaultValue("any") Permission permission ) { if (resourceType == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (patternType == Acl.PatternType.UNKNOWN) { throw new BadRequestException("pattern_type cannot be UNKNOWN"); } if (operation == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (permission == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<SearchAclsResponse> response = aclManager.get() .searchAcls( clusterId, resourceType, resourceName.isEmpty() ? null : resourceName, patternType, principal.isEmpty() ? null : principal, host.isEmpty() ? null : host, operation, permission) .thenApply( acls -> SearchAclsResponse.create( AclDataList.builder() .setMetadata( ResourceCollection.Metadata.builder() .setSelf( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", resourceType.name()) .putQueryParameter("resource_name", resourceName) .putQueryParameter("pattern_type", patternType.name()) .putQueryParameter("principal", principal) .putQueryParameter("host", host) .putQueryParameter("operation", operation.name()) .putQueryParameter("permission", permission.name()) .build()) .build()) .setData( acls.stream() .map(this::toAclData) .sorted( Comparator.comparing(AclData::getResourceType) .thenComparing(AclData::getResourceName) .thenComparing(AclData::getPatternType) .thenComparing(AclData::getPrincipal) .thenComparing(AclData::getHost) .thenComparing(AclData::getOperation) .thenComparing(AclData::getPermission)) .collect(Collectors.toList())) .build())); AsyncResponses.asyncResume(asyncResponse, response); } @Inject  AclsResource(Provider<AclManager> aclManager, UrlFactory urlFactory); @GET @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.list") void searchAcls(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType,
      @QueryParam("resource_name") @DefaultValue("") String resourceName,
      @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType,
      @QueryParam("principal") @DefaultValue("") String principal,
      @QueryParam("host") @DefaultValue("") String host,
      @QueryParam("operation") @DefaultValue("any") Operation operation,
      @QueryParam("permission") @DefaultValue("any") Permission permission
  ); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") void createAcl(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @Valid CreateAclRequest request
  ); @DELETE @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.delete") void deleteAcls(
      @Suspended AsyncResponse asyncResponse,
      @PathParam("clusterId") String clusterId,
      @QueryParam("resource_type") @DefaultValue("any") ResourceType resourceType,
      @QueryParam("resource_name") @DefaultValue("") String resourceName,
      @QueryParam("pattern_type") @DefaultValue("any") PatternType patternType,
      @QueryParam("principal") @DefaultValue("") String principal,
      @QueryParam("host") @DefaultValue("") String host,
      @QueryParam("operation") @DefaultValue("any") Operation operation,
      @QueryParam("permission") @DefaultValue("any") Permission permission
  ); AclData toAclData(Acl acl);  }