Search in sources :

Example 1 with SearchAclsResponse

use of io.confluent.kafkarest.entities.v3.SearchAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceTest method searchAcls_returnsMatchedAcls.

@Test
public void searchAcls_returnsMatchedAcls() {
    expect(aclManager.searchAcls(CLUSTER_ID, Acl.ResourceType.TOPIC, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    null, /* host= */
    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, /* resourceName= */
    "topic-1", Acl.PatternType.MATCH, /* principal= */
    "", /* host= */
    "", 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%3Aalice" + "&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%3Abob" + "&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());
}
Also used : SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 2 with SearchAclsResponse

use of io.confluent.kafkarest.entities.v3.SearchAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceIntegrationTest method createAliceAndBobAcls.

private void createAliceAndBobAcls() {
    SearchAclsResponse expectedPreCreateSearchResponse = SearchAclsResponse.create(AclDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(expectedSearchUrl).build()).setData(emptyList()).build());
    Response actualPreCreateSearchResponse = request(baseAclUrl, ImmutableMap.of("resource_type", "topic", "resource_name", "topic-1", "pattern_type", "match")).accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), actualPreCreateSearchResponse.getStatus());
    assertEquals(expectedPreCreateSearchResponse, actualPreCreateSearchResponse.readEntity(SearchAclsResponse.class));
    Response actualCreateAliceResponse = request(baseAclUrl).post(Entity.entity(CreateAclRequest.builder().setResourceType(Acl.ResourceType.TOPIC).setResourceName("*").setPatternType(Acl.PatternType.LITERAL).setPrincipal("User:alice").setHost("*").setOperation(Acl.Operation.READ).setPermission(Acl.Permission.ALLOW).build(), MediaType.APPLICATION_JSON));
    assertEquals(Status.CREATED.getStatusCode(), actualCreateAliceResponse.getStatus());
    assertEquals(expectedAliceUrl, actualCreateAliceResponse.getLocation().toString());
    Response actualCreateBobResponse = request(baseAclUrl).post(Entity.entity(CreateAclRequest.builder().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(), MediaType.APPLICATION_JSON));
    assertEquals(Status.CREATED.getStatusCode(), actualCreateBobResponse.getStatus());
    assertEquals(expectedBobUrl, actualCreateBobResponse.getLocation().toString());
    SearchAclsResponse expectedPostCreateSearchResponse = SearchAclsResponse.create(AclDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(expectedSearchUrl).build()).setData(Arrays.asList(ALICE_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedAliceUrl).build()).setClusterId(clusterId).build(), BOB_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedBobUrl).build()).setClusterId(clusterId).build())).build());
    Response actualPostCreateSearchResponse = request(baseAclUrl, ImmutableMap.of("resource_type", "topic", "resource_name", "topic-1", "pattern_type", "match")).accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), actualPostCreateSearchResponse.getStatus());
    assertEquals(expectedPostCreateSearchResponse, actualPostCreateSearchResponse.readEntity(SearchAclsResponse.class));
}
Also used : SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Response(javax.ws.rs.core.Response) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse)

Example 3 with SearchAclsResponse

use of io.confluent.kafkarest.entities.v3.SearchAclsResponse in project kafka-rest by confluentinc.

the class AclsResourceIntegrationTest method testCreateSearchAndSeparateDelete.

@Test
public void testCreateSearchAndSeparateDelete() {
    createAliceAndBobAcls();
    DeleteAclsResponse expectedDeleteAliceResponse = DeleteAclsResponse.create(singletonList(ALICE_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedAliceUrl).build()).setClusterId(clusterId).build()));
    Client webClient = getClient();
    restApp.configureBaseApplication(webClient);
    Response actualDeleteAliceResponse = webClient.target(expectedAliceUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.OK.getStatusCode(), actualDeleteAliceResponse.getStatus());
    assertEquals(expectedDeleteAliceResponse, actualDeleteAliceResponse.readEntity(DeleteAclsResponse.class));
    DeleteAclsResponse expectedDeleteBobResponse = DeleteAclsResponse.create(singletonList(BOB_ACL_DATA.setMetadata(Resource.Metadata.builder().setSelf(expectedBobUrl).build()).setClusterId(clusterId).build()));
    Response actualDeleteBobResponse = webClient.target(expectedBobUrl).request().accept(MediaType.APPLICATION_JSON).delete();
    assertEquals(Status.OK.getStatusCode(), actualDeleteBobResponse.getStatus());
    assertEquals(expectedDeleteBobResponse, actualDeleteBobResponse.readEntity(DeleteAclsResponse.class));
    SearchAclsResponse expectedPostDeleteSearchResponse = SearchAclsResponse.create(AclDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(expectedSearchUrl).build()).setData(emptyList()).build());
    Response actualPostDeleteSearchResponse = request(baseAclUrl, ImmutableMap.of("resource_type", "topic", "resource_name", "topic-1", "pattern_type", "match")).accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), actualPostDeleteSearchResponse.getStatus());
    assertEquals(expectedPostDeleteSearchResponse, actualPostDeleteSearchResponse.readEntity(SearchAclsResponse.class));
}
Also used : DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Response(javax.ws.rs.core.Response) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) SearchAclsResponse(io.confluent.kafkarest.entities.v3.SearchAclsResponse) DeleteAclsResponse(io.confluent.kafkarest.entities.v3.DeleteAclsResponse) Client(javax.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Aggregations

SearchAclsResponse (io.confluent.kafkarest.entities.v3.SearchAclsResponse)3 DeleteAclsResponse (io.confluent.kafkarest.entities.v3.DeleteAclsResponse)2 Response (javax.ws.rs.core.Response)2 Test (org.junit.jupiter.api.Test)2 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 Client (javax.ws.rs.client.Client)1