Package org.springframework.web.cors
Class UrlBasedCorsConfigurationSource
- java.lang.Object
- org.springframework.web.cors.UrlBasedCorsConfigurationSource
- All Implemented Interfaces:
CorsConfigurationSource
public class UrlBasedCorsConfigurationSource extends Object implements CorsConfigurationSource
Provide a per requestCorsConfiguration
instance based on a collection ofCorsConfiguration
mapped on path patterns.Exact path mapping URIs (such as
"/admin"
) are supported as well as Ant-style path patterns (such as"/admin/**"
).- Since:
- 4.2
- Author:
- Sebastien Deleuze
Constructor Summary
Constructors Constructor Description UrlBasedCorsConfigurationSource()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CorsConfiguration
getCorsConfiguration(HttpServletRequest request)
Return aCorsConfiguration
based on the incoming request.Map<String,CorsConfiguration>
getCorsConfigurations()
Get the CORS configuration.void
registerCorsConfiguration(String path, CorsConfiguration config)
Register aCorsConfiguration
for the specified path pattern.void
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.void
setCorsConfigurations(Map<String,CorsConfiguration> corsConfigurations)
Set CORS configuration based on URL patterns.void
setLookupPathAttributeName(String lookupPathAttributeName)
Optionally configure the name of the attribute that caches the lookupPath.void
setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.void
setRemoveSemicolonContent(boolean removeSemicolonContent)
Shortcut to same property on underlyingUrlPathHelper
.void
setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.
Constructor Detail
UrlBasedCorsConfigurationSource
public UrlBasedCorsConfigurationSource()
Method Detail
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher.- See Also:
AntPathMatcher
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.- See Also:
UrlPathHelper.setUrlDecode(boolean)
setLookupPathAttributeName
public void setLookupPathAttributeName(@Nullable String lookupPathAttributeName)
Optionally configure the name of the attribute that caches the lookupPath. This is used to make the call toUrlPathHelper.getLookupPathForRequest(HttpServletRequest, String)
- Parameters:
lookupPathAttributeName
- the request attribute to check- Since:
- 5.2
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Shortcut to same property on underlyingUrlPathHelper
.
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set the UrlPathHelper to use for resolution of lookup paths.Use this to override the default UrlPathHelper with a custom subclass.
setCorsConfigurations
public void setCorsConfigurations(@Nullable Map<String,CorsConfiguration> corsConfigurations)
Set CORS configuration based on URL patterns.
getCorsConfigurations
public Map<String,CorsConfiguration> getCorsConfigurations()
Get the CORS configuration.
registerCorsConfiguration
public void registerCorsConfiguration(String path, CorsConfiguration config)
Register aCorsConfiguration
for the specified path pattern.
getCorsConfiguration
@Nullable public CorsConfiguration getCorsConfiguration(HttpServletRequest request)
Description copied from interface:CorsConfigurationSource
Return aCorsConfiguration
based on the incoming request.- Specified by:
getCorsConfiguration
in interfaceCorsConfigurationSource
- Returns:
- the associated
CorsConfiguration
, ornull
if none