ActivityPermissionsFilter extends CheMethodInvokerFilter { @Override protected void filter(GenericResourceMethod genericResourceMethod, Object[] arguments) throws ApiException { final String methodName = genericResourceMethod.getMethod().getName(); final Subject currentSubject = EnvironmentContext.getCurrent().getSubject(); String domain; String action; String instance; switch (methodName) { case "active": domain = WorkspaceDomain.DOMAIN_ID; instance = (String) arguments[0]; action = WorkspaceDomain.USE; break; case "getWorkspacesByActivity": domain = SystemDomain.DOMAIN_ID; instance = null; action = SystemDomain.MONITOR_SYSTEM_ACTION; break; default: throw new ForbiddenException("The user does not have permission to perform this operation"); } currentSubject.checkPermission(domain, instance, action); }    }
@Test(expectedExceptions = ForbiddenException.class) public void shouldThrowExceptionWhenCallingUnlistedMethod() throws Exception { GenericResourceMethod genericResourceMethod = Mockito.mock(GenericResourceMethod.class); when(genericResourceMethod.getMethod()) .thenReturn( this.getClass().getDeclaredMethod("shouldThrowExceptionWhenCallingUnlistedMethod")); Object[] argument = new Object[0]; permissionsFilter.filter(genericResourceMethod, argument); }