Skip to content

Commit 2275030

Browse files
committed
Update HandlerMappingIntrospector Usage in CORS support
Closes gh-16501 Signed-off-by: Evgeniy Cheban <[email protected]>
1 parent ca1f891 commit 2275030

File tree

1 file changed

+7
-5
lines changed
  • config/src/main/java/org/springframework/security/config/annotation/web/configurers

1 file changed

+7
-5
lines changed

Diff for: config/src/main/java/org/springframework/security/config/annotation/web/configurers/CorsConfigurer.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.util.ClassUtils;
2525
import org.springframework.web.cors.CorsConfiguration;
2626
import org.springframework.web.cors.CorsConfigurationSource;
27+
import org.springframework.web.cors.PreFlightRequestHandler;
2728
import org.springframework.web.filter.CorsFilter;
2829
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
2930

@@ -109,13 +110,14 @@ static class MvcCorsFilter {
109110
private static CorsFilter getMvcCorsFilter(ApplicationContext context) {
110111
if (!context.containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) {
111112
throw new NoSuchBeanDefinitionException(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, "A Bean named "
112-
+ HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + " of type "
113-
+ HandlerMappingIntrospector.class.getName()
113+
+ HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + " of type " + PreFlightRequestHandler.class.getName()
114114
+ " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.");
115115
}
116-
HandlerMappingIntrospector mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME,
117-
HandlerMappingIntrospector.class);
118-
return new CorsFilter(mappingIntrospector);
116+
PreFlightRequestHandler mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME,
117+
PreFlightRequestHandler.class);
118+
Assert.isInstanceOf(CorsConfigurationSource.class, mappingIntrospector,
119+
() -> "mappingIntrospector must implement " + CorsConfigurationSource.class.getName());
120+
return new CorsFilter((CorsConfigurationSource) mappingIntrospector);
119121
}
120122

121123
}

0 commit comments

Comments
 (0)