Class HandlerMappingIntrospector
- All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.cors.CorsConfigurationSource, org.springframework.web.cors.PreFlightRequestHandler
HandlerMapping that would
serve a specific request.
Provides the following methods:
getMatchableHandlerMapping(HttpServletRequest)— obtain aHandlerMappingto check request-matching criteria against.getCorsConfiguration(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
Nested ClassesModifier and TypeClassDescriptionstatic final classDeprecated, for removal: This API element is subject to removal in a future version.Container for aMatchableHandlerMappingandCorsConfigurationfor a given request matched by dispatcher type and requestURI. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionvoidDeprecated, for removal: This API element is subject to removal in a future version.booleanDeprecated, for removal: This API element is subject to removal in a future version.jakarta.servlet.FilterDeprecated, for removal: This API element is subject to removal in a future version.Filterthat looks up theMatchableHandlerMappingandCorsConfigurationfor 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.@Nullable org.springframework.web.cors.CorsConfigurationgetCorsConfiguration(jakarta.servlet.http.HttpServletRequest request) 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.Return the configured or detectedHandlerMappings.getMatchableHandlerMapping(jakarta.servlet.http.HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.Find theHandlerMappingthat would handle the given request and return aMatchableHandlerMappingto use for path matching.intDeprecated, for removal: This API element is subject to removal in a future version.Return the configured limit on security patterns to cache.voidhandlePreFlight(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Deprecated, for removal: This API element is subject to removal in a future version.Find the matchingHandlerMappingfor the request, and invoke the handler it returns as aPreFlightRequestHandler.voidresetCache(jakarta.servlet.ServletRequest request, @Nullable HandlerMappingIntrospector.CachedResult cachedResult) Deprecated, for removal: This API element is subject to removal in a future version.Restore a previousHandlerMappingIntrospector.CachedResult.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) Deprecated, for removal: This API element is subject to removal in a future version.setCache(jakarta.servlet.http.HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.Perform a lookup and save theHandlerMappingIntrospector.CachedResultas a request attribute.voidsetPatternCacheLimit(int patternCacheLimit) Deprecated, for removal: This API element is subject to removal in a future version.Set a limit on the maximum number of security patterns passed intoMatchableHandlerMapping.match(HttpServletRequest, String)at runtime to cache.
-
Constructor Details
-
HandlerMappingIntrospector
public HandlerMappingIntrospector()Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
setPatternCacheLimit
public void setPatternCacheLimit(int patternCacheLimit) Deprecated, for removal: This API element is subject to removal in a future version.Set a limit on the maximum number of security patterns passed intoMatchableHandlerMapping.match(HttpServletRequest, String)at runtime to cache.By default, this is set to 2048.
- Parameters:
patternCacheLimit- the limit to use- Since:
- 6.2.8
-
getPatternCacheLimit
public int getPatternCacheLimit()Deprecated, for removal: This API element is subject to removal in a future version.Return the configured limit on security patterns to cache.- Since:
- 6.2.8
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
afterPropertiesSet
public void afterPropertiesSet()Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
getHandlerMappings
Deprecated, for removal: This API element is subject to removal in a future version.Return the configured or detectedHandlerMappings. -
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(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.Find the matchingHandlerMappingfor the request, and invoke the handler it returns as aPreFlightRequestHandler.- Specified by:
handlePreFlightin interfaceorg.springframework.web.cors.PreFlightRequestHandler- Throws:
NoHandlerFoundException- if no handler matches the requestException- Since:
- 6.2
-
createCacheFilter
public jakarta.servlet.Filter createCacheFilter()Deprecated, for removal: This API element is subject to removal in a future version.Filterthat looks up theMatchableHandlerMappingandCorsConfigurationfor 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
HandlerMappingIntrospectorshould 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
public @Nullable HandlerMappingIntrospector.CachedResult setCache(jakarta.servlet.http.HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.Perform a lookup and save theHandlerMappingIntrospector.CachedResultas 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(jakarta.servlet.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(jakarta.servlet.http.HttpServletRequest request) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.Find theHandlerMappingthat would handle the given request and return aMatchableHandlerMappingto use for path matching.- Parameters:
request- the current request- Returns:
- the resolved
MatchableHandlerMapping, ornull - Throws:
IllegalStateException- if the matching HandlerMapping is not an instance ofMatchableHandlerMappingException- if any of the HandlerMapping's raise an exception
-
getCorsConfiguration
public @Nullable org.springframework.web.cors.CorsConfiguration getCorsConfiguration(jakarta.servlet.http.HttpServletRequest request) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
getCorsConfigurationin interfaceorg.springframework.web.cors.CorsConfigurationSource
-
PathPatternParser; whenallHandlerMappingsUsePathPatternParser()returns true, it is sufficient to use that to align with handler mappings.