@Test( expectedExceptions = ForbiddenException.class, expectedExceptionsMessageRegExp = "User is not authorized to perform specified operation" ) public void shouldThrowForbiddenExceptionWhenRequestedUnknownMethod() throws Exception { final GenericResourceMethod mock = mock(GenericResourceMethod.class); Method injectLinks = InviteService.class.getMethod("getServiceDescriptor"); when(mock.getMethod()).thenReturn(injectLinks); permissionsFilter.filter(mock, new Object[] {}); }
@Override protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException { String methodName = genericMethodResource.getMethod().getName(); String domain; String instance; switch (methodName) { case INVITE_METHOD: InviteDto inviteDto = (InviteDto) arguments[0]; domain = inviteDto.getDomainId(); instance = inviteDto.getInstanceId(); break; case GET_INVITES_METHOD: case REMOVE_METHOD: domain = ((String) arguments[0]); instance = ((String) arguments[1]); break; default: throw new ForbiddenException("User is not authorized to perform specified operation"); } if (!EnvironmentContext.getCurrent() .getSubject() .hasPermission(domain, instance, SET_PERMISSIONS)) { throw new ForbiddenException("User is not authorized to invite into specified instance"); } }
InviteServicePermissionsFilter extends CheMethodInvokerFilter { @Override protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException { String methodName = genericMethodResource.getMethod().getName(); String domain; String instance; switch (methodName) { case INVITE_METHOD: InviteDto inviteDto = (InviteDto) arguments[0]; domain = inviteDto.getDomainId(); instance = inviteDto.getInstanceId(); break; case GET_INVITES_METHOD: case REMOVE_METHOD: domain = ((String) arguments[0]); instance = ((String) arguments[1]); break; default: throw new ForbiddenException("User is not authorized to perform specified operation"); } if (!EnvironmentContext.getCurrent() .getSubject() .hasPermission(domain, instance, SET_PERMISSIONS)) { throw new ForbiddenException("User is not authorized to invite into specified instance"); } } }
InviteServicePermissionsFilter extends CheMethodInvokerFilter { @Override protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException { String methodName = genericMethodResource.getMethod().getName(); String domain; String instance; switch (methodName) { case INVITE_METHOD: InviteDto inviteDto = (InviteDto) arguments[0]; domain = inviteDto.getDomainId(); instance = inviteDto.getInstanceId(); break; case GET_INVITES_METHOD: case REMOVE_METHOD: domain = ((String) arguments[0]); instance = ((String) arguments[1]); break; default: throw new ForbiddenException("User is not authorized to perform specified operation"); } if (!EnvironmentContext.getCurrent() .getSubject() .hasPermission(domain, instance, SET_PERMISSIONS)) { throw new ForbiddenException("User is not authorized to invite into specified instance"); } }  }
InviteServicePermissionsFilter extends CheMethodInvokerFilter { @Override protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException { String methodName = genericMethodResource.getMethod().getName(); String domain; String instance; switch (methodName) { case INVITE_METHOD: InviteDto inviteDto = (InviteDto) arguments[0]; domain = inviteDto.getDomainId(); instance = inviteDto.getInstanceId(); break; case GET_INVITES_METHOD: case REMOVE_METHOD: domain = ((String) arguments[0]); instance = ((String) arguments[1]); break; default: throw new ForbiddenException("User is not authorized to perform specified operation"); } if (!EnvironmentContext.getCurrent() .getSubject() .hasPermission(domain, instance, SET_PERMISSIONS)) { throw new ForbiddenException("User is not authorized to invite into specified instance"); } }   }
InviteServicePermissionsFilter extends CheMethodInvokerFilter { @Override protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException { String methodName = genericMethodResource.getMethod().getName(); String domain; String instance; switch (methodName) { case INVITE_METHOD: InviteDto inviteDto = (InviteDto) arguments[0]; domain = inviteDto.getDomainId(); instance = inviteDto.getInstanceId(); break; case GET_INVITES_METHOD: case REMOVE_METHOD: domain = ((String) arguments[0]); instance = ((String) arguments[1]); break; default: throw new ForbiddenException("User is not authorized to perform specified operation"); } if (!EnvironmentContext.getCurrent() .getSubject() .hasPermission(domain, instance, SET_PERMISSIONS)) { throw new ForbiddenException("User is not authorized to invite into specified instance"); } }    }