|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -183,9 +183,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set "global" CORS configuration based on URL patterns. By default the first |
|
|
|
* Set the "global" CORS configurations based on URL patterns. By default the first |
|
|
|
* matching URL pattern is combined with the CORS configuration for the |
|
|
|
* matching URL pattern is combined with the CORS configuration for the handler, if any. |
|
|
|
* handler, if any. |
|
|
|
|
|
|
|
* @since 4.2 |
|
|
|
* @since 4.2 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) { |
|
|
|
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) { |
|
|
|
@ -193,7 +192,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Get the "global" CORS configuration. |
|
|
|
* Get the "global" CORS configurations. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Map<String, CorsConfiguration> getCorsConfigurations() { |
|
|
|
public Map<String, CorsConfiguration> getCorsConfigurations() { |
|
|
|
return this.globalCorsConfigSource.getCorsConfigurations(); |
|
|
|
return this.globalCorsConfigSource.getCorsConfigurations(); |
|
|
|
@ -257,21 +256,22 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Detect beans of type {@link MappedInterceptor} and add them to the list of mapped interceptors. |
|
|
|
* Detect beans of type {@link MappedInterceptor} and add them to the list |
|
|
|
* <p>This is called in addition to any {@link MappedInterceptor}s that may have been provided |
|
|
|
* of mapped interceptors. |
|
|
|
* via {@link #setInterceptors}, by default adding all beans of type {@link MappedInterceptor} |
|
|
|
* <p>This is called in addition to any {@link MappedInterceptor}s that may |
|
|
|
* from the current context and its ancestors. Subclasses can override and refine this policy. |
|
|
|
* have been provided via {@link #setInterceptors}, by default adding all |
|
|
|
* @param mappedInterceptors an empty list to add {@link MappedInterceptor} instances to |
|
|
|
* beans of type {@link MappedInterceptor} from the current context and its |
|
|
|
|
|
|
|
* ancestors. Subclasses can override and refine this policy. |
|
|
|
|
|
|
|
* @param mappedInterceptors an empty list to add to |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) { |
|
|
|
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) { |
|
|
|
mappedInterceptors.addAll( |
|
|
|
mappedInterceptors.addAll(BeanFactoryUtils.beansOfTypeIncludingAncestors( |
|
|
|
BeanFactoryUtils.beansOfTypeIncludingAncestors( |
|
|
|
obtainApplicationContext(), MappedInterceptor.class, true, false).values()); |
|
|
|
obtainApplicationContext(), MappedInterceptor.class, true, false).values()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Initialize the specified interceptors, checking for {@link MappedInterceptor}s and |
|
|
|
* Initialize the specified interceptors adapting |
|
|
|
* adapting {@link HandlerInterceptor}s and {@link WebRequestInterceptor}s if necessary. |
|
|
|
* {@link WebRequestInterceptor}s to {@link HandlerInterceptor}. |
|
|
|
* @see #setInterceptors |
|
|
|
* @see #setInterceptors |
|
|
|
* @see #adaptInterceptor |
|
|
|
* @see #adaptInterceptor |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -288,13 +288,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Adapt the given interceptor object to the {@link HandlerInterceptor} interface. |
|
|
|
* Adapt the given interceptor object to {@link HandlerInterceptor}. |
|
|
|
* <p>By default, the supported interceptor types are {@link HandlerInterceptor} |
|
|
|
* <p>By default, the supported interceptor types are |
|
|
|
* and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor} |
|
|
|
* {@link HandlerInterceptor} and {@link WebRequestInterceptor}. Each given |
|
|
|
* will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}. |
|
|
|
* {@link WebRequestInterceptor} is wrapped with |
|
|
|
* Can be overridden in subclasses. |
|
|
|
* {@link WebRequestHandlerInterceptorAdapter}. |
|
|
|
* @param interceptor the specified interceptor object |
|
|
|
* @param interceptor the interceptor |
|
|
|
* @return the interceptor wrapped as HandlerInterceptor |
|
|
|
* @return the interceptor downcast or adapted to HandlerInterceptor |
|
|
|
* @see org.springframework.web.servlet.HandlerInterceptor |
|
|
|
* @see org.springframework.web.servlet.HandlerInterceptor |
|
|
|
* @see org.springframework.web.context.request.WebRequestInterceptor |
|
|
|
* @see org.springframework.web.context.request.WebRequestInterceptor |
|
|
|
* @see WebRequestHandlerInterceptorAdapter |
|
|
|
* @see WebRequestHandlerInterceptorAdapter |
|
|
|
@ -313,7 +313,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the adapted interceptors as {@link HandlerInterceptor} array. |
|
|
|
* Return the adapted interceptors as {@link HandlerInterceptor} array. |
|
|
|
* @return the array of {@link HandlerInterceptor}s, or {@code null} if none |
|
|
|
* @return the array of {@link HandlerInterceptor HandlerInterceptor}s, |
|
|
|
|
|
|
|
* or {@code null} if none |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
protected final HandlerInterceptor[] getAdaptedInterceptors() { |
|
|
|
protected final HandlerInterceptor[] getAdaptedInterceptors() { |
|
|
|
@ -393,8 +394,8 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
* Build a {@link HandlerExecutionChain} for the given handler, including |
|
|
|
* Build a {@link HandlerExecutionChain} for the given handler, including |
|
|
|
* applicable interceptors. |
|
|
|
* applicable interceptors. |
|
|
|
* <p>The default implementation builds a standard {@link HandlerExecutionChain} |
|
|
|
* <p>The default implementation builds a standard {@link HandlerExecutionChain} |
|
|
|
* with the given handler, the handler mapping's common interceptors, and any |
|
|
|
* with the given handler, the common interceptors of the handler mapping, and any |
|
|
|
* {@link MappedInterceptor}s matching to the current request URL. Interceptors |
|
|
|
* {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors |
|
|
|
* are added in the order they were registered. Subclasses may override this |
|
|
|
* are added in the order they were registered. Subclasses may override this |
|
|
|
* in order to extend/rearrange the list of interceptors. |
|
|
|
* in order to extend/rearrange the list of interceptors. |
|
|
|
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a |
|
|
|
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a |
|
|
|
@ -464,12 +465,12 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport |
|
|
|
|
|
|
|
|
|
|
|
if (CorsUtils.isPreFlightRequest(request)) { |
|
|
|
if (CorsUtils.isPreFlightRequest(request)) { |
|
|
|
HandlerInterceptor[] interceptors = chain.getInterceptors(); |
|
|
|
HandlerInterceptor[] interceptors = chain.getInterceptors(); |
|
|
|
chain = new HandlerExecutionChain(new PreFlightHandler(config), interceptors); |
|
|
|
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
chain.addInterceptor(new CorsInterceptor(config)); |
|
|
|
chain.addInterceptor(new CorsInterceptor(config)); |
|
|
|
|
|
|
|
return chain; |
|
|
|
} |
|
|
|
} |
|
|
|
return chain; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|