class FactoryPermissionsFilter extends CheMethodInvokerFilter {

  @Override
  protected void filter(GenericResourceMethod genericResourceMethod, Object[] arguments)
      throws ApiException {
    final String methodName = genericResourceMethod.getMethod().getName();

    final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();

    switch (methodName) {
      case "getFactoryJson":
        {
          String workspaceId = ((String) arguments[0]);

          currentSubject.checkPermission(
              WorkspaceDomain.DOMAIN_ID, workspaceId, WorkspaceDomain.READ);
          return;
        }
      case "removeFactory":
        checkSubjectIsCreator((String) arguments[0], currentSubject, "remove");
        return;
      case "updateFactory":
        checkSubjectIsCreator((String) arguments[0], currentSubject, "update");
        return;

      case "getFactory":
      case "saveFactory":
      case "getFactoryByAttribute":
      case "resolveFactory":
        // public methods
        // do nothing
        return;

      default:
        throw new ForbiddenException("The user does not have permission to perform this operation");
    }
  }

  @Inject public  FactoryPermissionsFilter(FactoryManager factoryManager);

}