use of javax.ws.rs.container.ResourceInfo in project candlepin by candlepin.
the class VerifyAuthorizationFilter method runFilter.
@Override
public void runFilter(ContainerRequestContext requestContext) {
HttpRequest request = ResteasyProviderFactory.getContextData(HttpRequest.class);
Principal principal = (Principal) requestContext.getSecurityContext().getUserPrincipal();
ResourceInfo resourceInfo = ResteasyProviderFactory.getContextData(ResourceInfo.class);
Method method = resourceInfo.getResourceMethod();
if (log.isDebugEnabled()) {
log.debug("Authorization check for {} mapping to {}.{}", requestContext.getUriInfo().getPath(), method.getDeclaringClass().getName(), method.getName());
}
Map<Verify, Object> argMap = getArguments(request, method);
// Couldn't find a match in Resteasy for method
if (argMap.isEmpty()) {
/* It would also be possible to get here if a super-admin only method
* were inadvertently being filtered through this filter. Normally the
* AuthorizationFeature takes care of sending methods without any @Verify
* annotations through the SuperAdminAuthorizationFilter */
throw new IseException("Could not get parameters for " + method);
}
Access defaultAccess = getDefaultAccess(method);
if (!hasAccess(argMap, principal, defaultAccess)) {
denyAccess(principal, method);
}
}
use of javax.ws.rs.container.ResourceInfo 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 javax.ws.rs.container.ResourceInfo 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
}
use of javax.ws.rs.container.ResourceInfo 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
}
Aggregations