Class AbstractHttpSessionApplicationInitializer

java.lang.Object
org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer
All Implemented Interfaces:
org.springframework.web.WebApplicationInitializer

@Order(100) public abstract class AbstractHttpSessionApplicationInitializer extends Object implements org.springframework.web.WebApplicationInitializer
Registers the DelegatingFilterProxy to use the springSessionRepositoryFilter before any other registered Filter. When used with AbstractHttpSessionApplicationInitializer(Class...), it will also register a ContextLoaderListener. When used with AbstractHttpSessionApplicationInitializer(), this class is typically used in addition to a subclass of AbstractContextLoaderInitializer.

By default the DelegatingFilterProxy is registered with support for asynchronous requests, but can be enabled by overriding isAsyncSessionSupported() and getSessionDispatcherTypes().

Additional configuration before and after the springSecurityFilterChain can be added by overriding afterSessionRepositoryFilter(ServletContext).

Caveats

Subclasses of AbstractDispatcherServletInitializer will register their filters before any other Filter. This means that you will typically want to ensure subclasses of AbstractDispatcherServletInitializer are invoked first. This can be done by ensuring the Order or Ordered of AbstractDispatcherServletInitializer are sooner than subclasses of AbstractSecurityWebApplicationInitializer.

  • Field Details

    • DEFAULT_FILTER_NAME

      public static final String DEFAULT_FILTER_NAME
      The default name for Spring Session's repository filter.
      See Also:
  • Constructor Details

    • AbstractHttpSessionApplicationInitializer

      protected AbstractHttpSessionApplicationInitializer()
      Creates a new instance that assumes the Spring Session configuration is loaded by some other means than this class. For example, a user might create a ContextLoaderListener using a subclass of AbstractContextLoaderInitializer.
      See Also:
      • ContextLoaderListener
    • AbstractHttpSessionApplicationInitializer

      protected AbstractHttpSessionApplicationInitializer(Class<?>... configurationClasses)
      Creates a new instance that will instantiate the ContextLoaderListener with the specified classes.
      Parameters:
      configurationClasses - @Configuration classes that will be used to configure the context
  • Method Details

    • onStartup

      public void onStartup(jakarta.servlet.ServletContext servletContext)
      Specified by:
      onStartup in interface org.springframework.web.WebApplicationInitializer
    • insertFilters

      protected final void insertFilters(jakarta.servlet.ServletContext servletContext, jakarta.servlet.Filter... filters)
      Inserts the provided Filters before existing Filters using default generated names, getSessionDispatcherTypes(), and isAsyncSessionSupported().
      Parameters:
      servletContext - the ServletContext to use
      filters - the Filters to register
    • appendFilters

      protected final void appendFilters(jakarta.servlet.ServletContext servletContext, jakarta.servlet.Filter... filters)
      Inserts the provided Filters after existing Filters using default generated names, getSessionDispatcherTypes(), and isAsyncSessionSupported().
      Parameters:
      servletContext - the ServletContext to use
      filters - the Filters to register
    • getDispatcherWebApplicationContextSuffix

      protected String getDispatcherWebApplicationContextSuffix()
      Return the <servlet-name> to use the DispatcherServlet's WebApplicationContext to find the DelegatingFilterProxy or null to use the parent ApplicationContext.

      For example, if you are using AbstractDispatcherServletInitializer or AbstractAnnotationConfigDispatcherServletInitializer and using the provided Servlet name, you can return "dispatcher" from this method to use the DispatcherServlet's WebApplicationContext.

      Returns:
      the <servlet-name> of the DispatcherServlet to use its WebApplicationContext or null (default) to use the parent ApplicationContext.
    • beforeSessionRepositoryFilter

      protected void beforeSessionRepositoryFilter(jakarta.servlet.ServletContext servletContext)
      Invoked before the springSessionRepositoryFilter is added.
      Parameters:
      servletContext - the ServletContext
    • afterSessionRepositoryFilter

      protected void afterSessionRepositoryFilter(jakarta.servlet.ServletContext servletContext)
      Invoked after the springSessionRepositoryFilter is added.
      Parameters:
      servletContext - the ServletContext
    • getSessionDispatcherTypes

      protected EnumSet<jakarta.servlet.DispatcherType> getSessionDispatcherTypes()
      Get the DispatcherType for the springSessionRepositoryFilter.
      Returns:
      the DispatcherType for the filter
    • isAsyncSessionSupported

      protected boolean isAsyncSessionSupported()
      Determine if the springSessionRepositoryFilter should be marked as supporting asynch. Default is true.
      Returns:
      true if springSessionRepositoryFilter should be marked as supporting asynch