Search in sources :

Example 1 with ApiConfig

use of org.ff4j.web.ApiConfig 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 ApiConfig

use of org.ff4j.web.ApiConfig in project ff4j by ff4j.

the class SampleFF4jJersey2Application method getWebApiConfiguration.

@Override
protected ApiConfig getWebApiConfiguration() {
    ApiConfig fac = new ApiConfig(ff4j);
    fac.setDocumentation(true);
    fac.setPort(3388);
    fac.setHost("localhost");
    fac.setWebContext("webapi");
    return fac;
}
Also used : ApiConfig(org.ff4j.web.ApiConfig)

Example 3 with ApiConfig

use of org.ff4j.web.ApiConfig in project ff4j by ff4j.

the class SecurityAuthenticationFilterTest method testUnAuthorizedApiKey.

@Test(expected = WebApplicationException.class)
public void testUnAuthorizedApiKey() throws IOException {
    // Given
    FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
    ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
    when(mockRequest.getHeaderString("Authorization")).thenReturn("apiKey=12");
    when(mockRequest.getMethod()).thenReturn("GET");
    UriInfo mockUriInfo = mock(UriInfo.class);
    when(mockUriInfo.getPath()).thenReturn("someURL");
    when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
    // Define ApiConfig
    FF4jAuthenticationFilter.setApiConfig(new ApiConfig());
    // When
    faf.filter(mockRequest);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) FF4jAuthenticationFilter(org.ff4j.web.api.security.FF4jAuthenticationFilter) ApiConfig(org.ff4j.web.ApiConfig) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 4 with ApiConfig

use of org.ff4j.web.ApiConfig in project ff4j by ff4j.

the class SecurityAuthenticationFilterTest method testAuthorizedApiKey.

@Test
public void testAuthorizedApiKey() throws IOException {
    // Define ApiConfig
    FF4jAuthenticationFilter.setApiConfig(new ApiConfig().createApiKey("12", true, true, Util.set("USER")));
    // Given
    FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
    ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
    when(mockRequest.getHeaderString("Authorization")).thenReturn("apiKey=12");
    when(mockRequest.getMethod()).thenReturn("GET");
    UriInfo mockUriInfo = mock(UriInfo.class);
    when(mockUriInfo.getPath()).thenReturn("someURL");
    when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
    // When
    faf.filter(mockRequest);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) FF4jAuthenticationFilter(org.ff4j.web.api.security.FF4jAuthenticationFilter) ApiConfig(org.ff4j.web.ApiConfig) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 5 with ApiConfig

use of org.ff4j.web.ApiConfig in project ff4j by ff4j.

the class SecurityAuthorizationFilterTest method testAccessors.

@Test
public void testAccessors() throws IOException {
    // Given
    FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
    Assert.assertNull(faf.getInfo());
    Assert.assertNull(FF4jAuthorizationFilter.getApiConfig());
    FF4jAuthorizationFilter.setApiConfig(new ApiConfig());
    Assert.assertNotNull(FF4jAuthorizationFilter.getApiConfig());
}
Also used : FF4jAuthorizationFilter(org.ff4j.web.api.security.FF4jAuthorizationFilter) ApiConfig(org.ff4j.web.ApiConfig) Test(org.junit.Test)

Aggregations

ApiConfig (org.ff4j.web.ApiConfig)10 Test (org.junit.Test)8 ApiConfigBuilder (org.ff4j.web.ApiConfigBuilder)3 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)2 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)2 UriInfo (javax.ws.rs.core.UriInfo)2 FF4j (org.ff4j.FF4j)2 FF4jAuthenticationFilter (org.ff4j.web.api.security.FF4jAuthenticationFilter)2 FF4jSecurityContextFilter (org.ff4j.web.api.security.FF4jSecurityContextFilter)2 Set (java.util.Set)1 FF4JApiApplication (org.ff4j.web.api.FF4JApiApplication)1 FF4jAuthorizationFilter (org.ff4j.web.api.security.FF4jAuthorizationFilter)1