Class HandlerMappingIntrospector
- All Implemented Interfaces:
Aware
,InitializingBean
,ApplicationContextAware
,CorsConfigurationSource
,PreFlightRequestHandler
HandlerMapping
that would
serve a specific request.
Provides the following methods:
getMatchableHandlerMapping(jakarta.servlet.http.HttpServletRequest)
— obtain aHandlerMapping
to check request-matching criteria against.getCorsConfiguration(jakarta.servlet.http.HttpServletRequest)
— obtain the CORS configuration for the request.
Note that this is primarily an SPI to allow Spring Security to align its pattern matching with the same pattern matching that would be used in Spring MVC for a given request, in order to avoid security issues.
Use of this component incurs the performance overhead of mapping the
request, and should not be repeated multiple times per request.
createCacheFilter()
exposes a Filter to cache the results.
Applications that rely on Spring Security don't need to deploy this Filter
since Spring Security doe that. However, other custom security layers, used
in place of Spring Security that use this component should deploy the cache
Filter with requirements described in the Javadoc for the method.
- Since:
- 4.3.1
- Author:
- Rossen Stoyanchev
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Deprecated, for removal: This API element is subject to removal in a future version.Container for aMatchableHandlerMapping
andCorsConfiguration
for a given request matched by dispatcher type and requestURI. -
Constructor Summary
ConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deprecated, for removal: This API element is subject to removal in a future version.Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.boolean
Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Filter
that looks up theMatchableHandlerMapping
andCorsConfiguration
for the request proactively before delegating to the rest of the chain, caching the result in a request attribute, and restoring it after the chain returns.getCorsConfiguration
(HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.Return aCorsConfiguration
based on the incoming request.Deprecated, for removal: This API element is subject to removal in a future version.Return the configured or detectedHandlerMapping
s.Deprecated, for removal: This API element is subject to removal in a future version.Find theHandlerMapping
that would handle the given request and return aMatchableHandlerMapping
to use for path matching.void
handlePreFlight
(HttpServletRequest request, HttpServletResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Find the matchingHandlerMapping
for the request, and invoke the handler it returns as aPreFlightRequestHandler
.void
resetCache
(ServletRequest request, @Nullable HandlerMappingIntrospector.CachedResult cachedResult) Deprecated, for removal: This API element is subject to removal in a future version.Restore a previousHandlerMappingIntrospector.CachedResult
.void
setApplicationContext
(ApplicationContext applicationContext) Deprecated, for removal: This API element is subject to removal in a future version.Set the ApplicationContext that this object runs in.setCache
(HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.Perform a lookup and save theHandlerMappingIntrospector.CachedResult
as a request attribute.
-
Constructor Details
-
HandlerMappingIntrospector
public HandlerMappingIntrospector()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setApplicationContext
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:ApplicationContextAware
Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
andMessageSourceAware
, if applicable.- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Parameters:
applicationContext
- the ApplicationContext object to be used by this object- See Also:
-
afterPropertiesSet
public void afterPropertiesSet()Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
getHandlerMappings
Deprecated, for removal: This API element is subject to removal in a future version.Return the configured or detectedHandlerMapping
s. -
allHandlerMappingsUsePathPatternParser
public boolean allHandlerMappingsUsePathPatternParser()Deprecated, for removal: This API element is subject to removal in a future version.- Since:
- 6.2
-
handlePreFlight
public void handlePreFlight(HttpServletRequest request, HttpServletResponse response) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.Find the matchingHandlerMapping
for the request, and invoke the handler it returns as aPreFlightRequestHandler
.- Specified by:
handlePreFlight
in interfacePreFlightRequestHandler
- Parameters:
request
- current HTTP requestresponse
- current HTTP response- Throws:
NoHandlerFoundException
- if no handler matches the requestException
- Since:
- 6.2
-
createCacheFilter
Deprecated, for removal: This API element is subject to removal in a future version.Filter
that looks up theMatchableHandlerMapping
andCorsConfiguration
for the request proactively before delegating to the rest of the chain, caching the result in a request attribute, and restoring it after the chain returns.Note: Applications that rely on Spring Security do not use this component directly and should not deploy the filter instead allowing Spring Security to do it. Other custom security layers used in place of Spring Security that also rely on
HandlerMappingIntrospector
should deploy this filter ahead of other filters where lookups are performed, and should also make sure the filter is configured to handle all dispatcher types.- Returns:
- the Filter instance to use
- Since:
- 6.0.14
-
setCache
Deprecated, for removal: This API element is subject to removal in a future version.Perform a lookup and save theHandlerMappingIntrospector.CachedResult
as a request attribute. This method can be invoked from a filter before subsequent calls togetMatchableHandlerMapping(HttpServletRequest)
andgetCorsConfiguration(HttpServletRequest)
to avoid repeated lookups.- Parameters:
request
- the current request- Returns:
- the previous
HandlerMappingIntrospector.CachedResult
, if there is one from a parent dispatch - Since:
- 6.0.14
-
resetCache
public void resetCache(ServletRequest request, @Nullable HandlerMappingIntrospector.CachedResult cachedResult) Deprecated, for removal: This API element is subject to removal in a future version.Restore a previousHandlerMappingIntrospector.CachedResult
. This method can be invoked from a filter after delegating to the rest of the chain.- Since:
- 6.0.14
-
getMatchableHandlerMapping
public @Nullable MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest request) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.Find theHandlerMapping
that would handle the given request and return aMatchableHandlerMapping
to use for path matching.- Parameters:
request
- the current request- Returns:
- the resolved
MatchableHandlerMapping
, ornull
- Throws:
IllegalStateException
- if the matching HandlerMapping is not an instance ofMatchableHandlerMapping
Exception
- if any of the HandlerMapping's raise an exception
-
getCorsConfiguration
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:CorsConfigurationSource
Return aCorsConfiguration
based on the incoming request.- Specified by:
getCorsConfiguration
in interfaceCorsConfigurationSource
- Returns:
- the associated
CorsConfiguration
, ornull
if none
-
PathPatternParser
; whenallHandlerMappingsUsePathPatternParser()
returns true, it is sufficient to use that to align with handler mappings.