|
|
@ -67,8 +67,7 @@ import org.springframework.web.server.WebFilter;
|
|
|
|
* @since 2.0.0
|
|
|
|
* @since 2.0.0
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
@ConditionalOnProperty(prefix = "management.cloudfoundry", name = "enabled",
|
|
|
|
@ConditionalOnProperty(prefix = "management.cloudfoundry", name = "enabled", matchIfMissing = true)
|
|
|
|
matchIfMissing = true)
|
|
|
|
|
|
|
|
@AutoConfigureAfter(HealthEndpointAutoConfiguration.class)
|
|
|
|
@AutoConfigureAfter(HealthEndpointAutoConfiguration.class)
|
|
|
|
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
|
|
|
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
|
|
|
@ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY)
|
|
|
|
@ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY)
|
|
|
@ -86,58 +85,51 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
|
|
|
@ConditionalOnBean({ HealthEndpoint.class, ReactiveHealthEndpointWebExtension.class })
|
|
|
|
@ConditionalOnBean({ HealthEndpoint.class, ReactiveHealthEndpointWebExtension.class })
|
|
|
|
public CloudFoundryReactiveHealthEndpointWebExtension cloudFoundryReactiveHealthEndpointWebExtension(
|
|
|
|
public CloudFoundryReactiveHealthEndpointWebExtension cloudFoundryReactiveHealthEndpointWebExtension(
|
|
|
|
ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension) {
|
|
|
|
ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension) {
|
|
|
|
return new CloudFoundryReactiveHealthEndpointWebExtension(
|
|
|
|
return new CloudFoundryReactiveHealthEndpointWebExtension(reactiveHealthEndpointWebExtension);
|
|
|
|
reactiveHealthEndpointWebExtension);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public CloudFoundryWebFluxEndpointHandlerMapping cloudFoundryWebFluxEndpointHandlerMapping(
|
|
|
|
public CloudFoundryWebFluxEndpointHandlerMapping cloudFoundryWebFluxEndpointHandlerMapping(
|
|
|
|
ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes,
|
|
|
|
ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes,
|
|
|
|
WebClient.Builder webClientBuilder,
|
|
|
|
WebClient.Builder webClientBuilder, ControllerEndpointsSupplier controllerEndpointsSupplier) {
|
|
|
|
ControllerEndpointsSupplier controllerEndpointsSupplier) {
|
|
|
|
|
|
|
|
CloudFoundryWebEndpointDiscoverer endpointDiscoverer = new CloudFoundryWebEndpointDiscoverer(
|
|
|
|
CloudFoundryWebEndpointDiscoverer endpointDiscoverer = new CloudFoundryWebEndpointDiscoverer(
|
|
|
|
this.applicationContext, parameterMapper, endpointMediaTypes,
|
|
|
|
this.applicationContext, parameterMapper, endpointMediaTypes, PathMapper.useEndpointId(),
|
|
|
|
PathMapper.useEndpointId(), Collections.emptyList(),
|
|
|
|
Collections.emptyList(), Collections.emptyList());
|
|
|
|
Collections.emptyList());
|
|
|
|
CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor(webClientBuilder,
|
|
|
|
CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor(
|
|
|
|
this.applicationContext.getEnvironment());
|
|
|
|
webClientBuilder, this.applicationContext.getEnvironment());
|
|
|
|
|
|
|
|
Collection<ExposableWebEndpoint> webEndpoints = endpointDiscoverer.getEndpoints();
|
|
|
|
Collection<ExposableWebEndpoint> webEndpoints = endpointDiscoverer.getEndpoints();
|
|
|
|
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
|
|
|
|
List<ExposableEndpoint<?>> allEndpoints = new ArrayList<>();
|
|
|
|
allEndpoints.addAll(webEndpoints);
|
|
|
|
allEndpoints.addAll(webEndpoints);
|
|
|
|
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
|
|
|
|
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
|
|
|
|
return new CloudFoundryWebFluxEndpointHandlerMapping(
|
|
|
|
return new CloudFoundryWebFluxEndpointHandlerMapping(new EndpointMapping("/cloudfoundryapplication"),
|
|
|
|
new EndpointMapping("/cloudfoundryapplication"), webEndpoints,
|
|
|
|
webEndpoints, endpointMediaTypes, getCorsConfiguration(), securityInterceptor,
|
|
|
|
endpointMediaTypes, getCorsConfiguration(), securityInterceptor,
|
|
|
|
|
|
|
|
new EndpointLinksResolver(allEndpoints));
|
|
|
|
new EndpointLinksResolver(allEndpoints));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private CloudFoundrySecurityInterceptor getSecurityInterceptor(
|
|
|
|
private CloudFoundrySecurityInterceptor getSecurityInterceptor(WebClient.Builder webClientBuilder,
|
|
|
|
WebClient.Builder webClientBuilder, Environment environment) {
|
|
|
|
Environment environment) {
|
|
|
|
ReactiveCloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(
|
|
|
|
ReactiveCloudFoundrySecurityService cloudfoundrySecurityService = getCloudFoundrySecurityService(
|
|
|
|
webClientBuilder, environment);
|
|
|
|
webClientBuilder, environment);
|
|
|
|
ReactiveTokenValidator tokenValidator = new ReactiveTokenValidator(
|
|
|
|
ReactiveTokenValidator tokenValidator = new ReactiveTokenValidator(cloudfoundrySecurityService);
|
|
|
|
cloudfoundrySecurityService);
|
|
|
|
return new CloudFoundrySecurityInterceptor(tokenValidator, cloudfoundrySecurityService,
|
|
|
|
return new CloudFoundrySecurityInterceptor(tokenValidator,
|
|
|
|
|
|
|
|
cloudfoundrySecurityService,
|
|
|
|
|
|
|
|
environment.getProperty("vcap.application.application_id"));
|
|
|
|
environment.getProperty("vcap.application.application_id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ReactiveCloudFoundrySecurityService getCloudFoundrySecurityService(
|
|
|
|
private ReactiveCloudFoundrySecurityService getCloudFoundrySecurityService(WebClient.Builder webClientBuilder,
|
|
|
|
WebClient.Builder webClientBuilder, Environment environment) {
|
|
|
|
Environment environment) {
|
|
|
|
String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
|
|
|
|
String cloudControllerUrl = environment.getProperty("vcap.application.cf_api");
|
|
|
|
boolean skipSslValidation = environment.getProperty(
|
|
|
|
boolean skipSslValidation = environment.getProperty("management.cloudfoundry.skip-ssl-validation",
|
|
|
|
"management.cloudfoundry.skip-ssl-validation", Boolean.class, false);
|
|
|
|
Boolean.class, false);
|
|
|
|
return (cloudControllerUrl != null) ? new ReactiveCloudFoundrySecurityService(
|
|
|
|
return (cloudControllerUrl != null)
|
|
|
|
webClientBuilder, cloudControllerUrl, skipSslValidation) : null;
|
|
|
|
? new ReactiveCloudFoundrySecurityService(webClientBuilder, cloudControllerUrl, skipSslValidation)
|
|
|
|
|
|
|
|
: null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private CorsConfiguration getCorsConfiguration() {
|
|
|
|
private CorsConfiguration getCorsConfiguration() {
|
|
|
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
|
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
|
|
|
corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL);
|
|
|
|
corsConfiguration.addAllowedOrigin(CorsConfiguration.ALL);
|
|
|
|
corsConfiguration.setAllowedMethods(
|
|
|
|
corsConfiguration.setAllowedMethods(Arrays.asList(HttpMethod.GET.name(), HttpMethod.POST.name()));
|
|
|
|
Arrays.asList(HttpMethod.GET.name(), HttpMethod.POST.name()));
|
|
|
|
corsConfiguration.setAllowedHeaders(Arrays.asList("Authorization", "X-Cf-App-Instance", "Content-Type"));
|
|
|
|
corsConfiguration.setAllowedHeaders(
|
|
|
|
|
|
|
|
Arrays.asList("Authorization", "X-Cf-App-Instance", "Content-Type"));
|
|
|
|
|
|
|
|
return corsConfiguration;
|
|
|
|
return corsConfiguration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -155,8 +147,7 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
|
|
|
private static class WebFilterChainPostProcessor implements BeanPostProcessor {
|
|
|
|
private static class WebFilterChainPostProcessor implements BeanPostProcessor {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName)
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
|
|
|
throws BeansException {
|
|
|
|
|
|
|
|
if (bean instanceof WebFilterChainProxy) {
|
|
|
|
if (bean instanceof WebFilterChainProxy) {
|
|
|
|
return postProcess((WebFilterChainProxy) bean);
|
|
|
|
return postProcess((WebFilterChainProxy) bean);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -170,10 +161,8 @@ public class ReactiveCloudFoundryActuatorAutoConfiguration {
|
|
|
|
MatcherSecurityWebFilterChain ignoredRequestFilterChain = new MatcherSecurityWebFilterChain(
|
|
|
|
MatcherSecurityWebFilterChain ignoredRequestFilterChain = new MatcherSecurityWebFilterChain(
|
|
|
|
cloudFoundryRequestMatcher, Collections.singletonList(noOpFilter));
|
|
|
|
cloudFoundryRequestMatcher, Collections.singletonList(noOpFilter));
|
|
|
|
MatcherSecurityWebFilterChain allRequestsFilterChain = new MatcherSecurityWebFilterChain(
|
|
|
|
MatcherSecurityWebFilterChain allRequestsFilterChain = new MatcherSecurityWebFilterChain(
|
|
|
|
ServerWebExchangeMatchers.anyExchange(),
|
|
|
|
ServerWebExchangeMatchers.anyExchange(), Collections.singletonList(existing));
|
|
|
|
Collections.singletonList(existing));
|
|
|
|
return new WebFilterChainProxy(ignoredRequestFilterChain, allRequestsFilterChain);
|
|
|
|
return new WebFilterChainProxy(ignoredRequestFilterChain,
|
|
|
|
|
|
|
|
allRequestsFilterChain);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|