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)
Set if URL lookup should always use the full path within the current servlet context.void
setCorsConfigurations(Map<String,CorsConfiguration> corsConfigurations)
Set CORS configuration based on URL patterns.void
setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching URL paths against registered URL patterns.void
setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.void
setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded.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)
Set if URL lookup should always use the full path within the current servlet context. Else, the path within the current servlet mapping is used if applicable (that is, in the case of a ".../*" servlet mapping in web.xml).Default is "false".
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Set if context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
- See Also:
UrlPathHelper.setUrlDecode(boolean)
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.The default value is
true
.
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(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
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