@Override
      public Void invoke() throws AmbariException {

        // for a create there should only be one resource ...
        Set<Long> resourceIds = getResourceEntities(properties).keySet();
        Long      resourceId  = resourceIds.iterator().next();

        PrivilegeEntity entity = toEntity(properties, resourceId);

        if (entity.getPrincipal() == null) {
          throw new AmbariException("Can't find principal " + properties.get(PRINCIPAL_TYPE) +
              " " + properties.get(PRINCIPAL_NAME) + " for privilege.");
        }
        if (privilegeDAO.exists(entity)) {
            throw new DuplicateResourceException("The privilege already exists.");
        }
        if (!checkResourceTypes(entity)) {
          throw new AmbariException("Can't grant " + entity.getPermission().getResourceType().getName() +
              " permission on a " + entity.getResource().getResourceType().getName() + " resource.");
        }
        privilegeDAO.create(entity);
        entity.getPrincipal().getPrivileges().add(entity);
        principalDAO.merge(entity.getPrincipal());
        return null;
      }
Convert the given map of properties to a privilege entity for the resource
identified by the given id.

@param properties  the property map
@param resourceId  the resource id

@return the new privilege entity
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/PrivilegeResourceProvider.java