Class UrlBasedCorsConfigurationsource
- All Implemented Interfaces:
CorsConfigurationsource
CorsConfigurationsource that uses URL path patterns to select the
CorsConfiguration for a request.
Pattern matching can be done with a PathMatcher or with pre-parsed
PathPatterns. The syntax is largely the same with the latter being more
tailored for web usage and more efficient. The choice depends on the presence of a
resolved string lookupPath or a
parsed RequestPath
with a fallback on PathMatcher but the fallback can be disabled.
For more details, please see setAllowInitLookupPath(boolean).
- since:
- 4.2
- Author:
- sebastien Deleuze, Rossen stoyanchev
- see Also:
-
Constructor summary
ConstructorsConstructorDescriptionDefault constructor withPathPatternParser.defaultInstance.UrlBasedCorsConfigurationsource(PathPatternParser parser) Constructor with aPathPatternParserto parse patterns with. -
Method summary
Modifier and TypeMethodDescriptiongetCorsConfiguration(jakarta.servlet.http.HttpservletRequest request) Return aCorsConfigurationbased on the incoming request.Return all configured CORs mappings.voidregisterCorsConfiguration(string pattern, CorsConfiguration config) Variant ofsetCorsConfigurations(Map)to register one mapping at a time.voidsetAllowInitLookupPath(boolean allowInitLookupPath) Deprecated, for removal: This API element is subject to removal in a future version.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all.voidsetCorsConfigurations(@Nullable Map<string, CorsConfiguration> corsConfigurations) set the CORs configuration mappings.voidsetPathMatcher(PathMatcher pathMatcher) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.voidsetRemovesemicolonContent(boolean removesemicolonContent) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all.voidsetUrlDecode(boolean urlDecode) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all.voidsetUrlPathHelper(UrlPathHelper urlPathHelper) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.
-
Constructor Details
-
UrlBasedCorsConfigurationsource
public UrlBasedCorsConfigurationsource()Default constructor withPathPatternParser.defaultInstance. -
UrlBasedCorsConfigurationsource
Constructor with aPathPatternParserto parse patterns with.- Parameters:
parser- the parser to use- since:
- 5.3
-
-
Method Details
-
setAlwaysUseFullPath
@Deprecated(since="5.3", forRemoval=true) public void setAlwaysUseFullPath(boolean alwaysUseFullPath) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all. For further details, please seesetAllowInitLookupPath(boolean).shortcut to thesame propertyon the configuredUrlPathHelper. -
setUrlDecode
@Deprecated(since="5.3", forRemoval=true) public void setUrlDecode(boolean urlDecode) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all. For further details, please seesetAllowInitLookupPath(boolean).shortcut to thesame propertyon the configuredUrlPathHelper. -
setRemovesemicolonContent
@Deprecated(since="5.3", forRemoval=true) public void setRemovesemicolonContent(boolean removesemicolonContent) Deprecated, for removal: This API element is subject to removal in a future version.as of 5.3 in favor of usingsetUrlPathHelper(UrlPathHelper), if at all. For further details, please seesetAllowInitLookupPath(boolean).shortcut to thesame propertyon the configuredUrlPathHelper. -
setUrlPathHelper
@Deprecated(since="7.0", forRemoval=true) public void setUrlPathHelper(UrlPathHelper urlPathHelper) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Configure theUrlPathHelperto resolve the lookupPath. This may not be necessary if the lookupPath is expected to be pre-resolved or if parsedPathPatternsare used instead. For further details on that, seesetAllowInitLookupPath(boolean).By default this is
UrlPathHelper.defaultInstance. -
setAllowInitLookupPath
@Deprecated(since="7.0", forRemoval=true) public void setAllowInitLookupPath(boolean allowInitLookupPath) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.When enabled, if there is neither aesolvedstring lookupPath nor aparsedRequestPaththen use theconfiguredUrlPathHelperto resolve a string lookupPath. This in turn determines use of URL pattern matching withPathMatcheror with parsedPathPatterns.In spring MVC, either a resolved string lookupPath or a parsed
RequestPathis always available withinDispatcherservletprocessing. However, in a servletFiltersuch asCorsFilterthat may or may not be the case.By default this is set to
truein which case lazy lookupPath initialization is allowed. set this tofalsewhen an application is using parsedPathPatternsin which case theRequestPathcan be parsed earlier viaservletRequestPathFilter.- Parameters:
allowInitLookupPath- whether to disable lazy initialization and fail if not already resolved- since:
- 5.3
-
setPathMatcher
@Deprecated(since="7.0", forRemoval=true) public void setPathMatcher(PathMatcher pathMatcher) Deprecated, for removal: This API element is subject to removal in a future version.use ofPathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.Configure aPathMatcherto use for pattern matching.This is an advanced property that should be used only when a customized
AntPathMatcheror a custom PathMatcher is required.By default this is
AntPathMatcher.Note: setting
PathMatcherenforces use of string pattern matching even when aparsedRequestPathis available. -
setCorsConfigurations
public void setCorsConfigurations(@Nullable Map<string, CorsConfiguration> corsConfigurations) set the CORs configuration mappings.For pattern syntax see
AntPathMatcherandPathPatternas well as class-level Javadoc for details on which one may in use. Generally the syntax is largely the same withPathPatternmore tailored for web usage.- Parameters:
corsConfigurations- the mappings to use- see Also:
-
registerCorsConfiguration
Variant ofsetCorsConfigurations(Map)to register one mapping at a time.- Parameters:
pattern- the mapping patternconfig- the CORs configuration to use for the pattern- see Also:
-
getCorsConfigurations
Return all configured CORs mappings. -
getCorsConfiguration
public @Nullable CorsConfiguration getCorsConfiguration(jakarta.servlet.http.HttpservletRequest request) Description copied from interface: CorsConfigurationsourceReturn aCorsConfigurationbased on the incoming request.- specified by:
getCorsConfiguration in interface CorsConfigurationsource- Returns:
- the associated
CorsConfiguration, ornullif none
-
PathMatcherandUrlPathHelperis deprecated for use at runtime in web modules in favor of parsed patterns withPathPatternParser.