class ProviderBasedPermission implements ExtendedPermission {

  @Override
  public Boolean checkImpliesAll(Collection<Permission> requiredPermissions, boolean exceptionsOnError) {
    if (requiredPermissions.isEmpty()) {
      return Boolean.TRUE;
    }
    Set<String> required = new HashSet<>();
    for (Permission requiredPermission : requiredPermissions) {
      if (requiredPermission instanceof ProviderBasedPermission == false) {
        return null;
      }
      required.add(((ProviderBasedPermission) requiredPermission).getPermissionString());
    }
    UserPrincipals user = (UserPrincipals) AuthUtils.getSubject().getSession().getAttribute(UserPrincipals.ATTRIBUTE_KEY);
    if (user == null) {
      if (exceptionsOnError) {
        throw new UnauthenticatedException("Permission denied: User not logged in: " + required);
      } else {
        return Boolean.FALSE;
      }
    }
    PermissionCheckProviderRequest request = PermissionCheckProviderRequest.createGet(
        user.getAlternateIds(), user.getNetworkAddress(), required);
    PermissionCheckProviderResult result = _provider.isPermitted(request);
    if (exceptionsOnError) {
      result.checkErrors();
    }
    return Boolean.valueOf(result.isPermittedAll(required));
  }

    ProviderBasedPermission(PermissionCheckProvider provider, String permissionString);

}