Package com.vaadin.flow.spring.io
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:
-
PathMatchingResourcePatternResolver- Serialized Form
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe property key for allowed packages.static final StringThe property key for blocked JAR file.static final StringThe property key for blocked packages.Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionFilterableResourceResolver(org.springframework.core.io.ResourceLoader resourceLoader) Creates a new instance of the resolver. -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 booleanisAllowedByPackageProperties(String rootPath, String targetPath, boolean defaultValue) Check if the target path is allowed by the package properties.protected booleanisBlockedJar(org.springframework.core.io.Resource resource, String key) Returns whether the given resource is a blocked jar and shouldn't be included.protected booleanChecks 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
-
Field Details
-
ALLOWED_PACKAGES_PROPERTY
The property key for allowed packages.- See Also:
-
BLOCKED_PACKAGES_PROPERTY
The property key for blocked packages.- See Also:
-
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
Checks if the given path is a JAR file.- Parameters:
path- the path to check. Not null.- Returns:
trueif the path is a JAR file,falseotherwise
-
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:
doFindPathMatchingJarResourcesin classorg.springframework.core.io.support.PathMatchingResourcePatternResolver- Parameters:
rootDirResource- the root directory as ResourcerootDirUrl- the pre-resolved root directory URLsubPattern- 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:
doFindAllClassPathResourcesin classorg.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
Returns whether the given resource is a blocked jar and shouldn't be included.- Parameters:
resource- the resource to checkkey- the key for the package info- Returns:
trueif the resource is a blocked jar,falseotherwise
-
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 propertiestargetPath- relative path to checkdefaultValue- default value to return if the properties are not found- Returns:
trueif the target path is allowed by the package properties,
-