|
24 | 24 | import org.springframework.util.ClassUtils;
|
25 | 25 | import org.springframework.web.cors.CorsConfiguration;
|
26 | 26 | import org.springframework.web.cors.CorsConfigurationSource;
|
| 27 | +import org.springframework.web.cors.PreFlightRequestHandler; |
27 | 28 | import org.springframework.web.filter.CorsFilter;
|
28 | 29 | import org.springframework.web.servlet.handler.HandlerMappingIntrospector;
|
29 | 30 |
|
@@ -110,12 +111,14 @@ private static CorsFilter getMvcCorsFilter(ApplicationContext context) {
|
110 | 111 | if (!context.containsBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)) {
|
111 | 112 | throw new NoSuchBeanDefinitionException(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, "A Bean named "
|
112 | 113 | + HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME + " of type "
|
113 |
| - + HandlerMappingIntrospector.class.getName() |
| 114 | + + PreFlightRequestHandler.class.getName() |
114 | 115 | + " is required to use MvcRequestMatcher. Please ensure Spring Security & Spring MVC are configured in a shared ApplicationContext.");
|
115 | 116 | }
|
116 |
| - HandlerMappingIntrospector mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, |
117 |
| - HandlerMappingIntrospector.class); |
118 |
| - return new CorsFilter(mappingIntrospector); |
| 117 | + PreFlightRequestHandler mappingIntrospector = context.getBean(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, |
| 118 | + PreFlightRequestHandler.class); |
| 119 | + Assert.isInstanceOf(CorsConfigurationSource.class, mappingIntrospector, |
| 120 | + () -> "mappingIntrospector must implement " + CorsConfigurationSource.class.getName()); |
| 121 | + return new CorsFilter((CorsConfigurationSource) mappingIntrospector); |
119 | 122 | }
|
120 | 123 |
|
121 | 124 | }
|
|
0 commit comments