示例#1
0
  @Override
  public ServiceResults postEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {
    if ("rolenames".equalsIgnoreCase(dictionary)) {

      if (context.parameterCount() == 1) {

        String name = payload.getStringProperty("name");
        if (isBlank(name)) {
          return null;
        }

        String title = payload.getStringProperty("title");
        if (isBlank(title)) {
          title = name;
        }

        return newApplicationRole(name, title);

      } else if (context.parameterCount() == 2) {

        String roleName = context.getParameters().get(1).getName();
        if (isBlank(roleName)) {
          return null;
        }

        String permission = payload.getStringProperty("permission");
        if (isBlank(permission)) {
          return null;
        }

        return grantApplicationRolePermission(roleName, permission);
      }
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }
  @Override
  public ServiceResults postEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {

    if ("permissions".equalsIgnoreCase(dictionary)) {
      EntityRef entityRef = refs.get(0);
      checkPermissionsForEntitySubPath(context, entityRef, "permissions");

      String permission = payload.getStringProperty("permission");
      if (isBlank(permission)) {
        return null;
      }

      em.grantUserPermission(entityRef.getUuid(), permission);

      return genericServiceResults().withData(em.getUserPermissions(entityRef.getUuid()));
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }
  @Override
  public ServiceResults putEntityDictionary(
      ServiceContext context, List<EntityRef> refs, String dictionary, ServicePayload payload)
      throws Exception {

    if ("rolenames".equalsIgnoreCase(dictionary)) {
      EntityRef entityRef = refs.get(0);
      checkPermissionsForEntitySubPath(context, entityRef, "rolenames");

      if (context.parameterCount() == 0) {

        String name = payload.getStringProperty("name");
        if (isBlank(name)) {
          return null;
        }

        return addUserRole(entityRef.getUuid(), name);
      }
    }

    return super.postEntityDictionary(context, refs, dictionary, payload);
  }