@Test public void createAcl_createsAcl() { expect( aclManager.createAcl( CLUSTER_ID, Acl.ResourceType.TOPIC, "*", Acl.PatternType.LITERAL, "User:alice", "*", Acl.Operation.READ, Acl.Permission.ALLOW)) .andReturn(completedFuture( null)); replay(aclManager); FakeAsyncResponse response = new FakeAsyncResponse(); aclsResource.createAcl( response, CLUSTER_ID, CreateAclRequest.builder() .setResourceType(Acl.ResourceType.TOPIC) .setResourceName("*") .setPatternType(Acl.PatternType.LITERAL) .setPrincipal("User:alice") .setHost("*") .setOperation(Acl.Operation.READ) .setPermission(Acl.Permission.ALLOW) .build()); assertNull(response.getValue()); assertNull(response.getException()); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") public void createAcl( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @Valid CreateAclRequest request ) { if (request.getResourceType() == Acl.ResourceType.ANY || request.getResourceType() == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (request.getPatternType() == Acl.PatternType.ANY || request.getPatternType() == Acl.PatternType.MATCH || request.getPatternType() == Acl.PatternType.UNKNOWN) { throw new BadRequestException( String.format("pattern_type cannot be %s", request.getPatternType())); } if (request.getOperation() == Acl.Operation.ANY || request.getOperation() == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (request.getPermission() == Acl.Permission.ANY || request.getPermission() == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<Void> response = aclManager.get() .createAcl( clusterId, request.getResourceType(), request.getResourceName(), request.getPatternType(), request.getPrincipal(), request.getHost(), request.getOperation(), request.getPermission()); AsyncResponseBuilder.from( Response.status(Status.CREATED) .location( URI.create( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", request.getResourceType().name()) .putQueryParameter("resource_name", request.getResourceName()) .putQueryParameter("pattern_type", request.getPatternType().name()) .putQueryParameter("principal", request.getPrincipal()) .putQueryParameter("host", request.getHost()) .putQueryParameter("operation", request.getOperation().name()) .putQueryParameter("permission", request.getPermission().name()) .build()))) .entity(response) .asyncResume(asyncResponse); }
AclsResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") public void createAcl( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @Valid CreateAclRequest request ) { if (request.getResourceType() == Acl.ResourceType.ANY || request.getResourceType() == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (request.getPatternType() == Acl.PatternType.ANY || request.getPatternType() == Acl.PatternType.MATCH || request.getPatternType() == Acl.PatternType.UNKNOWN) { throw new BadRequestException( String.format("pattern_type cannot be %s", request.getPatternType())); } if (request.getOperation() == Acl.Operation.ANY || request.getOperation() == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (request.getPermission() == Acl.Permission.ANY || request.getPermission() == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<Void> response = aclManager.get() .createAcl( clusterId, request.getResourceType(), request.getResourceName(), request.getPatternType(), request.getPrincipal(), request.getHost(), request.getOperation(), request.getPermission()); AsyncResponseBuilder.from( Response.status(Status.CREATED) .location( URI.create( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", request.getResourceType().name()) .putQueryParameter("resource_name", request.getResourceName()) .putQueryParameter("pattern_type", request.getPatternType().name()) .putQueryParameter("principal", request.getPrincipal()) .putQueryParameter("host", request.getHost()) .putQueryParameter("operation", request.getOperation().name()) .putQueryParameter("permission", request.getPermission().name()) .build()))) .entity(response) .asyncResume(asyncResponse); } }
AclsResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") public void createAcl( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @Valid CreateAclRequest request ) { if (request.getResourceType() == Acl.ResourceType.ANY || request.getResourceType() == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (request.getPatternType() == Acl.PatternType.ANY || request.getPatternType() == Acl.PatternType.MATCH || request.getPatternType() == Acl.PatternType.UNKNOWN) { throw new BadRequestException( String.format("pattern_type cannot be %s", request.getPatternType())); } if (request.getOperation() == Acl.Operation.ANY || request.getOperation() == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (request.getPermission() == Acl.Permission.ANY || request.getPermission() == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<Void> response = aclManager.get() .createAcl( clusterId, request.getResourceType(), request.getResourceName(), request.getPatternType(), request.getPrincipal(), request.getHost(), request.getOperation(), request.getPermission()); AsyncResponseBuilder.from( Response.status(Status.CREATED) .location( URI.create( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", request.getResourceType().name()) .putQueryParameter("resource_name", request.getResourceName()) .putQueryParameter("pattern_type", request.getPatternType().name()) .putQueryParameter("principal", request.getPrincipal()) .putQueryParameter("host", request.getHost()) .putQueryParameter("operation", request.getOperation().name()) .putQueryParameter("permission", request.getPermission().name()) .build()))) .entity(response) .asyncResume(asyncResponse); } @Inject  AclsResource(Provider<AclManager> aclManager, UrlFactory urlFactory); }
AclsResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") public void createAcl( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @Valid CreateAclRequest request ) { if (request.getResourceType() == Acl.ResourceType.ANY || request.getResourceType() == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (request.getPatternType() == Acl.PatternType.ANY || request.getPatternType() == Acl.PatternType.MATCH || request.getPatternType() == Acl.PatternType.UNKNOWN) { throw new BadRequestException( String.format("pattern_type cannot be %s", request.getPatternType())); } if (request.getOperation() == Acl.Operation.ANY || request.getOperation() == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (request.getPermission() == Acl.Permission.ANY || request.getPermission() == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<Void> response = aclManager.get() .createAcl( clusterId, request.getResourceType(), request.getResourceName(), request.getPatternType(), request.getPrincipal(), request.getHost(), request.getOperation(), request.getPermission()); AsyncResponseBuilder.from( Response.status(Status.CREATED) .location( URI.create( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", request.getResourceType().name()) .putQueryParameter("resource_name", request.getResourceName()) .putQueryParameter("pattern_type", request.getPatternType().name()) .putQueryParameter("principal", request.getPrincipal()) .putQueryParameter("host", request.getHost()) .putQueryParameter("operation", request.getOperation().name()) .putQueryParameter("permission", request.getPermission().name()) .build()))) .entity(response) .asyncResume(asyncResponse); } @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 { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @PerformanceMetric("v3.acls.create") public void createAcl( @Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @Valid CreateAclRequest request ) { if (request.getResourceType() == Acl.ResourceType.ANY || request.getResourceType() == Acl.ResourceType.UNKNOWN) { throw new BadRequestException("resource_type cannot be ANY"); } if (request.getPatternType() == Acl.PatternType.ANY || request.getPatternType() == Acl.PatternType.MATCH || request.getPatternType() == Acl.PatternType.UNKNOWN) { throw new BadRequestException( String.format("pattern_type cannot be %s", request.getPatternType())); } if (request.getOperation() == Acl.Operation.ANY || request.getOperation() == Acl.Operation.UNKNOWN) { throw new BadRequestException("operation cannot be ANY"); } if (request.getPermission() == Acl.Permission.ANY || request.getPermission() == Acl.Permission.UNKNOWN) { throw new BadRequestException("permission cannot be ANY"); } CompletableFuture<Void> response = aclManager.get() .createAcl( clusterId, request.getResourceType(), request.getResourceName(), request.getPatternType(), request.getPrincipal(), request.getHost(), request.getOperation(), request.getPermission()); AsyncResponseBuilder.from( Response.status(Status.CREATED) .location( URI.create( urlFactory.newUrlBuilder() .appendPathSegment("v3") .appendPathSegment("clusters") .appendPathSegment(clusterId) .appendPathSegment("acls") .putQueryParameter("resource_type", request.getResourceType().name()) .putQueryParameter("resource_name", request.getResourceName()) .putQueryParameter("pattern_type", request.getPatternType().name()) .putQueryParameter("principal", request.getPrincipal()) .putQueryParameter("host", request.getHost()) .putQueryParameter("operation", request.getOperation().name()) .putQueryParameter("permission", request.getPermission().name()) .build()))) .entity(response) .asyncResume(asyncResponse); } @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);  }