Search in sources :

Example 71 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testUnknownLoginModule.

@Test
public void testUnknownLoginModule() throws IOException {
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect1", credentialFile.getPath());
    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) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 72 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testPostWithoutAppropriateCredential.

@Test
public void testPostWithoutAppropriateCredential() throws IOException {
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getPath()).thenReturn("connectors/connName/tasks");
    ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
    when(requestContext.getMethod()).thenReturn(HttpMethod.POST);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect1", credentialFile.getPath());
    jaasBasicAuthFilter.filter(requestContext);
    verify(uriInfo).getPath();
    verify(requestContext).getMethod();
    verify(requestContext).getUriInfo();
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) File(java.io.File) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.jupiter.api.Test)

Example 73 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testUnknownBearer.

@Test
public void testUnknownBearer() throws IOException {
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", credentialFile.getPath());
    ContainerRequestContext requestContext = setMock("Unknown", "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) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 74 with ContainerRequestContext

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

the class JaxrsContainerFilterTest method testResponseFilter.

@Test
public void testResponseFilter() throws Exception {
    Span span = new FakeSpan(SpanContext.INVALID, null);
    TagContext tagContext = mock(TagContext.class);
    HttpRequestContext context = JaxrsClientFilterTest.createHttpRequestContext(span, tagContext);
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getMatchedURIs()).thenReturn(Collections.singletonList("/resource/{route}"));
    ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
    when(requestContext.getProperty("opencensus.context")).thenReturn(context);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    ContainerResponseContext responseContext = mock(ContainerResponseContext.class);
    filter.filter(requestContext, responseContext);
    verify(requestContext).getProperty("opencensus.context");
    verify(responseContext, times(1)).getStatus();
}
Also used : FakeSpan(io.opencensus.contrib.http.jaxrs.JaxrsClientFilterTest.FakeSpan) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) TagContext(io.opencensus.tags.TagContext) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) HttpRequestContext(io.opencensus.contrib.http.HttpRequestContext) FakeSpan(io.opencensus.contrib.http.jaxrs.JaxrsClientFilterTest.FakeSpan) Span(io.opencensus.trace.Span) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 75 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project graylog2-server by Graylog2.

the class MessageExportFormatFilterTest method returns415IfAcceptedFormatIsNotEnabled.

@Test
void returns415IfAcceptedFormatIsNotEnabled() throws Exception {
    final ContainerRequestFilter filter = new MessageExportFormatFilter(Collections.singleton(disabledJsonExportFormat));
    final ContainerRequestContext requestContext = mockRequestContext(Collections.emptyList());
    filter.filter(requestContext);
    verifyRequestAborted(requestContext);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Test(org.junit.jupiter.api.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