public static void verifyAuthorization(String serviceName, Long clusterResourceId,
                                         Set<RoleAuthorization> clusterLevelAuthorizations,
                                         Set<RoleAuthorization> serviceLevelAuthorizations,
                                         String operation) throws AuthorizationException {
    if (null == clusterResourceId) {
      // Do not let clusterResourceId be null because that indicates we don't care about which cluster
      // we are checking authorization for, but we do.  Setting this to -1 ensures that no cluster
      // will match will will give only Ambari administrators access to this.
      clusterResourceId = -1L;
    }

    // If the service name is AMBARI, than the alert is for the cluster
    if (StringUtils.isEmpty(serviceName) || "AMBARI".equals(serviceName)) {
      if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, clusterResourceId,
          clusterLevelAuthorizations)) {
        throw new AuthorizationException(String.format("The authenticated user is not authorized to %s cluster-level alerts", operation));
      }
    } else {
      if (!AuthorizationHelper.isAuthorized(ResourceType.CLUSTER, clusterResourceId,
          serviceLevelAuthorizations)) {
        throw new AuthorizationException(String.format("The authenticated user is not authorized to %s service-level alerts", operation));
      }
    }
  }
Tests if the authenticated user is authorized to for either service- or cluster-level access to
alert data. An authorization failure results in a thrown {@link AuthorizationException}.
<p/>
If the service name from the AlertDefinitionEntity is null or empty, the alert is considered to
be a cluster-level alert, else it is considered to be a service-level alert.

@param serviceName                the name of the relevant service - null or empty indicates a cluster-level alert
@param clusterResourceId          the resource id of the relevant cluster
@param clusterLevelAuthorizations the set of cluster-level authorizations to check for
@param serviceLevelAuthorizations the set of service-level authorizations to check for
@param operation                  the name of the operation being tested for (used in error and logging messages)
@throws AuthorizationException if the authenticated user is not authorized
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProviderUtils.java