use of org.ff4j.web.api.security.FF4jAuthorizationFilter 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());
}
use of org.ff4j.web.api.security.FF4jAuthorizationFilter in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testRoleNothing.
@Test
public void testRoleNothing() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = new ResourceInfo() {
public Method getResourceMethod() {
return methodNothing;
}
public Class<?> getResourceClass() {
return targetResource;
}
};
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// OK
}
use of org.ff4j.web.api.security.FF4jAuthorizationFilter in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testPermitAll.
@Test
public void testPermitAll() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = mock(ResourceInfo.class);
when(mockResInfo.getResourceMethod()).thenReturn(methodPermit);
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// Then expecte 403
}
use of org.ff4j.web.api.security.FF4jAuthorizationFilter in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testDenyAll.
@Test(expected = WebApplicationException.class)
public void testDenyAll() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = mock(ResourceInfo.class);
when(mockResInfo.getResourceMethod()).thenReturn(methodDeny);
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("USER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// Then expecte 403
}
use of org.ff4j.web.api.security.FF4jAuthorizationFilter in project ff4j by ff4j.
the class SecurityAuthorizationFilterTest method testRoleAllowedInvalid.
@Test(expected = WebApplicationException.class)
public void testRoleAllowedInvalid() throws IOException {
// Given
FF4jAuthorizationFilter faf = new FF4jAuthorizationFilter();
ContainerRequestContext mockRequest = mock(ContainerRequestContext.class);
UriInfo mockUriInfo = mock(UriInfo.class);
ResourceInfo mockResInfo = new ResourceInfo() {
public Method getResourceMethod() {
return methodRole;
}
public Class<?> getResourceClass() {
return targetResource;
}
};
faf.setInfo(mockResInfo);
when(mockUriInfo.getPath()).thenReturn("localhost");
when(mockRequest.getSecurityContext()).thenReturn(new FF4jSecurityContext("user", "", Util.set("OTHER")));
when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
// When
faf.filter(mockRequest);
// Then expecte 403
}
Aggregations