Search in sources :

Example 31 with ContainerRequestContext

use of javax.ws.rs.container.ContainerRequestContext in project dropwizard by dropwizard.

the class AuthFilterTest method isSecureShouldStayTheSame.

@Test
void isSecureShouldStayTheSame() throws Exception {
    ContainerRequestContext requestContext = new FakeSecureRequestContext();
    new SimpleAuthFilter().filter(requestContext);
    assertTrue(requestContext.getSecurityContext().isSecure());
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Test(org.junit.jupiter.api.Test)

Example 32 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method setMock.

private ContainerRequestContext setMock(String authorization, String username, String password) {
    ContainerRequestContext requestContext = mock(ContainerRequestContext.class);
    when(requestContext.getMethod()).thenReturn(HttpMethod.GET);
    when(requestContext.getHeaderString(JaasBasicAuthFilter.AUTHORIZATION)).thenReturn(authHeader(authorization, username, password));
    return requestContext;
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext)

Example 33 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testUnknownCredentialsFile.

@Test
public void testUnknownCredentialsFile() throws IOException {
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", "/tmp/testcrednetial");
    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 34 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testEmptyCredentialsFile.

@Test
public void testEmptyCredentialsFile() throws IOException {
    File credentialFile = setupPropertyLoginFile(false);
    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 35 with ContainerRequestContext

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

the class JaasBasicAuthFilterTest method testBadPassword.

@Test
public void testBadPassword() throws IOException {
    File credentialFile = setupPropertyLoginFile(true);
    JaasBasicAuthFilter jaasBasicAuthFilter = setupJaasFilter("KafkaConnect", credentialFile.getPath());
    ContainerRequestContext requestContext = setMock("Basic", "user", "password1");
    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)

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