Class ApplicationContextRequestMatcher<C>

java.lang.Object
org.springframework.boot.security.web.servlet.ApplicationContextRequestMatcher<C>
Type Parameters:
C - the type of the context that the match method actually needs to use. Can be an ApplicationContext or a class of an existing bean.
All Implemented Interfaces:
RequestMatcher
Direct Known Subclasses:
EndpointRequest.AdditionalPathsEndpointRequestMatcher, EndpointRequest.EndpointRequestMatcher, EndpointRequest.LinksRequestMatcher, PathRequest.H2ConsoleRequestMatcher, StaticResourceRequest.StaticResourceRequestMatcher

public abstract class ApplicationContextRequestMatcher<C> extends Object implements RequestMatcher
ApplicationContext backed RequestMatcher. Can work directly with the ApplicationContext, obtain an existing bean or create a new bean that is autowired in the usual way.
Since:
4.0.0
Author:
Phillip Webb
  • Constructor Details

    • ApplicationContextRequestMatcher

      public ApplicationContextRequestMatcher(Class<? extends C> contextClass)
  • Method Details

    • matches

      public final boolean matches(HttpServletRequest request)
      Specified by:
      matches in interface RequestMatcher
    • ignoreApplicationContext

      protected boolean ignoreApplicationContext(WebApplicationContext webApplicationContext)
      Returns if the WebApplicationContext should be ignored and not used for matching. If this method returns true then the context will not be used and the matches method will return false.
      Parameters:
      webApplicationContext - the candidate web application context
      Returns:
      if the application context should be ignored
    • initialized

      protected void initialized(Supplier<C> context)
      Method that can be implemented by subclasses that wish to initialize items the first time that the matcher is called. This method will be called only once and only if ignoreApplicationContext(WebApplicationContext) returns false. Note that the supplied context will be based on the first request sent to the matcher.
      Parameters:
      context - a supplier for the initialized context (may throw an exception)
      See Also:
    • matches

      protected abstract boolean matches(HttpServletRequest request, Supplier<C> context)
      Decides whether the rule implemented by the strategy matches the supplied request.
      Parameters:
      request - the source request
      context - a supplier for the initialized context (may throw an exception)
      Returns:
      if the request matches
    • hasServerNamespace

      protected final boolean hasServerNamespace(@Nullable ApplicationContext context, String serverNamespace)
      Returns true if the specified context is a WebServerApplicationContext with a matching server namespace.
      Parameters:
      context - the context to check
      serverNamespace - the server namespace to match against
      Returns:
      true if the server namespace of the context matches
      Since:
      4.0.1
    • getServerNamespace

      protected final @Nullable String getServerNamespace(@Nullable ApplicationContext context)
      Returns the server namespace if the specified context is a WebServerApplicationContext.
      Parameters:
      context - the context
      Returns:
      the server namespace or null if the context is not a WebServerApplicationContext
      Since:
      4.0.1