Search in sources :

Example 36 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project kafka by apache.

the class JaasBasicAuthFilterTest method testNoFileOption.

@Test
public void testNoFileOption() throws IOException {
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", null);
    ContainerRequestContext requestContext = setMock("Basic", "user", "password");
    jaasBasicAuthFilter.filter(requestContext);
    verify(requestContext).abortWith(any(Response.class));
    verify(requestContext).getMethod();
    verify(requestContext).getHeaderString(JaasBasicAuthFilter.AUTHORIZATION);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Test(org.junit.jupiter.api.Test)

Example 37 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project kafka by apache.

the class JaasBasicAuthFilterTest method testPostNotChangingConnectorTask.

@Test
public void testPostNotChangingConnectorTask() throws IOException {
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getPath()).thenReturn("local:randomport/connectors/connName");
    ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
    when(requestContext.getMethod()).thenReturn(HttpMethod.POST);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    String authHeader = "Basic" + Base64.getEncoder().encodeToString(("user" + ":" + "password").getBytes());
    when(requestContext.getHeaderString(JaasBasicAuthFilter.AUTHORIZATION)).thenReturn(authHeader);
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", credentialFile.getPath());
    jaasBasicAuthFilter.filter(requestContext);
    verify(requestContext).abortWith(any(Response.class));
    verify(requestContext).getUriInfo();
    verify(requestContext).getUriInfo();
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) File(java.io.File) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.jupiter.api.Test)

Example 38 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project kafka by apache.

the class JaasBasicAuthFilterTest method testSuccess.

@Test
public void testSuccess() throws IOException {
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", credentialFile.getPath());
    ContainerRequestContext requestContext = setMock("Basic", "user", "password");
    jaasBasicAuthFilter.filter(requestContext);
    verify(requestContext).getMethod();
    verify(requestContext).getHeaderString(JaasBasicAuthFilter.AUTHORIZATION);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 39 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project kafka by apache.

the class JaasBasicAuthFilterTest method testBadCredential.

@Test
public void testBadCredential() throws IOException {
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", credentialFile.getPath());
    ContainerRequestContext requestContext = setMock("Basic", "user1", "password");
    jaasBasicAuthFilter.filter(requestContext);
    verify(requestContext).abortWith(any(Response.class));
    verify(requestContext).getMethod();
    verify(requestContext).getHeaderString(JaasBasicAuthFilter.AUTHORIZATION);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 40 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project instrumentation-java by census-instrumentation.

the class JaxrsContainerFilterTest method testRequestFilter.

@Test
public void testRequestFilter() throws Exception {
    UriInfo uriInfo = mock(UriInfo.class);
    ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    filter.filter(requestContext);
    verify(requestContext).setProperty(eq("opencensus.context"), any());
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)81 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)32 UriInfo (javax.ws.rs.core.UriInfo)23 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)22 Test (org.junit.jupiter.api.Test)18 Resource (org.glassfish.jersey.server.model.Resource)15 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)14 ApplicationHandler (org.glassfish.jersey.server.ApplicationHandler)12 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)10 File (java.io.File)8 ContainerResponseContext (javax.ws.rs.container.ContainerResponseContext)8 ResourceInfo (javax.ws.rs.container.ResourceInfo)8 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)8 IOException (java.io.IOException)7 URI (java.net.URI)6 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)6 FF4jAuthenticationFilter (org.ff4j.web.api.security.FF4jAuthenticationFilter)6 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)6 ApiKeyValidatorFilter (org.ff4j.web.api.filter.ApiKeyValidatorFilter)5