Package com.alpaca.security.filter
Class SimpleCORSFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
com.alpaca.security.filter.SimpleCORSFilter
- All Implemented Interfaces:
jakarta.servlet.Filter
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,org.springframework.context.EnvironmentAware
,org.springframework.core.env.EnvironmentCapable
,org.springframework.web.context.ServletContextAware
@Component
@Order(-2147483648)
public class SimpleCORSFilter
extends org.springframework.web.filter.OncePerRequestFilter
A simple CORS (Cross-Origin Resource Sharing) filter that enables broad access to the API from
any origin. Applied at the highest precedence to ensure CORS headers are set before all other
filters, including security filters.
This filter extends OncePerRequestFilter
so that its logic executes only once per HTTP
request dispatch, avoiding redundant header additions or unexpected behavior.
- See Also:
-
Field Summary
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doFilterInternal
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, jakarta.servlet.FilterChain filterChain) Adds standard CORS headers to each HTTP response to allow cross-origin access.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
SimpleCORSFilter
public SimpleCORSFilter()
-
-
Method Details
-
doFilterInternal
protected void doFilterInternal(@NonNull jakarta.servlet.http.HttpServletRequest request, @NonNull jakarta.servlet.http.HttpServletResponse response, @NonNull jakarta.servlet.FilterChain filterChain) throws jakarta.servlet.ServletException, IOException Adds standard CORS headers to each HTTP response to allow cross-origin access. This includes allowed origins, credentials support, accepted methods, and headers. Then continues filter chain execution.- Specified by:
doFilterInternal
in classorg.springframework.web.filter.OncePerRequestFilter
- Parameters:
request
- the incoming HTTP request (nevernull
)response
- the HTTP response to which CORS headers will be applied (nevernull
)filterChain
- the filter chain to delegate to after adding headers (nevernull
)- Throws:
jakarta.servlet.ServletException
- if an internal servlet error occursIOException
- if an I/O error occurs during request processing
-