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:
  • OncePerRequestFilter
  • 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 class org.springframework.web.filter.OncePerRequestFilter
      Parameters:
      request - the incoming HTTP request (never null)
      response - the HTTP response to which CORS headers will be applied (never null)
      filterChain - the filter chain to delegate to after adding headers (never null)
      Throws:
      jakarta.servlet.ServletException - if an internal servlet error occurs
      IOException - if an I/O error occurs during request processing