def CheckUserForLabels(username, authorized_labels, token=None):
  """Verify that the username has all the authorized_labels set."""
  authorized_labels = set(authorized_labels)

  try:
    user = aff4.FACTORY.Open("aff4:/users/%s" % username, aff4_type="GRRUser",
                             token=token)

    # Only return if all the authorized_labels are found in the user's
    # label list, otherwise raise UnauthorizedAccess.
    if (authorized_labels.intersection(
        user.GetLabelsNames()) == authorized_labels):
      return True
    else:
      raise access_control.UnauthorizedAccess(
          "User %s is missing labels (required: %s)." % (username,
                                                         authorized_labels))
  except __HOLE__:
    raise access_control.UnauthorizedAccess("User %s not found." % username)
dataset/ETHPy150Open google/grr/grr/lib/aff4_objects/user_managers.py/CheckUserForLabels