Search in sources :

Example 1 with FF4jSecurityContextFilter

use of org.ff4j.web.api.security.FF4jSecurityContextFilter in project ff4j by ff4j.

the class SecurityFilterTest method testAuthorizedApiKey.

@Test
public void testAuthorizedApiKey() throws IOException {
    // Define ApiConfig
    FF4jSecurityContextFilter.setSecurityConfig(new ApiConfig().createApiKey("12", true, true, Util.set("USER")));
    // Given
    FF4jSecurityContextFilter faf = new FF4jSecurityContextFilter();
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getPath(true)).thenReturn("someURLl");
    when(mockRequest.getHeaderValue("Authorization")).thenReturn("apiKey=12");
    Assert.assertNotNull(faf);
    faf.filter(mockRequest);
}
Also used : ApiConfig(org.ff4j.web.ApiConfig) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) FF4jSecurityContextFilter(org.ff4j.web.api.security.FF4jSecurityContextFilter) Test(org.junit.Test)

Example 2 with FF4jSecurityContextFilter

use of org.ff4j.web.api.security.FF4jSecurityContextFilter in project ff4j by ff4j.

the class SecurityFilterTest method testContextFilterGetWadl.

@Test
public void testContextFilterGetWadl() {
    FF4jSecurityContextFilter fscf = new FF4jSecurityContextFilter();
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getPath(true)).thenReturn("application.wadl");
    fscf.filter(mockRequest);
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) FF4jSecurityContextFilter(org.ff4j.web.api.security.FF4jSecurityContextFilter) Test(org.junit.Test)

Example 3 with FF4jSecurityContextFilter

use of org.ff4j.web.api.security.FF4jSecurityContextFilter in project ff4j by ff4j.

the class SecurityFilterTest method testUnAuthorizedInvalidValue.

@Test(expected = WebApplicationException.class)
public void testUnAuthorizedInvalidValue() throws IOException {
    FF4jSecurityContextFilter faf = new FF4jSecurityContextFilter();
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getPath(true)).thenReturn("someURLl");
    when(mockRequest.getHeaderValue("Authorization")).thenReturn("12");
    Assert.assertNotNull(faf);
    faf.filter(mockRequest);
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) FF4jSecurityContextFilter(org.ff4j.web.api.security.FF4jSecurityContextFilter) Test(org.junit.Test)

Example 4 with FF4jSecurityContextFilter

use of org.ff4j.web.api.security.FF4jSecurityContextFilter in project ff4j by ff4j.

the class SecurityFilterTest method testNoAuthorizationAttributeInHeader.

@Test(expected = WebApplicationException.class)
public void testNoAuthorizationAttributeInHeader() throws IOException {
    FF4jSecurityContextFilter faf = new FF4jSecurityContextFilter();
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getPath(true)).thenReturn("someURLl");
    when(mockRequest.getHeaderValue("Authorization")).thenReturn(null);
    Assert.assertNotNull(faf);
    faf.filter(mockRequest);
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) FF4jSecurityContextFilter(org.ff4j.web.api.security.FF4jSecurityContextFilter) Test(org.junit.Test)

Example 5 with FF4jSecurityContextFilter

use of org.ff4j.web.api.security.FF4jSecurityContextFilter in project ff4j by ff4j.

the class SecurityFilterTest method testUnAuthorized1NoAuthorization.

@Test(expected = WebApplicationException.class)
public void testUnAuthorized1NoAuthorization() throws IOException {
    // Given
    FF4jSecurityContextFilter faf = new FF4jSecurityContextFilter();
    ContainerRequest mockRequest = mock(ContainerRequest.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getPath(true)).thenReturn("someURLl");
    Assert.assertNotNull(faf);
    faf.filter(mockRequest);
}
Also used : ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) FF4jSecurityContextFilter(org.ff4j.web.api.security.FF4jSecurityContextFilter) Test(org.junit.Test)

Aggregations

ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)6 FF4jSecurityContextFilter (org.ff4j.web.api.security.FF4jSecurityContextFilter)6 Test (org.junit.Test)6 ApiConfig (org.ff4j.web.ApiConfig)2