类 CorsFilter
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- org.springframework.web.filter.OncePerRequestFilter
- org.springframework.web.filter.CorsFilter
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
public class CorsFilter extends OncePerRequestFilter
Filter
that handles CORS preflight requests and intercepts CORS simple and actual requests thanks to aCorsProcessor
implementation (DefaultCorsProcessor
by default) in order to add the relevant CORS response headers (likeAccess-Control-Allow-Origin
) using the providedCorsConfigurationSource
(for example anUrlBasedCorsConfigurationSource
instance.This is an alternative to Spring MVC Java config and XML namespace CORS configuration, useful for applications depending only on spring-web (not on spring-webmvc) or for security constraints requiring CORS checks to be performed at
Filter
level.This filter could be used in conjunction with
DelegatingFilterProxy
in order to help with its initialization.- 从以下版本开始:
- 4.2
- 作者:
- Sebastien Deleuze
- 另请参阅:
- CORS W3C recommendation
字段概要
从类继承的字段 org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
从类继承的字段 org.springframework.web.filter.GenericFilterBean
logger
构造器概要
构造器 构造器 说明 CorsFilter(CorsConfigurationSource configSource)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected void
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as fordoFilter
, but guaranteed to be just invoked once per request within a single request thread.void
setCorsProcessor(CorsProcessor processor)
Configure a customCorsProcessor
to use to apply the matchedCorsConfiguration
for a request.从类继承的方法 org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
从类继承的方法 org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
构造器详细资料
CorsFilter
public CorsFilter(CorsConfigurationSource configSource)
Constructor accepting aCorsConfigurationSource
used by the filter to find theCorsConfiguration
to use for each incoming request.
方法详细资料
setCorsProcessor
public void setCorsProcessor(CorsProcessor processor)
Configure a customCorsProcessor
to use to apply the matchedCorsConfiguration
for a request.By default
DefaultCorsProcessor
is used.
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
从类复制的说明:OncePerRequestFilter
Same contract as fordoFilter
, but guaranteed to be just invoked once per request within a single request thread. SeeOncePerRequestFilter.shouldNotFilterAsyncDispatch()
for details.Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.