Search in sources :

Example 6 with FF4jAuthorizationFilter

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

the class SecurityAuthorizationFilterTest method testRoleAllowed.

@Test
public void testRoleAllowed() 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("USER")));
    when(mockRequest.getUriInfo()).thenReturn(mockUriInfo);
    // When
    faf.filter(mockRequest);
// Then expecte 403
}
Also used : FF4jAuthorizationFilter(org.ff4j.web.api.security.FF4jAuthorizationFilter) ResourceInfo(javax.ws.rs.container.ResourceInfo) FF4jSecurityContext(org.ff4j.web.api.security.FF4jSecurityContext) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

FF4jAuthorizationFilter (org.ff4j.web.api.security.FF4jAuthorizationFilter)6 Test (org.junit.Test)6 ContainerRequestContext (javax.ws.rs.container.ContainerRequestContext)5 ResourceInfo (javax.ws.rs.container.ResourceInfo)5 UriInfo (javax.ws.rs.core.UriInfo)5 FF4jSecurityContext (org.ff4j.web.api.security.FF4jSecurityContext)5 ApiConfig (org.ff4j.web.ApiConfig)1