Search in sources :

Example 1 with FF4jAuthenticationFilter

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

the class SecurityAuthenticationFilterTest method testUnAuthorized1NoAuthorization.

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

Example 2 with FF4jAuthenticationFilter

use of org.ff4j.web.api.security.FF4jAuthenticationFilter 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 3 with FF4jAuthenticationFilter

use of org.ff4j.web.api.security.FF4jAuthenticationFilter 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 4 with FF4jAuthenticationFilter

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

the class SecurityAuthenticationFilterTest method testGETWadl.

@Test
public void testGETWadl() throws IOException {
    // Given
    FF4jAuthenticationFilter faf = new FF4jAuthenticationFilter();
    ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
    when(mockRequest.getMethod()).thenReturn("GET");
    UriInfo mockUriInfo = mock(UriInfo.class);
    when(mockUriInfo.getPath()).thenReturn("application.wadl");
    when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
    faf.filter(mockRequest);
}
Also used : ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) FF4jAuthenticationFilter(org.ff4j.web.api.security.FF4jAuthenticationFilter) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 5 with FF4jAuthenticationFilter

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

the class SecurityAuthenticationFilterTest method testUnAuthorizedInvalidValue.

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

Aggregations

ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)6 UriInfo (javax.ws.rs.core.UriInfo)6 FF4jAuthenticationFilter (org.ff4j.web.api.security.FF4jAuthenticationFilter)6 Test (org.junit.Test)6 ApiConfig (org.ff4j.web.ApiConfig)2