public static boolean isAuthorized(Authentication authentication, ResourceType resourceType,
                                     Long resourceId, Set<RoleAuthorization> requiredAuthorizations) {
    if ((requiredAuthorizations == null) || requiredAuthorizations.isEmpty()) {
      return true;
    } else if (authentication == null) {
      return false;
    } else {
      // Iterate through the set of required authorizations to see if at least one match is found.
      // If the user has at least one authorization that exists in the set of required authorizations,
      // that user is authorized to perform the operation.
      for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
        if (grantedAuthority instanceof AmbariGrantedAuthority) {
          AmbariGrantedAuthority ambariGrantedAuthority = (AmbariGrantedAuthority) grantedAuthority;
          PrivilegeEntity privilegeEntity = ambariGrantedAuthority.getPrivilegeEntity();
          ResourceEntity privilegeResource = privilegeEntity.getResource();
          ResourceType privilegeResourceType = ResourceType.translate(privilegeResource.getResourceType().getName());
          boolean resourceOK;

          if (ResourceType.AMBARI == privilegeResourceType) {
            // This resource type indicates administrative access
            resourceOK = true;
          } else if ((resourceType == null) || (resourceType == privilegeResourceType)) {
            resourceOK = (resourceId == null) || resourceId.equals(privilegeResource.getId());
          } else {
            resourceOK = false;
          }

          // The the authority is for the relevant resource, see if one of the authorizations matches
          // one of the required authorizations...
          if (resourceOK) {
            PermissionEntity permission = privilegeEntity.getPermission();
            Collection<RoleAuthorizationEntity> userAuthorizations = (permission == null)
                ? null
                : permission.getAuthorizations();

            if (userAuthorizations != null) {
              for (RoleAuthorizationEntity userAuthorization : userAuthorizations) {
                try {
                  if (requiredAuthorizations.contains(RoleAuthorization.translate(userAuthorization.getAuthorizationId()))) {
                    return true;
                  }
                } catch (IllegalArgumentException e) {
                  LOG.warn("Invalid authorization name, '{}'... ignoring.", userAuthorization.getAuthorizationId());
                }
              }
            }
          }
        }else {
            LOG.warn("GrantedAuthority is not an instance of AmbariGrantedAuthority. Ignoring.");
        }
      }

      return false;
    }
  }
Determines if the specified authenticated user is authorized to perform an operation on the
the specific resource by matching the authenticated user's authorizations with one from the
provided set of authorizations.
<p/>
The specified resource type is a high-level resource such as {@link ResourceType#AMBARI Ambari},
a {@link ResourceType#CLUSTER cluster}, or a {@link ResourceType#VIEW view}.
<p/>
The specified resource id is the (admin)resource id referenced by a specific resource instance
such as a cluster or view.

@param authentication         the authenticated user and associated access privileges
@param resourceType           a resource type being acted upon
@param resourceId             the privilege resource id (or adminresource.id) of the relevant resource
@param requiredAuthorizations a set of requirements for which one match will allow authorization
@return true if authorized; otherwise false
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AuthorizationHelper.java