From c3d623b54ed27bf52088b7090bba29dcc7346d5d Mon Sep 17 00:00:00 2001 From: Evgeniy Cheban Date: Thu, 20 Feb 2025 02:03:58 +0200 Subject: [PATCH] Update HandlerMappingIntrospector Usage in CORS support Closes gh-16501 --- .../annotation/web/configurers/CorsConfigurer.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java index 652558e0cd0..bbcafa82723 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java @@ -24,6 +24,7 @@ import org.springframework.util.ClassUtils; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.PreFlightRequestHandler; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.handler.HandlerMappingIntrospector; @@ -110,12 +111,12 @@ private static CorsFilter getMvcCorsFilter(ApplicationContext context) { if (!context.containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) { throw new NoSuchBeanDefinitionException(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, "A Bean named " + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + " of type " - + HandlerMappingIntrospector.class.getName() + + PreFlightRequestHandler.class.getName() + " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext."); } - HandlerMappingIntrospector mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, - HandlerMappingIntrospector.class); - return new CorsFilter(mappingIntrospector); + PreFlightRequestHandler mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, + PreFlightRequestHandler.class); + return new CorsFilter((CorsConfigurationSource) mappingIntrospector); } }