|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -45,6 +45,9 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
|
45 | 45 |
|
46 | 46 | private UrlPathHelper urlPathHelper = new UrlPathHelper();
|
47 | 47 |
|
| 48 | + @Nullable |
| 49 | + private String lookupPathAttributeName; |
| 50 | + |
48 | 51 |
|
49 | 52 | /**
|
50 | 53 | * Set the PathMatcher implementation to use for matching URL paths
|
@@ -72,6 +75,17 @@ public void setUrlDecode(boolean urlDecode) {
|
72 | 75 | this.urlPathHelper.setUrlDecode(urlDecode);
|
73 | 76 | }
|
74 | 77 |
|
| 78 | + /** |
| 79 | + * Optionally configure the name of the attribute that caches the lookupPath. |
| 80 | + * This is used to make the call to |
| 81 | + * {@link UrlPathHelper#getLookupPathForRequest(HttpServletRequest, String)} |
| 82 | + * @param lookupPathAttributeName the request attribute to check |
| 83 | + * @since 5.2 |
| 84 | + */ |
| 85 | + public void setLookupPathAttributeName(@Nullable String lookupPathAttributeName) { |
| 86 | + this.lookupPathAttributeName = lookupPathAttributeName; |
| 87 | + } |
| 88 | + |
75 | 89 | /**
|
76 | 90 | * Shortcut to same property on underlying {@link #setUrlPathHelper UrlPathHelper}.
|
77 | 91 | * @see org.springframework.web.util.UrlPathHelper#setRemoveSemicolonContent(boolean)
|
@@ -117,7 +131,7 @@ public void registerCorsConfiguration(String path, CorsConfiguration config) {
|
117 | 131 | @Override
|
118 | 132 | @Nullable
|
119 | 133 | public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
|
120 |
| - String lookupPath = this.urlPathHelper.getLookupPathForRequest(request); |
| 134 | + String lookupPath = this.urlPathHelper.getLookupPathForRequest(request, this.lookupPathAttributeName); |
121 | 135 | for (Map.Entry<String, CorsConfiguration> entry : this.corsConfigurations.entrySet()) {
|
122 | 136 | if (this.pathMatcher.match(entry.getKey(), lookupPath)) {
|
123 | 137 | return entry.getValue();
|
|
0 commit comments