|
48 | 48 | import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
|
49 | 49 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
50 | 50 | import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
51 |
| -import org.springframework.boot.autoconfigure.security.SecurityProperties; |
52 | 51 | import org.springframework.boot.cloud.CloudPlatform;
|
53 | 52 | import org.springframework.boot.info.GitProperties;
|
54 | 53 | import org.springframework.boot.web.client.RestTemplateBuilder;
|
|
60 | 59 | import org.springframework.http.HttpHeaders;
|
61 | 60 | import org.springframework.http.HttpMethod;
|
62 | 61 | import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
|
| 62 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
63 | 63 | import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
64 | 64 | import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
| 65 | +import org.springframework.security.web.SecurityFilterChain; |
65 | 66 | import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher;
|
66 | 67 | import org.springframework.security.web.util.matcher.OrRequestMatcher;
|
67 | 68 | import org.springframework.security.web.util.matcher.RequestMatcher;
|
@@ -158,38 +159,33 @@ private CorsConfiguration getCorsConfiguration() {
|
158 | 159 | }
|
159 | 160 |
|
160 | 161 | /**
|
161 |
| - * {@link WebSecurityConfigurer} to tell Spring Security to ignore cloudfoundry |
| 162 | + * {@link WebSecurityConfigurer} to tell Spring Security to permit cloudfoundry |
162 | 163 | * specific paths. The Cloud foundry endpoints are protected by their own security
|
163 | 164 | * interceptor.
|
164 | 165 | */
|
165 | 166 | @ConditionalOnClass({ WebSecurityCustomizer.class, WebSecurity.class })
|
166 | 167 | @Configuration(proxyBeanMethods = false)
|
167 | 168 | public static class IgnoredCloudFoundryPathsWebSecurityConfiguration {
|
168 | 169 |
|
169 |
| - @Bean |
170 |
| - IgnoredCloudFoundryPathsWebSecurityCustomizer ignoreCloudFoundryPathsWebSecurityCustomizer( |
171 |
| - CloudFoundryWebEndpointServletHandlerMapping handlerMapping) { |
172 |
| - return new IgnoredCloudFoundryPathsWebSecurityCustomizer(handlerMapping); |
173 |
| - } |
174 |
| - |
175 |
| - } |
| 170 | + private static final int FILTER_CHAIN_ORDER = -1; |
176 | 171 |
|
177 |
| - @Order(SecurityProperties.IGNORED_ORDER) |
178 |
| - static class IgnoredCloudFoundryPathsWebSecurityCustomizer implements WebSecurityCustomizer { |
179 |
| - |
180 |
| - private final PathMappedEndpoints pathMappedEndpoints; |
181 |
| - |
182 |
| - IgnoredCloudFoundryPathsWebSecurityCustomizer(CloudFoundryWebEndpointServletHandlerMapping handlerMapping) { |
183 |
| - this.pathMappedEndpoints = new PathMappedEndpoints(BASE_PATH, handlerMapping::getAllEndpoints); |
| 172 | + @Bean |
| 173 | + @Order(FILTER_CHAIN_ORDER) |
| 174 | + SecurityFilterChain cloudFoundrySecurityFilterChain(HttpSecurity http, |
| 175 | + CloudFoundryWebEndpointServletHandlerMapping handlerMapping) throws Exception { |
| 176 | + RequestMatcher cloudFoundryRequest = getRequestMatcher(handlerMapping); |
| 177 | + http.securityMatchers((matches) -> matches.requestMatchers(cloudFoundryRequest)) |
| 178 | + .authorizeHttpRequests((authorize) -> authorize.anyRequest().permitAll()); |
| 179 | + return http.build(); |
184 | 180 | }
|
185 | 181 |
|
186 |
| - @Override |
187 |
| - public void customize(WebSecurity web) { |
| 182 | + private RequestMatcher getRequestMatcher(CloudFoundryWebEndpointServletHandlerMapping handlerMapping) { |
| 183 | + PathMappedEndpoints endpoints = new PathMappedEndpoints(BASE_PATH, handlerMapping::getAllEndpoints); |
188 | 184 | List<RequestMatcher> matchers = new ArrayList<>();
|
189 |
| - this.pathMappedEndpoints.getAllPaths().forEach((path) -> matchers.add(pathMatcher(path + "/**"))); |
| 185 | + endpoints.getAllPaths().forEach((path) -> matchers.add(pathMatcher(path + "/**"))); |
190 | 186 | matchers.add(pathMatcher(BASE_PATH));
|
191 | 187 | matchers.add(pathMatcher(BASE_PATH + "/"));
|
192 |
| - web.ignoring().requestMatchers(new OrRequestMatcher(matchers)); |
| 188 | + return new OrRequestMatcher(matchers); |
193 | 189 | }
|
194 | 190 |
|
195 | 191 | private PathPatternRequestMatcher pathMatcher(String path) {
|
|
0 commit comments