code: public static <ResType> Iterable<ResType> filterAuthorizedResources(
        final AuthenticationResult authenticationResult,
        final Iterable<ResType> resources,
        final Function<? super ResType, Iterable<ResourceAction>> resourceActionGenerator,
        final AuthorizerMapper authorizerMapper
    )
    {
      final Authorizer authorizer = authorizerMapper.getAuthorizer(authenticationResult.getAuthorizerName());
      if (authorizer == null) {
        throw new ISE("No authorizer found with name: [%s].", authenticationResult.getAuthorizerName());
      }
  
      final Map<ResourceAction, Access> resultCache = new HashMap<>();
      final Iterable<ResType> filteredResources = Iterables.filter(
          resources,
          resource -> {
            final Iterable<ResourceAction> resourceActions = resourceActionGenerator.apply(resource);
            if (resourceActions == null) {
              return false;
            }
            for (ResourceAction resourceAction : resourceActions) {
              Access access = resultCache.computeIfAbsent(
                  resourceAction,
                  ra -> authorizer.authorize(
                      authenticationResult,
                      ra.getResource(),
                      ra.getAction()
                  )
              );
              if (!access.isAllowed()) {
                return false;
              }
            }
            return true;
          }
      );
  
      return filteredResources;
    }
docs: Filter a collection of resources by applying the resourceActionGenerator to each resource, return an iterable
  containing the filtered resources.
  
  The resourceActionGenerator returns an Iterable<ResourceAction> for each resource.
  
  If every resource-action in the iterable is authorized, the resource will be added to the filtered resources.
  
  If there is an authorization failure for one of the resource-actions, the resource will not be
  added to the returned filtered resources..
  
  If the resourceActionGenerator returns null for a resource, that resource will not be added to the filtered
  resources.
  
  @param authenticationResult    Authentication result representing identity of requester
  @param resources               resources to be processed into resource-actions
  @param resourceActionGenerator Function that creates an iterable of resource-actions from a resource
  @param authorizerMapper        authorizer mapper
  
  @return Iterable containing resources that were authorized