Class FilterableResourceResolver

java.lang.Object
org.springframework.core.io.support.PathMatchingResourcePatternResolver
com.vaadin.flow.spring.io.FilterableResourceResolver
All Implemented Interfaces:
Serializable, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver

public class FilterableResourceResolver extends org.springframework.core.io.support.PathMatchingResourcePatternResolver implements Serializable
A PathMatchingResourcePatternResolver that allows filtering resources by package properties. The resolver reads META-INF/VAADIN/package.properties from JAR files and directories. The properties file can contain a list of the allowed or blocked packages. If it contains both, the allowed packages take precedence. Allowed packages are mapped with the key "vaadin.allowed-packages". Blocked packages are mapped with the key "vaadin.blocked-packages".
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The property key for allowed packages.
    static final String
    The property key for blocked JAR file.
    static final String
    The property key for blocked packages.

    Fields inherited from interface org.springframework.core.io.ResourceLoader

    CLASSPATH_URL_PREFIX

    Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver

    CLASSPATH_ALL_URL_PREFIX
  • Constructor Summary

    Constructors
    Constructor
    Description
    FilterableResourceResolver(org.springframework.core.io.ResourceLoader resourceLoader)
    Creates a new instance of the resolver.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Set<org.springframework.core.io.Resource>
    Find all class path resources with the given path via the configured ClassLoader.
    protected Set<org.springframework.core.io.Resource>
    doFindPathMatchingJarResources(org.springframework.core.io.Resource rootDirResource, URL rootDirUrl, String subPattern)
    Find all resources in jar files that match the given location pattern via the Ant-style PathMatcher.
    protected boolean
    isAllowedByPackageProperties(String rootPath, String targetPath, boolean defaultValue)
    Check if the target path is allowed by the package properties.
    protected boolean
    isBlockedJar(org.springframework.core.io.Resource resource, String key)
    Returns whether the given resource is a blocked jar and shouldn't be included.
    protected boolean
    isJar(String path)
    Checks if the given path is a JAR file.

    Methods inherited from class org.springframework.core.io.support.PathMatchingResourcePatternResolver

    addAllClassLoaderJarRoots, addClassPathManifestEntries, clearCache, convertClassLoaderURL, determineRootDir, doFindPathMatchingFileResources, findAllClassPathResources, findAllModulePathResources, findPathMatchingResources, getClassLoader, getJarFile, getPathMatcher, getResource, getResourceLoader, getResources, isJarResource, resolveRootDirResource, setPathMatcher, setUseCaches

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ALLOWED_PACKAGES_PROPERTY

      public static final String ALLOWED_PACKAGES_PROPERTY
      The property key for allowed packages.
      See Also:
    • BLOCKED_PACKAGES_PROPERTY

      public static final String BLOCKED_PACKAGES_PROPERTY
      The property key for blocked packages.
      See Also:
    • BLOCKED_JAR_PROPERTY

      public static final String BLOCKED_JAR_PROPERTY
      The property key for blocked JAR file.
      See Also:
  • Constructor Details

    • FilterableResourceResolver

      public FilterableResourceResolver(org.springframework.core.io.ResourceLoader resourceLoader)
      Creates a new instance of the resolver.
      Parameters:
      resourceLoader - the resource loader to use
  • Method Details

    • isJar

      protected boolean isJar(String path)
      Checks if the given path is a JAR file.
      Parameters:
      path - the path to check. Not null.
      Returns:
      true if the path is a JAR file, false otherwise
    • doFindPathMatchingJarResources

      protected Set<org.springframework.core.io.Resource> doFindPathMatchingJarResources(org.springframework.core.io.Resource rootDirResource, URL rootDirUrl, String subPattern) throws IOException
      Find all resources in jar files that match the given location pattern via the Ant-style PathMatcher. Supports additional filtering based on allowed or blocked packages in package.properties.
      Overrides:
      doFindPathMatchingJarResources in class org.springframework.core.io.support.PathMatchingResourcePatternResolver
      Parameters:
      rootDirResource - the root directory as Resource
      rootDirUrl - the pre-resolved root directory URL
      subPattern - the sub pattern to match (below the root directory)
      Returns:
      a mutable Set of matching Resource instances
      Throws:
      IOException - in case of I/O error
    • doFindAllClassPathResources

      protected Set<org.springframework.core.io.Resource> doFindAllClassPathResources(String path) throws IOException
      Find all class path resources with the given path via the configured ClassLoader. Called by findAllClassPathResources(String). Supports additional filtering based on allowed or blocked packages in package.properties.
      Overrides:
      doFindAllClassPathResources in class org.springframework.core.io.support.PathMatchingResourcePatternResolver
      Parameters:
      path - the absolute path within the class path (never a leading slash)
      Returns:
      a mutable Set of matching Resource instances
      Throws:
      IOException - in case of I/O errors
    • isBlockedJar

      protected boolean isBlockedJar(org.springframework.core.io.Resource resource, String key)
      Returns whether the given resource is a blocked jar and shouldn't be included.
      Parameters:
      resource - the resource to check
      key - the key for the package info
      Returns:
      true if the resource is a blocked jar, false otherwise
    • isAllowedByPackageProperties

      protected boolean isAllowedByPackageProperties(String rootPath, String targetPath, boolean defaultValue)
      Check if the target path is allowed by the package properties.
      Parameters:
      rootPath - Root path as a key for the cached properties
      targetPath - relative path to check
      defaultValue - default value to return if the properties are not found
      Returns:
      true if the target path is allowed by the package properties,