>
-
-
-
-[[overview-endpoint-urls]]
-=== URLs
-
-By default, all web endpoints are available beneath the path `/actuator` with URLs of
-the form `/actuator/\{id}`. The `/actuator` base path can be configured by using the
-`management.endpoints.web.base-path` property, as shown in the following example:
-
-[source,properties,indent=0]
-----
- management.endpoints.web.base-path=/manage
-----
-
-The preceding `application.properties` example changes the form of the endpoint URLs from
-`/actuator/\{id}` to `/manage/\{id}`. For example, the URL `info` endpoint would become
-`/manage/info`.
-
-
-
-[[overview-timestamps]]
-=== Timestamps
-
-All timestamps that are consumed by the endpoints, either as query parameters or in the
-request body, must be formatted as an offset date and time as specified in
-https://en.wikipedia.org/wiki/ISO_8601[ISO 8601].
-
-
-
-include::endpoints/auditevents.adoc[leveloffset=+1]
-include::endpoints/beans.adoc[leveloffset=+1]
-include::endpoints/caches.adoc[leveloffset=+1]
-include::endpoints/conditions.adoc[leveloffset=+1]
-include::endpoints/configprops.adoc[leveloffset=+1]
-include::endpoints/env.adoc[leveloffset=+1]
-include::endpoints/flyway.adoc[leveloffset=+1]
-include::endpoints/health.adoc[leveloffset=+1]
-include::endpoints/heapdump.adoc[leveloffset=+1]
-include::endpoints/httptrace.adoc[leveloffset=+1]
-include::endpoints/info.adoc[leveloffset=+1]
-include::endpoints/integrationgraph.adoc[leveloffset=+1]
-include::endpoints/liquibase.adoc[leveloffset=+1]
-include::endpoints/logfile.adoc[leveloffset=+1]
-include::endpoints/loggers.adoc[leveloffset=+1]
-include::endpoints/mappings.adoc[leveloffset=+1]
-include::endpoints/metrics.adoc[leveloffset=+1]
-include::endpoints/prometheus.adoc[leveloffset=+1]
-include::endpoints/scheduledtasks.adoc[leveloffset=+1]
-include::endpoints/sessions.adoc[leveloffset=+1]
-include::endpoints/shutdown.adoc[leveloffset=+1]
-include::endpoints/threaddump.adoc[leveloffset=+1]
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEndpointElementCondition.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEndpointElementCondition.java
index 0ad2e1d9ef2d..e1634475bbc1 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEndpointElementCondition.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/OnEndpointElementCondition.java
@@ -69,7 +69,8 @@ protected ConditionOutcome getEndpointOutcome(ConditionContext context, String e
}
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) {
- boolean match = Boolean.valueOf(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
+ boolean match = Boolean
+ .parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType)
.because(this.prefix + "defaults.enabled is considered " + match));
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java
new file mode 100644
index 000000000000..4a028096f7d7
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityHealthContributorAutoConfiguration.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.availability;
+
+import org.springframework.boot.actuate.availability.AvailabilityStateHealthIndicator;
+import org.springframework.boot.actuate.availability.LivenessStateHealthIndicator;
+import org.springframework.boot.actuate.availability.ReadinessStateHealthIndicator;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.availability.ApplicationAvailability;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * {@link EnableAutoConfiguration Auto-configuration} for
+ * {@link AvailabilityStateHealthIndicator}.
+ *
+ * @author Brian Clozel
+ * @since 2.3.2
+ */
+@Configuration(proxyBeanMethods = false)
+@AutoConfigureAfter(ApplicationAvailabilityAutoConfiguration.class)
+public class AvailabilityHealthContributorAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = "livenessStateHealthIndicator")
+ @ConditionalOnProperty(prefix = "management.health.livenessstate", name = "enabled", havingValue = "true")
+ public LivenessStateHealthIndicator livenessStateHealthIndicator(ApplicationAvailability applicationAvailability) {
+ return new LivenessStateHealthIndicator(applicationAvailability);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(name = "readinessStateHealthIndicator")
+ @ConditionalOnProperty(prefix = "management.health.readinessstate", name = "enabled", havingValue = "true")
+ public ReadinessStateHealthIndicator readinessStateHealthIndicator(
+ ApplicationAvailability applicationAvailability) {
+ return new ReadinessStateHealthIndicator(applicationAvailability);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java
new file mode 100644
index 000000000000..99e0e84d1004
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesAutoConfiguration.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.availability;
+
+import org.springframework.boot.actuate.availability.LivenessStateHealthIndicator;
+import org.springframework.boot.actuate.availability.ReadinessStateHealthIndicator;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionMessage;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+import org.springframework.boot.availability.ApplicationAvailability;
+import org.springframework.boot.cloud.CloudPlatform;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * {@link EnableAutoConfiguration Auto-configuration} for availability probes.
+ *
+ * @author Brian Clozel
+ * @author Phillip Webb
+ * @since 2.3.0
+ */
+@Configuration(proxyBeanMethods = false)
+@Conditional(AvailabilityProbesAutoConfiguration.ProbesCondition.class)
+@AutoConfigureAfter({ AvailabilityHealthContributorAutoConfiguration.class,
+ ApplicationAvailabilityAutoConfiguration.class })
+public class AvailabilityProbesAutoConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = "livenessStateHealthIndicator")
+ public LivenessStateHealthIndicator livenessStateHealthIndicator(ApplicationAvailability applicationAvailability) {
+ return new LivenessStateHealthIndicator(applicationAvailability);
+ }
+
+ @Bean
+ @ConditionalOnMissingBean(name = "readinessStateHealthIndicator")
+ public ReadinessStateHealthIndicator readinessStateHealthIndicator(
+ ApplicationAvailability applicationAvailability) {
+ return new ReadinessStateHealthIndicator(applicationAvailability);
+ }
+
+ @Bean
+ public AvailabilityProbesHealthEndpointGroupsPostProcessor availabilityProbesHealthEndpointGroupsPostProcessor() {
+ return new AvailabilityProbesHealthEndpointGroupsPostProcessor();
+ }
+
+ /**
+ * {@link SpringBootCondition} to enable or disable probes.
+ *
+ * Probes are enabled if the dedicated configuration property is enabled or if the
+ * Kubernetes cloud environment is detected/enforced.
+ */
+ static class ProbesCondition extends SpringBootCondition {
+
+ private static final String ENABLED_PROPERTY = "management.endpoint.health.probes.enabled";
+
+ private static final String DEPRECATED_ENABLED_PROPERTY = "management.health.probes.enabled";
+
+ @Override
+ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
+ Environment environment = context.getEnvironment();
+ ConditionMessage.Builder message = ConditionMessage.forCondition("Probes availability");
+ ConditionOutcome outcome = onProperty(environment, message, ENABLED_PROPERTY);
+ if (outcome != null) {
+ return outcome;
+ }
+ outcome = onProperty(environment, message, DEPRECATED_ENABLED_PROPERTY);
+ if (outcome != null) {
+ return outcome;
+ }
+ if (CloudPlatform.getActive(environment) == CloudPlatform.KUBERNETES) {
+ return ConditionOutcome.match(message.because("running on Kubernetes"));
+ }
+ return ConditionOutcome.noMatch(message.because("not running on a supported cloud platform"));
+ }
+
+ private ConditionOutcome onProperty(Environment environment, ConditionMessage.Builder message,
+ String propertyName) {
+ String enabled = environment.getProperty(propertyName);
+ if (enabled != null) {
+ boolean match = !"false".equalsIgnoreCase(enabled);
+ return new ConditionOutcome(match, message.because("'" + propertyName + "' set to '" + enabled + "'"));
+ }
+ return null;
+ }
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroup.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroup.java
new file mode 100644
index 000000000000..c8a42ca3bbff
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroup.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.availability;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.springframework.boot.actuate.endpoint.SecurityContext;
+import org.springframework.boot.actuate.health.HealthEndpointGroup;
+import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
+import org.springframework.boot.actuate.health.StatusAggregator;
+
+/**
+ * {@link HealthEndpointGroup} used to support availability probes.
+ *
+ * @author Phillip Webb
+ * @author Brian Clozel
+ */
+class AvailabilityProbesHealthEndpointGroup implements HealthEndpointGroup {
+
+ private final Set members;
+
+ AvailabilityProbesHealthEndpointGroup(String... members) {
+ this.members = new HashSet<>(Arrays.asList(members));
+ }
+
+ @Override
+ public boolean isMember(String name) {
+ return this.members.contains(name);
+ }
+
+ @Override
+ public boolean showComponents(SecurityContext securityContext) {
+ return false;
+ }
+
+ @Override
+ public boolean showDetails(SecurityContext securityContext) {
+ return false;
+ }
+
+ @Override
+ public StatusAggregator getStatusAggregator() {
+ return StatusAggregator.getDefault();
+ }
+
+ @Override
+ public HttpCodeStatusMapper getHttpCodeStatusMapper() {
+ return HttpCodeStatusMapper.DEFAULT;
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroups.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroups.java
new file mode 100644
index 000000000000..0da69e7b5e44
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroups.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.availability;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.springframework.boot.actuate.health.HealthEndpointGroup;
+import org.springframework.boot.actuate.health.HealthEndpointGroups;
+import org.springframework.util.Assert;
+
+/**
+ * {@link HealthEndpointGroups} decorator to support availability probes.
+ *
+ * @author Phillip Webb
+ * @author Brian Clozel
+ */
+class AvailabilityProbesHealthEndpointGroups implements HealthEndpointGroups {
+
+ private static final Map GROUPS;
+ static {
+ Map groups = new LinkedHashMap<>();
+ groups.put("liveness", new AvailabilityProbesHealthEndpointGroup("livenessState"));
+ groups.put("readiness", new AvailabilityProbesHealthEndpointGroup("readinessState"));
+ GROUPS = Collections.unmodifiableMap(groups);
+ }
+
+ private final HealthEndpointGroups groups;
+
+ private final Set names;
+
+ AvailabilityProbesHealthEndpointGroups(HealthEndpointGroups groups) {
+ Assert.notNull(groups, "Groups must not be null");
+ this.groups = groups;
+ Set names = new LinkedHashSet<>(groups.getNames());
+ names.addAll(GROUPS.keySet());
+ this.names = Collections.unmodifiableSet(names);
+ }
+
+ @Override
+ public HealthEndpointGroup getPrimary() {
+ return this.groups.getPrimary();
+ }
+
+ @Override
+ public Set getNames() {
+ return this.names;
+ }
+
+ @Override
+ public HealthEndpointGroup get(String name) {
+ HealthEndpointGroup group = this.groups.get(name);
+ if (group == null) {
+ group = GROUPS.get(name);
+ }
+ return group;
+ }
+
+ static boolean containsAllProbeGroups(HealthEndpointGroups groups) {
+ return groups.getNames().containsAll(GROUPS.keySet());
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroupsPostProcessor.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroupsPostProcessor.java
new file mode 100644
index 000000000000..fcd36c99d9f1
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/AvailabilityProbesHealthEndpointGroupsPostProcessor.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.availability;
+
+import org.springframework.boot.actuate.health.HealthEndpointGroups;
+import org.springframework.boot.actuate.health.HealthEndpointGroupsPostProcessor;
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+
+/**
+ * {@link HealthEndpointGroupsPostProcessor} to add
+ * {@link AvailabilityProbesHealthEndpointGroups}.
+ *
+ * @author Phillip Webb
+ */
+@Order(Ordered.LOWEST_PRECEDENCE)
+class AvailabilityProbesHealthEndpointGroupsPostProcessor implements HealthEndpointGroupsPostProcessor {
+
+ @Override
+ public HealthEndpointGroups postProcessHealthEndpointGroups(HealthEndpointGroups groups) {
+ if (AvailabilityProbesHealthEndpointGroups.containsAllProbeGroups(groups)) {
+ return groups;
+ }
+ return new AvailabilityProbesHealthEndpointGroups(groups);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/package-info.java
new file mode 100644
index 000000000000..bec5a50f5350
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/availability/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Auto-configuration that extends health endpoints so that they can be used as
+ * availability probes.
+ */
+package org.springframework.boot.actuate.autoconfigure.availability;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java
index cf4f87aa89b5..23602f3ccb12 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,46 +16,35 @@
package org.springframework.boot.actuate.autoconfigure.cassandra;
-import java.util.Map;
+import com.datastax.oss.driver.api.core.CqlSession;
-import com.datastax.driver.core.Cluster;
-
-import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
+import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraDriverConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
-import org.springframework.boot.actuate.cassandra.CassandraHealthIndicator;
-import org.springframework.boot.actuate.health.HealthContributor;
+import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.cassandra.core.CassandraOperations;
+import org.springframework.context.annotation.Import;
/**
* {@link EnableAutoConfiguration Auto-configuration} for
- * {@link CassandraHealthIndicator}.
+ * {@link CassandraDriverHealthIndicator}.
*
* @author Julien Dubois
* @author Stephane Nicoll
* @since 2.1.0
*/
@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass({ Cluster.class, CassandraOperations.class })
-@ConditionalOnBean(CassandraOperations.class)
+@ConditionalOnClass(CqlSession.class)
@ConditionalOnEnabledHealthIndicator("cassandra")
@AutoConfigureAfter({ CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class,
CassandraReactiveHealthContributorAutoConfiguration.class })
-public class CassandraHealthContributorAutoConfiguration
- extends CompositeHealthContributorConfiguration {
-
- @Bean
- @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
- public HealthContributor cassandraHealthContributor(Map cassandraOperations) {
- return createContributor(cassandraOperations);
- }
+@Import({ CassandraDriverConfiguration.class,
+ CassandraHealthContributorConfigurations.CassandraOperationsConfiguration.class })
+@SuppressWarnings("deprecation")
+public class CassandraHealthContributorAutoConfiguration {
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java
new file mode 100644
index 000000000000..b3ff97fe0e69
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthContributorConfigurations.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.cassandra;
+
+import java.util.Map;
+
+import com.datastax.oss.driver.api.core.CqlSession;
+
+import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
+import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration;
+import org.springframework.boot.actuate.cassandra.CassandraDriverHealthIndicator;
+import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator;
+import org.springframework.boot.actuate.health.HealthContributor;
+import org.springframework.boot.actuate.health.ReactiveHealthContributor;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.cassandra.core.CassandraOperations;
+import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
+
+/**
+ * Health contributor options for Cassandra.
+ *
+ * @author Stephane Nicoll
+ */
+class CassandraHealthContributorConfigurations {
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnBean(CqlSession.class)
+ static class CassandraDriverConfiguration
+ extends CompositeHealthContributorConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
+ HealthContributor cassandraHealthContributor(Map sessions) {
+ return createContributor(sessions);
+ }
+
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(CassandraOperations.class)
+ @ConditionalOnBean(CassandraOperations.class)
+ @Deprecated
+ static class CassandraOperationsConfiguration extends
+ CompositeHealthContributorConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
+ HealthContributor cassandraHealthContributor(Map cassandraOperations) {
+ return createContributor(cassandraOperations);
+ }
+
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnBean(CqlSession.class)
+ static class CassandraReactiveDriverConfiguration extends
+ CompositeReactiveHealthContributorConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
+ ReactiveHealthContributor cassandraHealthContributor(Map sessions) {
+ return createContributor(sessions);
+ }
+
+ }
+
+ @Configuration(proxyBeanMethods = false)
+ @ConditionalOnClass(ReactiveCassandraOperations.class)
+ @ConditionalOnBean(ReactiveCassandraOperations.class)
+ @Deprecated
+ static class CassandraReactiveOperationsConfiguration extends
+ CompositeReactiveHealthContributorConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
+ ReactiveHealthContributor cassandraHealthContributor(
+ Map reactiveCassandraOperations) {
+ return createContributor(reactiveCassandraOperations);
+ }
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java
index 45ba39a5b0e2..c3f9e90cc67f 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,48 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.boot.actuate.autoconfigure.cassandra;
-import java.util.Map;
+package org.springframework.boot.actuate.autoconfigure.cassandra;
-import com.datastax.driver.core.Cluster;
+import com.datastax.oss.driver.api.core.CqlSession;
import reactor.core.publisher.Flux;
-import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration;
+import org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorConfigurations.CassandraReactiveDriverConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
-import org.springframework.boot.actuate.cassandra.CassandraReactiveHealthIndicator;
-import org.springframework.boot.actuate.health.ReactiveHealthContributor;
+import org.springframework.boot.actuate.cassandra.CassandraDriverReactiveHealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.cassandra.CassandraReactiveDataAutoConfiguration;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
+import org.springframework.context.annotation.Import;
/**
* {@link EnableAutoConfiguration Auto-configuration} for
- * {@link CassandraReactiveHealthIndicator}.
+ * {@link CassandraDriverReactiveHealthIndicator}.
*
* @author Artsiom Yudovin
* @author Stephane Nicoll
* @since 2.1.0
*/
@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass({ Cluster.class, ReactiveCassandraOperations.class, Flux.class })
-@ConditionalOnBean(ReactiveCassandraOperations.class)
+@ConditionalOnClass({ CqlSession.class, Flux.class })
@ConditionalOnEnabledHealthIndicator("cassandra")
@AutoConfigureAfter(CassandraReactiveDataAutoConfiguration.class)
-public class CassandraReactiveHealthContributorAutoConfiguration extends
- CompositeReactiveHealthContributorConfiguration {
-
- @Bean
- @ConditionalOnMissingBean(name = { "cassandraHealthIndicator", "cassandraHealthContributor" })
- public ReactiveHealthContributor cassandraHealthContributor(
- Map reactiveCassandraOperations) {
- return createContributor(reactiveCassandraOperations);
- }
+@Import({ CassandraReactiveDriverConfiguration.class,
+ CassandraHealthContributorConfigurations.CassandraReactiveOperationsConfiguration.class })
+@SuppressWarnings("deprecation")
+public class CassandraReactiveHealthContributorAutoConfiguration {
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/AccessLevel.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/AccessLevel.java
index b609dda14806..7c23ba93d219 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/AccessLevel.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/AccessLevel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,9 @@ public enum AccessLevel {
*/
FULL;
+ /**
+ * The request attribute used to store the {@link AccessLevel}.
+ */
public static final String REQUEST_ATTRIBUTE = "cloudFoundryAccessLevel";
private final List ids;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryAuthorizationException.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryAuthorizationException.java
index 93f33f1b06a3..48525ee8a55a 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryAuthorizationException.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryAuthorizationException.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,24 +58,54 @@ public Reason getReason() {
*/
public enum Reason {
+ /**
+ * Access Denied.
+ */
ACCESS_DENIED(HttpStatus.FORBIDDEN),
+ /**
+ * Invalid Audience.
+ */
INVALID_AUDIENCE(HttpStatus.UNAUTHORIZED),
+ /**
+ * Invalid Issuer.
+ */
INVALID_ISSUER(HttpStatus.UNAUTHORIZED),
+ /**
+ * Invalid Key ID.
+ */
INVALID_KEY_ID(HttpStatus.UNAUTHORIZED),
+ /**
+ * Invalid Signature.
+ */
INVALID_SIGNATURE(HttpStatus.UNAUTHORIZED),
+ /**
+ * Invalid Token.
+ */
INVALID_TOKEN(HttpStatus.UNAUTHORIZED),
+ /**
+ * Missing Authorization.
+ */
MISSING_AUTHORIZATION(HttpStatus.UNAUTHORIZED),
+ /**
+ * Token Expired.
+ */
TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED),
+ /**
+ * Unsupported Token Signing Algorithm.
+ */
UNSUPPORTED_TOKEN_SIGNING_ALGORITHM(HttpStatus.UNAUTHORIZED),
+ /**
+ * Service Unavailable.
+ */
SERVICE_UNAVAILABLE(HttpStatus.SERVICE_UNAVAILABLE);
private final HttpStatus status;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java
index 7f5105895640..a01fe72a9246 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,21 +58,21 @@ public CloudFoundryWebEndpointDiscoverer(ApplicationContext applicationContext,
}
@Override
- protected boolean isExtensionExposed(Object extensionBean) {
- if (isHealthEndpointExtension(extensionBean) && !isCloudFoundryHealthEndpointExtension(extensionBean)) {
+ protected boolean isExtensionTypeExposed(Class> extensionBeanType) {
+ if (isHealthEndpointExtension(extensionBeanType) && !isCloudFoundryHealthEndpointExtension(extensionBeanType)) {
// Filter regular health endpoint extensions so a CF version can replace them
return false;
}
return true;
}
- private boolean isHealthEndpointExtension(Object extensionBean) {
- return MergedAnnotations.from(extensionBean.getClass()).get(EndpointWebExtension.class)
+ private boolean isHealthEndpointExtension(Class> extensionBeanType) {
+ return MergedAnnotations.from(extensionBeanType).get(EndpointWebExtension.class)
.getValue("endpoint", Class.class).map(HealthEndpoint.class::isAssignableFrom).orElse(false);
}
- private boolean isCloudFoundryHealthEndpointExtension(Object extensionBean) {
- return MergedAnnotations.from(extensionBean.getClass()).isPresent(EndpointCloudFoundryExtension.class);
+ private boolean isCloudFoundryHealthEndpointExtension(Class> extensionBeanType) {
+ return MergedAnnotations.from(extensionBeanType).isPresent(EndpointCloudFoundryExtension.class);
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtension.java
index 589f952bc770..67f1708b5175 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtension.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundryReactiveHealthEndpointWebExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,12 +19,12 @@
import reactor.core.publisher.Mono;
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.EndpointCloudFoundryExtension;
+import org.springframework.boot.actuate.endpoint.ApiVersion;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.Selector.Match;
-import org.springframework.boot.actuate.endpoint.http.ApiVersion;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.boot.actuate.health.HealthComponent;
import org.springframework.boot.actuate.health.HealthEndpoint;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java
index bb82d7c2038a..7f9a83b3f15e 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,10 @@
import java.util.List;
import java.util.Map;
-import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import reactor.core.publisher.Mono;
+import reactor.netty.http.Http11SslContextSpec;
import reactor.netty.http.client.HttpClient;
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
@@ -66,14 +66,13 @@ class ReactiveCloudFoundrySecurityService {
}
protected ReactorClientHttpConnector buildTrustAllSslConnector() {
- HttpClient client = HttpClient.create()
- .secure((sslContextSpec) -> sslContextSpec.sslContext(createSslContext()));
+ HttpClient client = HttpClient.create().secure((spec) -> spec.sslContext(createSslContextSpec()));
return new ReactorClientHttpConnector(client);
}
- private SslContextBuilder createSslContext() {
- return SslContextBuilder.forClient().sslProvider(SslProvider.JDK)
- .trustManager(InsecureTrustManagerFactory.INSTANCE);
+ private Http11SslContextSpec createSslContextSpec() {
+ return Http11SslContextSpec.forClient().configure(
+ (builder) -> builder.sslProvider(SslProvider.JDK).trustManager(InsecureTrustManagerFactory.INSTANCE));
}
/**
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java
index a0950f72441b..04f24deeb771 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,6 +64,7 @@
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.DispatcherServlet;
@@ -158,18 +159,23 @@ private CorsConfiguration getCorsConfiguration() {
* specific paths. The Cloud foundry endpoints are protected by their own security
* interceptor.
*/
- @ConditionalOnClass(WebSecurity.class)
- @Order(SecurityProperties.IGNORED_ORDER)
+ @ConditionalOnClass({ WebSecurityCustomizer.class, WebSecurity.class })
@Configuration(proxyBeanMethods = false)
- public static class IgnoredPathsWebSecurityConfigurer implements WebSecurityConfigurer {
+ public static class IgnoredCloudFoundryPathsWebSecurityConfiguration {
- @Override
- public void init(WebSecurity builder) throws Exception {
- builder.ignoring().requestMatchers(new AntPathRequestMatcher("/cloudfoundryapplication/**"));
+ @Bean
+ IgnoredCloudFoundryPathsWebSecurityCustomizer ignoreCloudFoundryPathsWebSecurityCustomizer() {
+ return new IgnoredCloudFoundryPathsWebSecurityCustomizer();
}
+ }
+
+ @Order(SecurityProperties.IGNORED_ORDER)
+ static class IgnoredCloudFoundryPathsWebSecurityCustomizer implements WebSecurityCustomizer {
+
@Override
- public void configure(WebSecurity builder) throws Exception {
+ public void customize(WebSecurity web) {
+ web.ignoring().requestMatchers(new AntPathRequestMatcher("/cloudfoundryapplication/**"));
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryHealthEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryHealthEndpointWebExtension.java
index e91a1fbe4b54..7ec0b9772e97 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryHealthEndpointWebExtension.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryHealthEndpointWebExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,12 @@
package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.EndpointCloudFoundryExtension;
+import org.springframework.boot.actuate.endpoint.ApiVersion;
import org.springframework.boot.actuate.endpoint.SecurityContext;
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.Selector;
import org.springframework.boot.actuate.endpoint.annotation.Selector.Match;
-import org.springframework.boot.actuate.endpoint.http.ApiVersion;
import org.springframework.boot.actuate.endpoint.web.WebEndpointResponse;
import org.springframework.boot.actuate.health.HealthComponent;
import org.springframework.boot.actuate.health.HealthEndpoint;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryInfoEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryInfoEndpointWebExtension.java
index 73b2bbd968dc..9d3502d48e3e 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryInfoEndpointWebExtension.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryInfoEndpointWebExtension.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.actuate.autoconfigure.cloudfoundry.servlet;
import java.util.Map;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java
index bb2331e7bc22..472535cf6b29 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java
@@ -25,6 +25,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.AccessLevel;
import org.springframework.boot.actuate.autoconfigure.cloudfoundry.SecurityResponse;
import org.springframework.boot.actuate.endpoint.EndpointId;
@@ -51,6 +54,8 @@
*/
class CloudFoundryWebEndpointServletHandlerMapping extends AbstractWebMvcEndpointHandlerMapping {
+ private static final Log logger = LogFactory.getLog(CloudFoundryWebEndpointServletHandlerMapping.class);
+
private final CloudFoundrySecurityInterceptor securityInterceptor;
private final EndpointLinksResolver linksResolver;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/SkipSslVerificationHttpRequestFactory.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/SkipSslVerificationHttpRequestFactory.java
index 1d40a1d0f352..c613c16a2ee9 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/SkipSslVerificationHttpRequestFactory.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/SkipSslVerificationHttpRequestFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ private SSLSocketFactory createSslSocketFactory() throws Exception {
return context.getSocketFactory();
}
- private class SkipHostnameVerifier implements HostnameVerifier {
+ private static class SkipHostnameVerifier implements HostnameVerifier {
@Override
public boolean verify(String s, SSLSession sslSession) {
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java
index d9fe6c792fef..4225492220c4 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,9 @@
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint;
+import org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpointWebExtension;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@@ -30,6 +32,7 @@
*
* @author Phillip Webb
* @author Stephane Nicoll
+ * @author Chris Bono
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
@@ -46,7 +49,19 @@ public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoi
if (keysToSanitize != null) {
endpoint.setKeysToSanitize(keysToSanitize);
}
+ String[] additionalKeysToSanitize = properties.getAdditionalKeysToSanitize();
+ if (additionalKeysToSanitize != null) {
+ endpoint.keysToSanitize(additionalKeysToSanitize);
+ }
return endpoint;
}
+ @Bean
+ @ConditionalOnMissingBean
+ @ConditionalOnBean(ConfigurationPropertiesReportEndpoint.class)
+ public ConfigurationPropertiesReportEndpointWebExtension configurationPropertiesReportEndpointWebExtension(
+ ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint) {
+ return new ConfigurationPropertiesReportEndpointWebExtension(configurationPropertiesReportEndpoint);
+ }
+
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointProperties.java
index 7170f64ab242..d4a2b1383583 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,12 @@ public class ConfigurationPropertiesReportEndpointProperties {
*/
private String[] keysToSanitize;
+ /**
+ * Keys that should be sanitized in addition to those already configured. Keys can be
+ * simple strings that the property ends with or regular expressions.
+ */
+ private String[] additionalKeysToSanitize;
+
public String[] getKeysToSanitize() {
return this.keysToSanitize;
}
@@ -42,4 +48,12 @@ public void setKeysToSanitize(String[] keysToSanitize) {
this.keysToSanitize = keysToSanitize;
}
+ public String[] getAdditionalKeysToSanitize() {
+ return this.additionalKeysToSanitize;
+ }
+
+ public void setAdditionalKeysToSanitize(String[] additionalKeysToSanitize) {
+ this.additionalKeysToSanitize = additionalKeysToSanitize;
+ }
+
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthContributorAutoConfiguration.java
index ede9c1353c0d..dd0f5b4d9008 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.actuate.autoconfigure.couchbase;
import java.util.Map;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfiguration.java
index 9343848a5386..7429505cdcfd 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.actuate.autoconfigure.couchbase;
import java.util.Map;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthContributorAutoConfiguration.java
deleted file mode 100644
index 8778925eab3c..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthContributorAutoConfiguration.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.elasticsearch;
-
-import java.time.Duration;
-import java.util.Map;
-
-import org.elasticsearch.client.Client;
-
-import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
-import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
-import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
-import org.springframework.boot.actuate.health.HealthContributor;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for
- * {@link ElasticsearchHealthIndicator} using the Elasticsearch {@link Client}.
- *
- * @author Stephane Nicoll
- * @since 2.1.0
- * @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
- * deprecated upstream
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass(Client.class)
-@ConditionalOnBean(Client.class)
-@ConditionalOnEnabledHealthIndicator("elasticsearch")
-@AutoConfigureAfter(ElasticsearchAutoConfiguration.class)
-@EnableConfigurationProperties(ElasticsearchHealthIndicatorProperties.class)
-@Deprecated
-public class ElasticSearchClientHealthContributorAutoConfiguration
- extends CompositeHealthContributorConfiguration {
-
- private final ElasticsearchHealthIndicatorProperties properties;
-
- public ElasticSearchClientHealthContributorAutoConfiguration(ElasticsearchHealthIndicatorProperties properties) {
- this.properties = properties;
- }
-
- @Bean
- @ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
- public HealthContributor elasticsearchHealthContributor(Map clients) {
- return createContributor(clients);
- }
-
- @Override
- protected ElasticsearchHealthIndicator createIndicator(Client client) {
- Duration responseTimeout = this.properties.getResponseTimeout();
- return new ElasticsearchHealthIndicator(client, (responseTimeout != null) ? responseTimeout.toMillis() : 100,
- this.properties.getIndices());
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthContributorAutoConfiguration.java
deleted file mode 100644
index 62aa0a9e9f39..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthContributorAutoConfiguration.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.elasticsearch;
-
-import java.util.Map;
-
-import io.searchbox.client.JestClient;
-
-import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
-import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
-import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
-import org.springframework.boot.actuate.elasticsearch.ElasticsearchJestHealthIndicator;
-import org.springframework.boot.actuate.health.HealthContributor;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for
- * {@link ElasticsearchHealthIndicator} using the {@link JestClient}.
- *
- * @author Stephane Nicoll
- * @since 2.1.0
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass(JestClient.class)
-@ConditionalOnBean(JestClient.class)
-@ConditionalOnEnabledHealthIndicator("elasticsearch")
-@AutoConfigureAfter({ JestAutoConfiguration.class, ElasticSearchClientHealthContributorAutoConfiguration.class })
-@Deprecated
-public class ElasticSearchJestHealthContributorAutoConfiguration
- extends CompositeHealthContributorConfiguration {
-
- @Bean
- @ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
- public HealthContributor elasticsearchHealthContributor(Map clients) {
- return createContributor(clients);
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchReactiveHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchReactiveHealthContributorAutoConfiguration.java
new file mode 100644
index 000000000000..91ebf36ef3c6
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchReactiveHealthContributorAutoConfiguration.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.elasticsearch;
+
+import java.util.Map;
+
+import reactor.core.publisher.Flux;
+
+import org.springframework.boot.actuate.autoconfigure.health.CompositeReactiveHealthContributorConfiguration;
+import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
+import org.springframework.boot.actuate.elasticsearch.ElasticsearchReactiveHealthIndicator;
+import org.springframework.boot.actuate.health.ReactiveHealthContributor;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
+
+/**
+ * {@link EnableAutoConfiguration Auto-configuration} for
+ * {@link ElasticsearchReactiveHealthIndicator} using the
+ * {@link ReactiveElasticsearchClient}.
+ *
+ * @author Aleksander Lech
+ * @since 2.3.2
+ */
+@Configuration(proxyBeanMethods = false)
+@ConditionalOnClass({ ReactiveElasticsearchClient.class, Flux.class })
+@ConditionalOnBean(ReactiveElasticsearchClient.class)
+@ConditionalOnEnabledHealthIndicator("elasticsearch")
+@AutoConfigureAfter(ReactiveElasticsearchRestClientAutoConfiguration.class)
+public class ElasticSearchReactiveHealthContributorAutoConfiguration extends
+ CompositeReactiveHealthContributorConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
+ public ReactiveHealthContributor elasticsearchHealthContributor(Map clients) {
+ return createContributor(clients);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthContributorAutoConfiguration.java
index 2ce57ad27a7a..0fe95723dc24 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
import java.util.Map;
import org.elasticsearch.client.RestClient;
+import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
@@ -29,7 +30,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
+import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -41,17 +42,16 @@
* @since 2.1.1
*/
@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass(RestClient.class)
-@ConditionalOnBean(RestClient.class)
+@ConditionalOnClass(RestHighLevelClient.class)
+@ConditionalOnBean(RestHighLevelClient.class)
@ConditionalOnEnabledHealthIndicator("elasticsearch")
-@AutoConfigureAfter({ RestClientAutoConfiguration.class, ElasticSearchClientHealthContributorAutoConfiguration.class })
-@SuppressWarnings("deprecation")
+@AutoConfigureAfter(ElasticsearchRestClientAutoConfiguration.class)
public class ElasticSearchRestHealthContributorAutoConfiguration
- extends CompositeHealthContributorConfiguration {
+ extends CompositeHealthContributorConfiguration {
@Bean
- @ConditionalOnMissingBean(name = { "elasticsearchRestHealthIndicator", "elasticsearchRestHealthContributor" })
- public HealthContributor elasticsearchRestHealthContributor(Map clients) {
+ @ConditionalOnMissingBean(name = { "elasticsearchHealthIndicator", "elasticsearchHealthContributor" })
+ public HealthContributor elasticsearchHealthContributor(Map clients) {
return createContributor(clients);
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticsearchHealthIndicatorProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticsearchHealthIndicatorProperties.java
deleted file mode 100644
index 93863da4abc2..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticsearchHealthIndicatorProperties.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.elasticsearch;
-
-import java.time.Duration;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.boot.actuate.elasticsearch.ElasticsearchHealthIndicator;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
-
-/**
- * External configuration properties for {@link ElasticsearchHealthIndicator}.
- *
- * @author Binwei Yang
- * @author Andy Wilkinson
- * @since 2.0.0
- * @deprecated since 2.2.0 as {@literal org.elasticsearch.client:transport} has been
- * deprecated upstream
- */
-@ConfigurationProperties(prefix = "management.health.elasticsearch", ignoreUnknownFields = false)
-@Deprecated
-public class ElasticsearchHealthIndicatorProperties {
-
- /**
- * Comma-separated index names.
- */
- private List indices = new ArrayList<>();
-
- /**
- * Time to wait for a response from the cluster.
- */
- private Duration responseTimeout = Duration.ofMillis(100);
-
- @DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
- public List getIndices() {
- return this.indices;
- }
-
- public void setIndices(List indices) {
- this.indices = indices;
- }
-
- @DeprecatedConfigurationProperty(reason = "Upstream elasticsearch transport is deprected")
- public Duration getResponseTimeout() {
- return this.responseTimeout;
- }
-
- public void setResponseTimeout(Duration responseTimeout) {
- this.responseTimeout = responseTimeout;
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java
index d32af3609f98..36bd3bc6d18e 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/EndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ExposeExcludePropertyEndpointFilter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ExposeExcludePropertyEndpointFilter.java
deleted file mode 100644
index e9786a232394..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/ExposeExcludePropertyEndpointFilter.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.endpoint;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.springframework.boot.actuate.endpoint.EndpointFilter;
-import org.springframework.boot.actuate.endpoint.EndpointId;
-import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
-import org.springframework.boot.context.properties.bind.Bindable;
-import org.springframework.boot.context.properties.bind.Binder;
-import org.springframework.core.env.Environment;
-import org.springframework.util.Assert;
-
-/**
- * {@link EndpointFilter} that will filter endpoints based on {@code include} and
- * {@code exclude} properties.
- *
- * @param the endpoint type
- * @author Phillip Webb
- * @since 2.0.0
- */
-public class ExposeExcludePropertyEndpointFilter> implements EndpointFilter {
-
- private final Class endpointType;
-
- private final Set include;
-
- private final Set exclude;
-
- private final Set exposeDefaults;
-
- public ExposeExcludePropertyEndpointFilter(Class endpointType, Environment environment, String prefix,
- String... exposeDefaults) {
- Assert.notNull(endpointType, "EndpointType must not be null");
- Assert.notNull(environment, "Environment must not be null");
- Assert.hasText(prefix, "Prefix must not be empty");
- Binder binder = Binder.get(environment);
- this.endpointType = endpointType;
- this.include = bind(binder, prefix + ".include");
- this.exclude = bind(binder, prefix + ".exclude");
- this.exposeDefaults = asSet(Arrays.asList(exposeDefaults));
- }
-
- public ExposeExcludePropertyEndpointFilter(Class endpointType, Collection include,
- Collection exclude, String... exposeDefaults) {
- Assert.notNull(endpointType, "EndpointType Type must not be null");
- this.endpointType = endpointType;
- this.include = asSet(include);
- this.exclude = asSet(exclude);
- this.exposeDefaults = asSet(Arrays.asList(exposeDefaults));
- }
-
- private Set bind(Binder binder, String name) {
- return asSet(binder.bind(name, Bindable.listOf(String.class)).map(this::cleanup).orElseGet(ArrayList::new));
- }
-
- private List cleanup(List values) {
- return values.stream().map(this::cleanup).collect(Collectors.toList());
- }
-
- private String cleanup(String value) {
- return "*".equals(value) ? "*" : EndpointId.fromPropertyValue(value).toLowerCaseString();
- }
-
- private Set asSet(Collection items) {
- if (items == null) {
- return Collections.emptySet();
- }
- return items.stream().map((item) -> item.toLowerCase(Locale.ENGLISH)).collect(Collectors.toSet());
- }
-
- @Override
- public boolean match(E endpoint) {
- if (this.endpointType.isInstance(endpoint)) {
- return isExposed(endpoint) && !isExcluded(endpoint);
- }
- return true;
- }
-
- private boolean isExposed(ExposableEndpoint> endpoint) {
- if (this.include.isEmpty()) {
- return this.exposeDefaults.contains("*") || contains(this.exposeDefaults, endpoint);
- }
- return this.include.contains("*") || contains(this.include, endpoint);
- }
-
- private boolean isExcluded(ExposableEndpoint> endpoint) {
- if (this.exclude.isEmpty()) {
- return false;
- }
- return this.exclude.contains("*") || contains(this.exclude, endpoint);
- }
-
- private boolean contains(Set items, ExposableEndpoint> endpoint) {
- return items.contains(endpoint.getEndpointId().toLowerCaseString());
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java
deleted file mode 100644
index 8dc4bdb5611a..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
-import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.core.env.Environment;
-
-/**
- * {@link Conditional @Conditional} that checks whether an endpoint is enabled or not.
- * Matches according to the endpoints specific {@link Environment} property, falling back
- * to {@code management.endpoints.enabled-by-default} or failing that
- * {@link Endpoint#enableByDefault()}.
- *
- * When placed on a {@code @Bean} method, the endpoint defaults to the return type of the
- * factory method:
- *
- *
- * @Configuration
- * public class MyConfiguration {
- *
- * @ConditionalOnEnableEndpoint
- * @Bean
- * public MyEndpoint myEndpoint() {
- * ...
- * }
- *
- * }
- *
- * It is also possible to use the same mechanism for extensions:
- *
- *
- * @Configuration
- * public class MyConfiguration {
- *
- * @ConditionalOnEnableEndpoint
- * @Bean
- * public MyEndpointWebExtension myEndpointWebExtension() {
- * ...
- * }
- *
- * }
- *
- * In the sample above, {@code MyEndpointWebExtension} will be created if the endpoint is
- * enabled as defined by the rules above. {@code MyEndpointWebExtension} must be a regular
- * extension that refers to an endpoint, something like:
- *
- *
- * @EndpointWebExtension(endpoint = MyEndpoint.class)
- * public class MyEndpointWebExtension {
- *
- * }
- *
- * Alternatively, the target endpoint can be manually specified for components that should
- * only be created when a given endpoint is enabled:
- *
- *
- * @Configuration
- * public class MyConfiguration {
- *
- * @ConditionalOnEnableEndpoint(endpoint = MyEndpoint.class)
- * @Bean
- * public MyComponent myComponent() {
- * ...
- * }
- *
- * }
- *
- * @author Stephane Nicoll
- * @since 2.0.0
- * @see Endpoint
- * @deprecated as of 2.2.0 in favor of
- * {@link ConditionalOnAvailableEndpoint @ConditionalOnAvailableEndpoint}
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.METHOD, ElementType.TYPE })
-@Documented
-@Conditional(OnEnabledEndpointCondition.class)
-@Deprecated
-public @interface ConditionalOnEnabledEndpoint {
-
- /**
- * The endpoint type that should be checked. Inferred when the return type of the
- * {@code @Bean} method is either an {@link Endpoint @Endpoint} or an
- * {@link EndpointExtension @EndpointExtension}.
- * @return the endpoint type to check
- * @since 2.0.6
- */
- Class> endpoint() default Void.class;
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnAvailableEndpointCondition.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnAvailableEndpointCondition.java
index b13faff3d783..adc73887f089 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnAvailableEndpointCondition.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnAvailableEndpointCondition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,18 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
-import java.util.List;
+import java.util.Map;
import java.util.Set;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter.DefaultIncludes;
import org.springframework.boot.actuate.endpoint.EndpointId;
+import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.cloud.CloudPlatform;
-import org.springframework.boot.context.properties.bind.Bindable;
-import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.ConditionContext;
-import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.ConcurrentReferenceHashMap;
@@ -39,13 +37,14 @@
*
* @author Brian Clozel
* @author Stephane Nicoll
+ * @author Phillip Webb
* @see ConditionalOnAvailableEndpoint
*/
class OnAvailableEndpointCondition extends AbstractEndpointCondition {
private static final String JMX_ENABLED_KEY = "spring.jmx.enabled";
- private static final ConcurrentReferenceHashMap> endpointExposureCache = new ConcurrentReferenceHashMap<>();
+ private static final Map> exposuresCache = new ConcurrentReferenceHashMap<>();
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
@@ -60,79 +59,51 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
return new ConditionOutcome(true, message.andCondition(ConditionalOnAvailableEndpoint.class)
.because("application is running on Cloud Foundry"));
}
- AnnotationAttributes attributes = getEndpointAttributes(ConditionalOnAvailableEndpoint.class, context,
- metadata);
- EndpointId id = EndpointId.of(environment, attributes.getString("id"));
- Set exposureInformations = getExposureInformation(environment);
- for (ExposureInformation exposureInformation : exposureInformations) {
- if (exposureInformation.isExposed(id)) {
+ EndpointId id = EndpointId.of(environment,
+ getEndpointAttributes(ConditionalOnAvailableEndpoint.class, context, metadata).getString("id"));
+ Set exposures = getExposures(environment);
+ for (Exposure exposure : exposures) {
+ if (exposure.isExposed(id)) {
return new ConditionOutcome(true,
message.andCondition(ConditionalOnAvailableEndpoint.class)
- .because("marked as exposed by a 'management.endpoints."
- + exposureInformation.getPrefix() + ".exposure' property"));
+ .because("marked as exposed by a 'management.endpoints." + exposure.getPrefix()
+ + ".exposure' property"));
}
}
return new ConditionOutcome(false, message.andCondition(ConditionalOnAvailableEndpoint.class)
.because("no 'management.endpoints' property marked it as exposed"));
}
- private Set getExposureInformation(Environment environment) {
- Set exposureInformations = endpointExposureCache.get(environment);
- if (exposureInformations == null) {
- exposureInformations = new HashSet<>(2);
- Binder binder = Binder.get(environment);
+ private Set getExposures(Environment environment) {
+ Set exposures = exposuresCache.get(environment);
+ if (exposures == null) {
+ exposures = new HashSet<>(2);
if (environment.getProperty(JMX_ENABLED_KEY, Boolean.class, false)) {
- exposureInformations.add(new ExposureInformation(binder, "jmx", "*"));
+ exposures.add(new Exposure(environment, "jmx", DefaultIncludes.JMX));
}
- exposureInformations.add(new ExposureInformation(binder, "web", "info", "health"));
- endpointExposureCache.put(environment, exposureInformations);
+ exposures.add(new Exposure(environment, "web", DefaultIncludes.WEB));
+ exposuresCache.put(environment, exposures);
}
- return exposureInformations;
+ return exposures;
}
- static class ExposureInformation {
+ static class Exposure extends IncludeExcludeEndpointFilter> {
private final String prefix;
- private final Set include;
-
- private final Set exclude;
-
- private final Set exposeDefaults;
-
- ExposureInformation(Binder binder, String prefix, String... exposeDefaults) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ Exposure(Environment environment, String prefix, DefaultIncludes defaultIncludes) {
+ super((Class) ExposableEndpoint.class, environment, "management.endpoints." + prefix + ".exposure",
+ defaultIncludes);
this.prefix = prefix;
- this.include = bind(binder, "management.endpoints." + prefix + ".exposure.include");
- this.exclude = bind(binder, "management.endpoints." + prefix + ".exposure.exclude");
- this.exposeDefaults = new HashSet<>(Arrays.asList(exposeDefaults));
- }
-
- private Set bind(Binder binder, String name) {
- List values = binder.bind(name, Bindable.listOf(String.class)).orElse(Collections.emptyList());
- Set result = new HashSet<>(values.size());
- for (String value : values) {
- result.add("*".equals(value) ? "*" : EndpointId.fromPropertyValue(value).toLowerCaseString());
- }
- return result;
}
String getPrefix() {
return this.prefix;
}
- boolean isExposed(EndpointId endpointId) {
- String id = endpointId.toLowerCaseString();
- if (!this.exclude.isEmpty()) {
- if (this.exclude.contains("*") || this.exclude.contains(id)) {
- return false;
- }
- }
- if (this.include.isEmpty()) {
- if (this.exposeDefaults.contains("*") || this.exposeDefaults.contains(id)) {
- return true;
- }
- }
- return this.include.contains("*") || this.include.contains(id);
+ boolean isExposed(EndpointId id) {
+ return super.match(id);
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java
deleted file mode 100644
index 2babd17f148f..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
-
-import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
-import org.springframework.context.annotation.ConditionContext;
-import org.springframework.core.type.AnnotatedTypeMetadata;
-
-/**
- * A condition that checks if an endpoint is enabled.
- *
- * @author Stephane Nicoll
- * @author Andy Wilkinson
- * @author Phillip Webb
- * @see ConditionalOnEnabledEndpoint
- * @deprecated as of 2.2.0 in favor of {@link OnAvailableEndpointCondition}
- */
-@Deprecated
-class OnEnabledEndpointCondition extends AbstractEndpointCondition {
-
- @Override
- public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
- return getEnablementOutcome(context, metadata, ConditionalOnEnabledEndpoint.class);
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilter.java
new file mode 100644
index 000000000000..3b71edbf70c9
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/IncludeExcludeEndpointFilter.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2012-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.endpoint.expose;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.springframework.boot.actuate.endpoint.EndpointFilter;
+import org.springframework.boot.actuate.endpoint.EndpointId;
+import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
+import org.springframework.boot.context.properties.bind.Bindable;
+import org.springframework.boot.context.properties.bind.Binder;
+import org.springframework.core.env.Environment;
+import org.springframework.util.Assert;
+
+/**
+ * {@link EndpointFilter} that will filter endpoints based on {@code include} and
+ * {@code exclude} patterns.
+ *
+ * @param the endpoint type
+ * @author Phillip Webb
+ * @since 2.2.7
+ */
+public class IncludeExcludeEndpointFilter> implements EndpointFilter {
+
+ private final Class endpointType;
+
+ private final EndpointPatterns include;
+
+ private final EndpointPatterns defaultIncludes;
+
+ private final EndpointPatterns exclude;
+
+ /**
+ * Create a new {@link IncludeExcludeEndpointFilter} with include/exclude rules bound
+ * from the {@link Environment}.
+ * @param endpointType the endpoint type that should be considered (other types always
+ * match)
+ * @param environment the environment containing the properties
+ * @param prefix the property prefix to bind
+ * @param defaultIncludes the default {@code includes} to use when none are specified.
+ */
+ public IncludeExcludeEndpointFilter(Class endpointType, Environment environment, String prefix,
+ String... defaultIncludes) {
+ this(endpointType, environment, prefix, new EndpointPatterns(defaultIncludes));
+ }
+
+ /**
+ * Create a new {@link IncludeExcludeEndpointFilter} with include/exclude rules bound
+ * from the {@link Environment}.
+ * @param endpointType the endpoint type that should be considered (other types always
+ * match)
+ * @param environment the environment containing the properties
+ * @param prefix the property prefix to bind
+ * @param defaultIncludes the default {@code includes} to use when none are specified.
+ */
+ public IncludeExcludeEndpointFilter(Class endpointType, Environment environment, String prefix,
+ DefaultIncludes defaultIncludes) {
+ this(endpointType, environment, prefix, DefaultIncludes.patterns(defaultIncludes));
+ }
+
+ private IncludeExcludeEndpointFilter(Class endpointType, Environment environment, String prefix,
+ EndpointPatterns defaultIncludes) {
+ Assert.notNull(endpointType, "EndpointType must not be null");
+ Assert.notNull(environment, "Environment must not be null");
+ Assert.hasText(prefix, "Prefix must not be empty");
+ Assert.notNull(defaultIncludes, "DefaultIncludes must not be null");
+ Binder binder = Binder.get(environment);
+ this.endpointType = endpointType;
+ this.include = new EndpointPatterns(bind(binder, prefix + ".include"));
+ this.defaultIncludes = defaultIncludes;
+ this.exclude = new EndpointPatterns(bind(binder, prefix + ".exclude"));
+ }
+
+ /**
+ * Create a new {@link IncludeExcludeEndpointFilter} with specific include/exclude
+ * rules.
+ * @param endpointType the endpoint type that should be considered (other types always
+ * match)
+ * @param include the include patterns
+ * @param exclude the exclude patterns
+ * @param defaultIncludes the default {@code includes} to use when none are specified.
+ */
+ public IncludeExcludeEndpointFilter(Class endpointType, Collection include, Collection exclude,
+ String... defaultIncludes) {
+ this(endpointType, include, exclude, new EndpointPatterns(defaultIncludes));
+ }
+
+ /**
+ * Create a new {@link IncludeExcludeEndpointFilter} with specific include/exclude
+ * rules.
+ * @param endpointType the endpoint type that should be considered (other types always
+ * match)
+ * @param include the include patterns
+ * @param exclude the exclude patterns
+ * @param defaultIncludes the default {@code includes} to use when none are specified.
+ */
+ public IncludeExcludeEndpointFilter(Class endpointType, Collection include, Collection exclude,
+ DefaultIncludes defaultIncludes) {
+ this(endpointType, include, exclude, DefaultIncludes.patterns(defaultIncludes));
+ }
+
+ private IncludeExcludeEndpointFilter(Class endpointType, Collection include, Collection exclude,
+ EndpointPatterns defaultIncludes) {
+ Assert.notNull(endpointType, "EndpointType Type must not be null");
+ Assert.notNull(defaultIncludes, "DefaultIncludes must not be null");
+ this.endpointType = endpointType;
+ this.include = new EndpointPatterns(include);
+ this.defaultIncludes = defaultIncludes;
+ this.exclude = new EndpointPatterns(exclude);
+ }
+
+ private List bind(Binder binder, String name) {
+ return binder.bind(name, Bindable.listOf(String.class)).orElseGet(ArrayList::new);
+ }
+
+ @Override
+ public boolean match(E endpoint) {
+ if (!this.endpointType.isInstance(endpoint)) {
+ // Leave non-matching types for other filters
+ return true;
+ }
+ return match(endpoint.getEndpointId());
+ }
+
+ /**
+ * Return {@code true} if the filter matches.
+ * @param endpointId the endpoint ID to check
+ * @return {@code true} if the filter matches
+ */
+ protected final boolean match(EndpointId endpointId) {
+ return isIncluded(endpointId) && !isExcluded(endpointId);
+ }
+
+ private boolean isIncluded(EndpointId endpointId) {
+ if (this.include.isEmpty()) {
+ return this.defaultIncludes.matches(endpointId);
+ }
+ return this.include.matches(endpointId);
+ }
+
+ private boolean isExcluded(EndpointId endpointId) {
+ if (this.exclude.isEmpty()) {
+ return false;
+ }
+ return this.exclude.matches(endpointId);
+ }
+
+ /**
+ * Default include patterns that can be used.
+ */
+ public enum DefaultIncludes {
+
+ /**
+ * The default set of include patterns used for JMX.
+ */
+ JMX("*"),
+
+ /**
+ * The default set of include patterns used for web.
+ */
+ WEB("health");
+
+ private final EndpointPatterns patterns;
+
+ DefaultIncludes(String... patterns) {
+ this.patterns = new EndpointPatterns(patterns);
+ }
+
+ static EndpointPatterns patterns(DefaultIncludes defaultIncludes) {
+ return (defaultIncludes != null) ? defaultIncludes.patterns : (EndpointPatterns) null;
+ }
+
+ }
+
+ /**
+ * A set of endpoint patterns used to match IDs.
+ */
+ private static class EndpointPatterns {
+
+ private final boolean empty;
+
+ private final boolean matchesAll;
+
+ private final Set endpointIds;
+
+ EndpointPatterns(String[] patterns) {
+ this((patterns != null) ? Arrays.asList(patterns) : (Collection) null);
+ }
+
+ EndpointPatterns(Collection patterns) {
+ patterns = (patterns != null) ? patterns : Collections.emptySet();
+ boolean matchesAll = false;
+ Set endpointIds = new LinkedHashSet<>();
+ for (String pattern : patterns) {
+ if ("*".equals(pattern)) {
+ matchesAll = true;
+ }
+ else {
+ endpointIds.add(EndpointId.fromPropertyValue(pattern));
+ }
+ }
+ this.empty = patterns.isEmpty();
+ this.matchesAll = matchesAll;
+ this.endpointIds = endpointIds;
+ }
+
+ boolean isEmpty() {
+ return this.empty;
+ }
+
+ boolean matches(EndpointId endpointId) {
+ return this.matchesAll || this.endpointIds.contains(endpointId);
+ }
+
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/package-info.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/package-info.java
new file mode 100644
index 000000000000..023f6306ba87
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/expose/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Endpoint exposure logic used for auto-configuration and conditions.
+ */
+package org.springframework.boot.actuate.autoconfigure.endpoint.expose;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java
index e2af732276b0..4615c69d85cd 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/jmx/JmxEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
+import org.springframework.boot.LazyInitializationExcludeFilter;
+import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter;
import org.springframework.boot.actuate.endpoint.EndpointFilter;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.invoke.OperationInvokerAdvisor;
@@ -58,7 +60,7 @@
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
-@AutoConfigureAfter(JmxAutoConfiguration.class)
+@AutoConfigureAfter({ JmxAutoConfiguration.class, EndpointAutoConfiguration.class })
@EnableConfigurationProperties(JmxEndpointProperties.class)
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true")
public class JmxEndpointAutoConfiguration {
@@ -83,24 +85,35 @@ public JmxEndpointDiscoverer jmxAnnotationEndpointDiscoverer(ParameterValueMappe
}
@Bean
- @ConditionalOnSingleCandidate(MBeanServer.class)
- public JmxEndpointExporter jmxMBeanExporter(MBeanServer mBeanServer, Environment environment,
- ObjectProvider objectMapper, JmxEndpointsSupplier jmxEndpointsSupplier) {
+ @ConditionalOnMissingBean(EndpointObjectNameFactory.class)
+ public DefaultEndpointObjectNameFactory endpointObjectNameFactory(MBeanServer mBeanServer,
+ Environment environment) {
String contextId = ObjectUtils.getIdentityHexString(this.applicationContext);
- EndpointObjectNameFactory objectNameFactory = new DefaultEndpointObjectNameFactory(this.properties, environment,
- mBeanServer, contextId);
+ return new DefaultEndpointObjectNameFactory(this.properties, environment, mBeanServer, contextId);
+ }
+
+ @Bean
+ @ConditionalOnSingleCandidate(MBeanServer.class)
+ public JmxEndpointExporter jmxMBeanExporter(MBeanServer mBeanServer,
+ EndpointObjectNameFactory endpointObjectNameFactory, ObjectProvider objectMapper,
+ JmxEndpointsSupplier jmxEndpointsSupplier) {
JmxOperationResponseMapper responseMapper = new JacksonJmxOperationResponseMapper(
objectMapper.getIfAvailable());
- return new JmxEndpointExporter(mBeanServer, objectNameFactory, responseMapper,
+ return new JmxEndpointExporter(mBeanServer, endpointObjectNameFactory, responseMapper,
jmxEndpointsSupplier.getEndpoints());
}
@Bean
- public ExposeExcludePropertyEndpointFilter jmxIncludeExcludePropertyEndpointFilter() {
+ public IncludeExcludeEndpointFilter jmxIncludeExcludePropertyEndpointFilter() {
JmxEndpointProperties.Exposure exposure = this.properties.getExposure();
- return new ExposeExcludePropertyEndpointFilter<>(ExposableJmxEndpoint.class, exposure.getInclude(),
+ return new IncludeExcludeEndpointFilter<>(ExposableJmxEndpoint.class, exposure.getInclude(),
exposure.getExclude(), "*");
}
+ @Bean
+ static LazyInitializationExcludeFilter eagerlyInitializeJmxEndpointExporter() {
+ return LazyInitializationExcludeFilter.forBeanTypes(JmxEndpointExporter.class);
+ }
+
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java
index 979309da2528..d5dde9984dc4 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/CorsEndpointProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,11 +37,21 @@
public class CorsEndpointProperties {
/**
- * Comma-separated list of origins to allow. '*' allows all origins. When not set,
- * CORS support is disabled.
+ * Comma-separated list of origins to allow. '*' allows all origins. When credentials
+ * are allowed, '*' cannot be used and origin patterns should be configured instead.
+ * When no allowed origins or allowed origin patterns are set, CORS support is
+ * disabled.
*/
private List allowedOrigins = new ArrayList<>();
+ /**
+ * Comma-separated list of origin patterns to allow. Unlike allowed origins which only
+ * supports '*', origin patterns are more flexible (for example
+ * 'https://*.example.com') and can be used when credentials are allowed. When no
+ * allowed origin patterns or allowed origins are set, CORS support is disabled.
+ */
+ private List allowedOriginPatterns = new ArrayList<>();
+
/**
* Comma-separated list of methods to allow. '*' allows all methods. When not set,
* defaults to GET.
@@ -78,6 +88,14 @@ public void setAllowedOrigins(List allowedOrigins) {
this.allowedOrigins = allowedOrigins;
}
+ public List getAllowedOriginPatterns() {
+ return this.allowedOriginPatterns;
+ }
+
+ public void setAllowedOriginPatterns(List allowedOriginPatterns) {
+ this.allowedOriginPatterns = allowedOriginPatterns;
+ }
+
public List getAllowedMethods() {
return this.allowedMethods;
}
@@ -119,12 +137,13 @@ public void setMaxAge(Duration maxAge) {
}
public CorsConfiguration toCorsConfiguration() {
- if (CollectionUtils.isEmpty(this.allowedOrigins)) {
+ if (CollectionUtils.isEmpty(this.allowedOrigins) && CollectionUtils.isEmpty(this.allowedOriginPatterns)) {
return null;
}
PropertyMapper map = PropertyMapper.get();
CorsConfiguration configuration = new CorsConfiguration();
map.from(this::getAllowedOrigins).to(configuration::setAllowedOrigins);
+ map.from(this::getAllowedOriginPatterns).to(configuration::setAllowedOriginPatterns);
map.from(this::getAllowedHeaders).whenNot(CollectionUtils::isEmpty).to(configuration::setAllowedHeaders);
map.from(this::getAllowedMethods).whenNot(CollectionUtils::isEmpty).to(configuration::setAllowedMethods);
map.from(this::getExposedHeaders).whenNot(CollectionUtils::isEmpty).to(configuration::setExposedHeaders);
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java
index 2255a262c26f..21d84757a258 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
import org.glassfish.jersey.server.ResourceConfig;
-import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
import org.springframework.boot.actuate.endpoint.web.ExposableServletEndpoint;
import org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar;
@@ -47,10 +47,10 @@
public class ServletEndpointManagementContextConfiguration {
@Bean
- public ExposeExcludePropertyEndpointFilter servletExposeExcludePropertyEndpointFilter(
+ public IncludeExcludeEndpointFilter servletExposeExcludePropertyEndpointFilter(
WebEndpointProperties properties) {
WebEndpointProperties.Exposure exposure = properties.getExposure();
- return new ExposeExcludePropertyEndpointFilter<>(ExposableServletEndpoint.class, exposure.getInclude(),
+ return new IncludeExcludeEndpointFilter<>(ExposableServletEndpoint.class, exposure.getInclude(),
exposure.getExclude());
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java
index ea5eac25d2b8..387e82f3d132 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration;
-import org.springframework.boot.actuate.autoconfigure.endpoint.ExposeExcludePropertyEndpointFilter;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter;
+import org.springframework.boot.actuate.autoconfigure.endpoint.expose.IncludeExcludeEndpointFilter.DefaultIncludes;
import org.springframework.boot.actuate.endpoint.EndpointFilter;
import org.springframework.boot.actuate.endpoint.EndpointsSupplier;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -112,16 +113,16 @@ public PathMappedEndpoints pathMappedEndpoints(Collection>
}
@Bean
- public ExposeExcludePropertyEndpointFilter webExposeExcludePropertyEndpointFilter() {
+ public IncludeExcludeEndpointFilter webExposeExcludePropertyEndpointFilter() {
WebEndpointProperties.Exposure exposure = this.properties.getExposure();
- return new ExposeExcludePropertyEndpointFilter<>(ExposableWebEndpoint.class, exposure.getInclude(),
- exposure.getExclude(), "info", "health");
+ return new IncludeExcludeEndpointFilter<>(ExposableWebEndpoint.class, exposure.getInclude(),
+ exposure.getExclude(), DefaultIncludes.WEB);
}
@Bean
- public ExposeExcludePropertyEndpointFilter controllerExposeExcludePropertyEndpointFilter() {
+ public IncludeExcludeEndpointFilter controllerExposeExcludePropertyEndpointFilter() {
WebEndpointProperties.Exposure exposure = this.properties.getExposure();
- return new ExposeExcludePropertyEndpointFilter<>(ExposableControllerEndpoint.class, exposure.getInclude(),
+ return new IncludeExcludeEndpointFilter<>(ExposableControllerEndpoint.class, exposure.getInclude(),
exposure.getExclude());
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java
index aded969536d4..06a9223eaf62 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,11 @@ public class WebEndpointProperties {
private final Exposure exposure = new Exposure();
/**
- * Base path for Web endpoints. Relative to server.servlet.context-path or
- * management.server.servlet.context-path if management.server.port is configured.
+ * Base path for Web endpoints. Relative to the servlet context path
+ * (server.servlet.context-path) or WebFlux base path (spring.webflux.base-path) when
+ * the management server is sharing the main server port. Relative to the management
+ * server base path (management.server.base-path) when a separate management server
+ * port (management.server.port) is configured.
*/
private String basePath = "/actuator";
@@ -48,6 +51,8 @@ public class WebEndpointProperties {
*/
private final Map pathMapping = new LinkedHashMap<>();
+ private final Discovery discovery = new Discovery();
+
public Exposure getExposure() {
return this.exposure;
}
@@ -72,6 +77,10 @@ public Map getPathMapping() {
return this.pathMapping;
}
+ public Discovery getDiscovery() {
+ return this.discovery;
+ }
+
public static class Exposure {
/**
@@ -102,4 +111,21 @@ public void setExclude(Set exclude) {
}
+ public static class Discovery {
+
+ /**
+ * Whether the discovery page is enabled.
+ */
+ private boolean enabled = true;
+
+ public boolean isEnabled() {
+ return this.enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ }
+
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
index d22961a5f62f..c5b55c1e5140 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/jersey/JerseyWebEndpointManagementContextConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,14 +21,12 @@
import java.util.HashSet;
import java.util.List;
-import javax.annotation.PostConstruct;
-
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.model.Resource;
-import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration;
+import org.springframework.boot.actuate.autoconfigure.web.jersey.ManagementContextResourceConfigCustomizer;
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
@@ -45,7 +43,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
-import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
@@ -69,28 +66,24 @@ class JerseyWebEndpointManagementContextConfiguration {
@Bean
JerseyWebEndpointsResourcesRegistrar jerseyWebEndpointsResourcesRegistrar(Environment environment,
- ObjectProvider resourceConfig, WebEndpointsSupplier webEndpointsSupplier,
- ServletEndpointsSupplier servletEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
- WebEndpointProperties webEndpointProperties) {
+ WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier,
+ EndpointMediaTypes endpointMediaTypes, WebEndpointProperties webEndpointProperties) {
String basePath = webEndpointProperties.getBasePath();
- boolean shouldRegisterLinks = shouldRegisterLinksMapping(environment, basePath);
- shouldRegisterLinksMapping(environment, basePath);
- return new JerseyWebEndpointsResourcesRegistrar(resourceConfig.getIfAvailable(), webEndpointsSupplier,
- servletEndpointsSupplier, endpointMediaTypes, basePath, shouldRegisterLinks);
+ boolean shouldRegisterLinks = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
+ return new JerseyWebEndpointsResourcesRegistrar(webEndpointsSupplier, servletEndpointsSupplier,
+ endpointMediaTypes, basePath, shouldRegisterLinks);
}
- private boolean shouldRegisterLinksMapping(Environment environment, String basePath) {
- return StringUtils.hasText(basePath)
- || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
+ private boolean shouldRegisterLinksMapping(WebEndpointProperties properties, Environment environment,
+ String basePath) {
+ return properties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath)
+ || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}
/**
- * Register endpoints with the {@link ResourceConfig}. The
- * {@link ResourceConfigCustomizer} cannot be used because we don't want to apply
+ * Register endpoints with the {@link ResourceConfig} for the management context.
*/
- static class JerseyWebEndpointsResourcesRegistrar {
-
- private final ResourceConfig resourceConfig;
+ static class JerseyWebEndpointsResourcesRegistrar implements ManagementContextResourceConfigCustomizer {
private final WebEndpointsSupplier webEndpointsSupplier;
@@ -102,11 +95,9 @@ static class JerseyWebEndpointsResourcesRegistrar {
private final boolean shouldRegisterLinks;
- JerseyWebEndpointsResourcesRegistrar(ResourceConfig resourceConfig, WebEndpointsSupplier webEndpointsSupplier,
+ JerseyWebEndpointsResourcesRegistrar(WebEndpointsSupplier webEndpointsSupplier,
ServletEndpointsSupplier servletEndpointsSupplier, EndpointMediaTypes endpointMediaTypes,
String basePath, boolean shouldRegisterLinks) {
- super();
- this.resourceConfig = resourceConfig;
this.webEndpointsSupplier = webEndpointsSupplier;
this.servletEndpointsSupplier = servletEndpointsSupplier;
this.mediaTypes = endpointMediaTypes;
@@ -114,21 +105,19 @@ static class JerseyWebEndpointsResourcesRegistrar {
this.shouldRegisterLinks = shouldRegisterLinks;
}
- @PostConstruct
- void register() {
- // We can't easily use @ConditionalOnBean because @AutoConfigureBefore is
- // not an option for management contexts. Instead we manually check if
- // the resource config bean exists
- if (this.resourceConfig == null) {
- return;
- }
+ @Override
+ public void customize(ResourceConfig config) {
+ register(config);
+ }
+
+ private void register(ResourceConfig config) {
Collection webEndpoints = this.webEndpointsSupplier.getEndpoints();
Collection servletEndpoints = this.servletEndpointsSupplier.getEndpoints();
EndpointLinksResolver linksResolver = getLinksResolver(webEndpoints, servletEndpoints);
EndpointMapping mapping = new EndpointMapping(this.basePath);
- JerseyEndpointResourceFactory resourceFactory = new JerseyEndpointResourceFactory();
- register(resourceFactory.createEndpointResources(mapping, webEndpoints, this.mediaTypes, linksResolver,
- this.shouldRegisterLinks));
+ Collection endpointResources = new JerseyEndpointResourceFactory().createEndpointResources(
+ mapping, webEndpoints, this.mediaTypes, linksResolver, this.shouldRegisterLinks);
+ register(endpointResources, config);
}
private EndpointLinksResolver getLinksResolver(Collection webEndpoints,
@@ -139,8 +128,8 @@ private EndpointLinksResolver getLinksResolver(Collection
return new EndpointLinksResolver(endpoints, this.basePath);
}
- private void register(Collection resources) {
- this.resourceConfig.registerResources(new HashSet<>(resources));
+ private void register(Collection resources, ResourceConfig config) {
+ config.registerResources(new HashSet<>(resources));
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java
index aa758ae72d7d..e4794e10c8fd 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/reactive/WebFluxEndpointManagementContextConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,12 +75,13 @@ public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping(WebEndpoi
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
return new WebFluxEndpointHandlerMapping(endpointMapping, endpoints, endpointMediaTypes,
corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
- shouldRegisterLinksMapping(environment, basePath));
+ shouldRegisterLinksMapping(webEndpointProperties, environment, basePath));
}
- private boolean shouldRegisterLinksMapping(Environment environment, String basePath) {
- return StringUtils.hasText(basePath)
- || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
+ private boolean shouldRegisterLinksMapping(WebEndpointProperties properties, Environment environment,
+ String basePath) {
+ return properties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath)
+ || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}
@Bean
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java
index 91064d4d5aec..75fab2727432 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/servlet/WebMvcEndpointManagementContextConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,13 +74,18 @@ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpoint
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
- boolean shouldRegisterLinksMapping = StringUtils.hasText(basePath)
- || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT);
+ boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes,
corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath),
shouldRegisterLinksMapping);
}
+ private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment,
+ String basePath) {
+ return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath)
+ || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
+ }
+
@Bean
@ConditionalOnMissingBean
public ControllerEndpointHandlerMapping controllerEndpointHandlerMapping(
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java
index c8af552deabb..30547155eb46 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,10 @@ public EnvironmentEndpoint environmentEndpoint(Environment environment, Environm
if (keysToSanitize != null) {
endpoint.setKeysToSanitize(keysToSanitize);
}
+ String[] additionalKeysToSanitize = properties.getAdditionalKeysToSanitize();
+ if (additionalKeysToSanitize != null) {
+ endpoint.keysToSanitize(additionalKeysToSanitize);
+ }
return endpoint;
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointProperties.java
index fe753edcff45..cd1bfddf133a 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,12 @@ public class EnvironmentEndpointProperties {
*/
private String[] keysToSanitize;
+ /**
+ * Keys that should be sanitized in addition to those already configured. Keys can be
+ * simple strings that the property ends with or regular expressions.
+ */
+ private String[] additionalKeysToSanitize;
+
public String[] getKeysToSanitize() {
return this.keysToSanitize;
}
@@ -42,4 +48,12 @@ public void setKeysToSanitize(String[] keysToSanitize) {
this.keysToSanitize = keysToSanitize;
}
+ public String[] getAdditionalKeysToSanitize() {
+ return this.additionalKeysToSanitize;
+ }
+
+ public void setAdditionalKeysToSanitize(String[] additionalKeysToSanitize) {
+ this.additionalKeysToSanitize = additionalKeysToSanitize;
+ }
+
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java
index 52c44bd28260..efabc7152933 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroup.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.health;
+import java.security.Principal;
import java.util.Collection;
import java.util.function.Predicate;
@@ -24,6 +25,9 @@
import org.springframework.boot.actuate.health.HealthEndpointGroup;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.StatusAggregator;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
/**
@@ -97,10 +101,34 @@ private boolean getShowResult(SecurityContext securityContext, Show show) {
}
private boolean isAuthorized(SecurityContext securityContext) {
- if (securityContext.getPrincipal() == null) {
+ Principal principal = securityContext.getPrincipal();
+ if (principal == null) {
return false;
}
- return CollectionUtils.isEmpty(this.roles) || this.roles.stream().anyMatch(securityContext::isUserInRole);
+ if (CollectionUtils.isEmpty(this.roles)) {
+ return true;
+ }
+ boolean checkAuthorities = isSpringSecurityAuthentication(principal);
+ for (String role : this.roles) {
+ if (securityContext.isUserInRole(role)) {
+ return true;
+ }
+ if (checkAuthorities) {
+ Authentication authentication = (Authentication) principal;
+ for (GrantedAuthority authority : authentication.getAuthorities()) {
+ String name = authority.getAuthority();
+ if (role.equals(name)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean isSpringSecurityAuthentication(Principal principal) {
+ return ClassUtils.isPresent("org.springframework.security.core.Authentication", null)
+ && (principal instanceof Authentication);
}
@Override
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java
index b0001dafaaf8..31346fecb6e2 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@
*/
class AutoConfiguredHealthEndpointGroups implements HealthEndpointGroups {
- private static Predicate ALL = (name) -> true;
+ private static final Predicate ALL = (name) -> true;
private final HealthEndpointGroup primaryGroup;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java
deleted file mode 100644
index c159c78dac1d..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeHealthIndicatorConfiguration.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.health.CompositeHealthIndicator;
-import org.springframework.boot.actuate.health.DefaultHealthIndicatorRegistry;
-import org.springframework.boot.actuate.health.HealthAggregator;
-import org.springframework.boot.actuate.health.HealthIndicator;
-import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
-import org.springframework.core.ResolvableType;
-
-/**
- * Base class for configurations that can combine source beans using a
- * {@link CompositeHealthIndicator}.
- *
- * @param the health indicator type
- * @param the bean source type
- * @author Stephane Nicoll
- * @since 2.0.0
- * @deprecated since 2.0.0 in favor of {@link CompositeHealthContributorConfiguration}
- */
-@Deprecated
-public abstract class CompositeHealthIndicatorConfiguration {
-
- @Autowired
- private HealthAggregator healthAggregator;
-
- protected HealthIndicator createHealthIndicator(Map beans) {
- if (beans.size() == 1) {
- return createHealthIndicator(beans.values().iterator().next());
- }
- HealthIndicatorRegistry registry = new DefaultHealthIndicatorRegistry();
- beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
- return new CompositeHealthIndicator(this.healthAggregator, registry);
- }
-
- @SuppressWarnings("unchecked")
- protected H createHealthIndicator(S source) {
- Class>[] generics = ResolvableType.forClass(CompositeHealthIndicatorConfiguration.class, getClass())
- .resolveGenerics();
- Class indicatorClass = (Class) generics[0];
- Class sourceClass = (Class) generics[1];
- try {
- return indicatorClass.getConstructor(sourceClass).newInstance(source);
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
- }
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java
deleted file mode 100644
index d3ca609aeb90..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/CompositeReactiveHealthIndicatorConfiguration.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.Map;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.health.CompositeReactiveHealthIndicator;
-import org.springframework.boot.actuate.health.DefaultReactiveHealthIndicatorRegistry;
-import org.springframework.boot.actuate.health.HealthAggregator;
-import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
-import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
-import org.springframework.core.ResolvableType;
-
-/**
- * Reactive variant of {@link CompositeHealthIndicatorConfiguration}.
- *
- * @param the health indicator type
- * @param the bean source type
- * @author Stephane Nicoll
- * @since 2.0.0
- * @deprecated since 2.2.0 in favor of
- * {@link CompositeReactiveHealthContributorConfiguration}
- */
-@Deprecated
-public abstract class CompositeReactiveHealthIndicatorConfiguration {
-
- @Autowired
- private HealthAggregator healthAggregator;
-
- protected ReactiveHealthIndicator createHealthIndicator(Map beans) {
- if (beans.size() == 1) {
- return createHealthIndicator(beans.values().iterator().next());
- }
- ReactiveHealthIndicatorRegistry registry = new DefaultReactiveHealthIndicatorRegistry();
- beans.forEach((name, source) -> registry.register(name, createHealthIndicator(source)));
- return new CompositeReactiveHealthIndicator(this.healthAggregator, registry);
- }
-
- @SuppressWarnings("unchecked")
- protected H createHealthIndicator(S source) {
- Class>[] generics = ResolvableType.forClass(CompositeReactiveHealthIndicatorConfiguration.class, getClass())
- .resolveGenerics();
- Class indicatorClass = (Class) generics[0];
- Class sourceClass = (Class) generics[1];
- try {
- return indicatorClass.getConstructor(sourceClass).newInstance(source);
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Unable to create indicator " + indicatorClass + " for source " + sourceClass, ex);
- }
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java
deleted file mode 100644
index 19c002de4abe..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthAggregatorStatusAggregatorAdapter.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.springframework.boot.actuate.health.Health;
-import org.springframework.boot.actuate.health.HealthAggregator;
-import org.springframework.boot.actuate.health.Status;
-import org.springframework.boot.actuate.health.StatusAggregator;
-
-/**
- * Adapter class to convert a legacy {@link HealthAggregator} to a
- * {@link StatusAggregator}.
- *
- * @author Phillip Webb
- */
-@SuppressWarnings("deprecation")
-class HealthAggregatorStatusAggregatorAdapter implements StatusAggregator {
-
- private HealthAggregator healthAggregator;
-
- HealthAggregatorStatusAggregatorAdapter(HealthAggregator healthAggregator) {
- this.healthAggregator = healthAggregator;
- }
-
- @Override
- public Status getAggregateStatus(Set statuses) {
- int index = 0;
- Map healths = new LinkedHashMap<>();
- for (Status status : statuses) {
- index++;
- healths.put("health" + index, asHealth(status));
- }
- Health aggregate = this.healthAggregator.aggregate(healths);
- return aggregate.getStatus();
- }
-
- private Health asHealth(Status status) {
- return Health.status(status).build();
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java
deleted file mode 100644
index e99f170b6f9f..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthContributorRegistryHealthIndicatorRegistryAdapter.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.springframework.boot.actuate.health.HealthContributor;
-import org.springframework.boot.actuate.health.HealthContributorRegistry;
-import org.springframework.boot.actuate.health.HealthIndicator;
-import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
-import org.springframework.boot.actuate.health.NamedContributor;
-import org.springframework.util.Assert;
-
-/**
- * Adapter class to convert a {@link HealthContributorRegistry} to a legacy
- * {@link HealthIndicatorRegistry}.
- *
- * @author Phillip Webb
- */
-@SuppressWarnings("deprecation")
-class HealthContributorRegistryHealthIndicatorRegistryAdapter implements HealthIndicatorRegistry {
-
- private final HealthContributorRegistry contributorRegistry;
-
- HealthContributorRegistryHealthIndicatorRegistryAdapter(HealthContributorRegistry contributorRegistry) {
- Assert.notNull(contributorRegistry, "ContributorRegistry must not be null");
- this.contributorRegistry = contributorRegistry;
- }
-
- @Override
- public void register(String name, HealthIndicator healthIndicator) {
- this.contributorRegistry.registerContributor(name, healthIndicator);
- }
-
- @Override
- public HealthIndicator unregister(String name) {
- HealthContributor contributor = this.contributorRegistry.unregisterContributor(name);
- if (contributor instanceof HealthIndicator) {
- return (HealthIndicator) contributor;
- }
- return null;
- }
-
- @Override
- public HealthIndicator get(String name) {
- HealthContributor contributor = this.contributorRegistry.getContributor(name);
- if (contributor instanceof HealthIndicator) {
- return (HealthIndicator) contributor;
- }
- return null;
- }
-
- @Override
- public Map getAll() {
- Map all = new LinkedHashMap<>();
- for (NamedContributor> namedContributor : this.contributorRegistry) {
- if (namedContributor.getContributor() instanceof HealthIndicator) {
- all.put(namedContributor.getName(), (HealthIndicator) namedContributor.getContributor());
- }
- }
- return all;
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java
index 972ee5d3a616..096a212ecfaf 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@@ -30,23 +29,14 @@
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Phillip Webb
+ * @author Scott Frederick
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnAvailableEndpoint(endpoint = HealthEndpoint.class)
-@EnableConfigurationProperties
-@Import({ LegacyHealthEndpointAdaptersConfiguration.class, LegacyHealthEndpointCompatibilityConfiguration.class,
- HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
+@EnableConfigurationProperties(HealthEndpointProperties.class)
+@Import({ HealthEndpointConfiguration.class, ReactiveHealthEndpointConfiguration.class,
HealthEndpointWebExtensionConfiguration.class, HealthEndpointReactiveWebExtensionConfiguration.class })
public class HealthEndpointAutoConfiguration {
- @Bean
- @SuppressWarnings("deprecation")
- HealthEndpointProperties healthEndpointProperties(HealthIndicatorProperties healthIndicatorProperties) {
- HealthEndpointProperties healthEndpointProperties = new HealthEndpointProperties();
- healthEndpointProperties.getStatus().getOrder().addAll(healthIndicatorProperties.getOrder());
- healthEndpointProperties.getStatus().getHttpMapping().putAll(healthIndicatorProperties.getHttpMapping());
- return healthEndpointProperties;
- }
-
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java
index 54b074dce32a..0190380e57fd 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,9 @@
import java.util.LinkedHashMap;
import java.util.Map;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.actuate.health.CompositeHealthContributor;
import org.springframework.boot.actuate.health.CompositeReactiveHealthContributor;
import org.springframework.boot.actuate.health.Health;
@@ -28,6 +31,7 @@
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.boot.actuate.health.HealthEndpointGroups;
+import org.springframework.boot.actuate.health.HealthEndpointGroupsPostProcessor;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
import org.springframework.boot.actuate.health.NamedContributor;
@@ -88,6 +92,42 @@ HealthEndpoint healthEndpoint(HealthContributorRegistry registry, HealthEndpoint
return new HealthEndpoint(registry, groups);
}
+ @Bean
+ static HealthEndpointGroupsBeanPostProcessor healthEndpointGroupsBeanPostProcessor(
+ ObjectProvider healthEndpointGroupsPostProcessors) {
+ return new HealthEndpointGroupsBeanPostProcessor(healthEndpointGroupsPostProcessors);
+ }
+
+ /**
+ * {@link BeanPostProcessor} to invoke {@link HealthEndpointGroupsPostProcessor}
+ * beans.
+ */
+ static class HealthEndpointGroupsBeanPostProcessor implements BeanPostProcessor {
+
+ private final ObjectProvider postProcessors;
+
+ HealthEndpointGroupsBeanPostProcessor(ObjectProvider postProcessors) {
+ this.postProcessors = postProcessors;
+ }
+
+ @Override
+ public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+ if (bean instanceof HealthEndpointGroups) {
+ return applyPostProcessors((HealthEndpointGroups) bean);
+ }
+ return bean;
+ }
+
+ private Object applyPostProcessors(HealthEndpointGroups bean) {
+ for (HealthEndpointGroupsPostProcessor postProcessor : this.postProcessors.orderedStream()
+ .toArray(HealthEndpointGroupsPostProcessor[]::new)) {
+ bean = postProcessor.postProcessHealthEndpointGroups(bean);
+ }
+ return bean;
+ }
+
+ }
+
/**
* Adapter to expose {@link ReactiveHealthContributor} beans as
* {@link HealthContributor} instances.
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java
index d2b6d9c46734..6ccf2ae5a133 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,16 +27,31 @@
* Configuration properties for {@link HealthEndpoint}.
*
* @author Phillip Webb
+ * @author Leo Li
* @since 2.0.0
*/
@ConfigurationProperties("management.endpoint.health")
public class HealthEndpointProperties extends HealthProperties {
+ /**
+ * When to show full health details.
+ */
+ private Show showDetails = Show.NEVER;
+
/**
* Health endpoint groups.
*/
private Map group = new LinkedHashMap<>();
+ @Override
+ public Show getShowDetails() {
+ return this.showDetails;
+ }
+
+ public void setShowDetails(Show showDetails) {
+ this.showDetails = showDetails;
+ }
+
public Map getGroup() {
return this.group;
}
@@ -56,6 +71,12 @@ public static class Group extends HealthProperties {
*/
private Set exclude;
+ /**
+ * When to show full health details. Defaults to the value of
+ * 'management.endpoint.health.show-details'.
+ */
+ private Show showDetails;
+
public Set getInclude() {
return this.include;
}
@@ -72,6 +93,15 @@ public void setExclude(Set exclude) {
this.exclude = exclude;
}
+ @Override
+ public Show getShowDetails() {
+ return this.showDetails;
+ }
+
+ public void setShowDetails(Show showDetails) {
+ this.showDetails = showDetails;
+ }
+
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java
deleted file mode 100644
index d6ef2959aae1..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import org.springframework.boot.actuate.health.HealthContributor;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * {@link EnableAutoConfiguration Auto-configuration} for {@link HealthContributor health
- * contributors}.
- *
- * @author Andy Wilkinson
- * @author Stephane Nicoll
- * @author Phillip Webb
- * @author Vedran Pavic
- * @since 2.0.0
- * @deprecated since 2.2.0 in favor of {@link HealthContributorAutoConfiguration}
- */
-@Deprecated
-@Configuration(proxyBeanMethods = false)
-public class HealthIndicatorAutoConfiguration {
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java
deleted file mode 100644
index 930707a7a4d7..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorProperties.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
-
-/**
- * Configuration properties for some health properties.
- *
- * @author Christian Dupuis
- * @since 2.0.0
- * @deprecated since 2.2.0 in favor of {@link HealthEndpointProperties}
- */
-@Deprecated
-@ConfigurationProperties(prefix = "management.health.status")
-public class HealthIndicatorProperties {
-
- private List order = new ArrayList<>();
-
- private final Map httpMapping = new LinkedHashMap<>();
-
- @DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.order")
- public List getOrder() {
- return this.order;
- }
-
- public void setOrder(List order) {
- this.order = order;
- }
-
- @DeprecatedConfigurationProperty(replacement = "management.endpoint.health.status.http-mapping")
- public Map getHttpMapping() {
- return this.httpMapping;
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java
index 901c4031d53e..8603f79aa55e 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,11 +43,6 @@ public abstract class HealthProperties {
*/
private Show showComponents;
- /**
- * When to show full health details.
- */
- private Show showDetails = Show.NEVER;
-
/**
* Roles used to determine whether or not a user is authorized to be shown details.
* When empty, all authenticated users are authorized.
@@ -66,13 +61,7 @@ public void setShowComponents(Show showComponents) {
this.showComponents = showComponents;
}
- public Show getShowDetails() {
- return this.showDetails;
- }
-
- public void setShowDetails(Show showDetails) {
- this.showDetails = showDetails;
- }
+ public abstract Show getShowDetails();
public Set getRoles() {
return this.roles;
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthStatusHttpMapperHttpCodeStatusMapperAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthStatusHttpMapperHttpCodeStatusMapperAdapter.java
deleted file mode 100644
index fcade05e3c52..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthStatusHttpMapperHttpCodeStatusMapperAdapter.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
-import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
-import org.springframework.boot.actuate.health.Status;
-
-/**
- * Adapter class to convert a legacy {@link HealthStatusHttpMapper} to a
- * {@link HttpCodeStatusMapper}.
- *
- * @author Phillip Webb
- */
-@SuppressWarnings("deprecation")
-class HealthStatusHttpMapperHttpCodeStatusMapperAdapter implements HttpCodeStatusMapper {
-
- private final HealthStatusHttpMapper healthStatusHttpMapper;
-
- HealthStatusHttpMapperHttpCodeStatusMapperAdapter(HealthStatusHttpMapper healthStatusHttpMapper) {
- this.healthStatusHttpMapper = healthStatusHttpMapper;
- }
-
- @Override
- public int getStatusCode(Status status) {
- return this.healthStatusHttpMapper.mapStatus(status);
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java
index 585fe7a21991..463fbea66bcf 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/IncludeExcludeGroupMemberPredicate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public boolean test(String name) {
}
private boolean isIncluded(String name) {
- return this.include.contains("*") || this.include.contains(clean(name));
+ return this.include.isEmpty() || this.include.contains("*") || this.include.contains(clean(name));
}
private boolean isExcluded(String name) {
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java
deleted file mode 100644
index e04f0a2c5afa..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointAdaptersConfiguration.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import org.springframework.boot.actuate.health.HttpCodeStatusMapper;
-import org.springframework.boot.actuate.health.StatusAggregator;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * Configuration to adapt legacy deprecated health endpoint classes and interfaces.
- *
- * @author Phillip Webb
- * @see HealthEndpointAutoConfiguration
- */
-@Configuration(proxyBeanMethods = false)
-@SuppressWarnings("deprecation")
-class LegacyHealthEndpointAdaptersConfiguration {
-
- @Bean
- @ConditionalOnBean(org.springframework.boot.actuate.health.HealthAggregator.class)
- StatusAggregator healthAggregatorStatusAggregatorAdapter(
- org.springframework.boot.actuate.health.HealthAggregator healthAggregator) {
- return new HealthAggregatorStatusAggregatorAdapter(healthAggregator);
- }
-
- @Bean
- @ConditionalOnBean(org.springframework.boot.actuate.health.HealthStatusHttpMapper.class)
- HttpCodeStatusMapper healthStatusHttpMapperHttpCodeStatusMapperAdapter(
- org.springframework.boot.actuate.health.HealthStatusHttpMapper healthStatusHttpMapper) {
- return new HealthStatusHttpMapperHttpCodeStatusMapperAdapter(healthStatusHttpMapper);
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java
deleted file mode 100644
index 4c1b1add27d7..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/LegacyHealthEndpointCompatibilityConfiguration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import reactor.core.publisher.Mono;
-
-import org.springframework.boot.actuate.health.HealthAggregator;
-import org.springframework.boot.actuate.health.HealthContributorRegistry;
-import org.springframework.boot.actuate.health.HealthIndicatorRegistry;
-import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
-import org.springframework.boot.actuate.health.OrderedHealthAggregator;
-import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
-import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.util.CollectionUtils;
-
-/**
- * Configuration to adapt legacy deprecated health endpoint classes and interfaces.
- *
- * @author Phillip Webb
- * @see HealthEndpointAutoConfiguration
- */
-@Configuration(proxyBeanMethods = false)
-@SuppressWarnings("deprecation")
-@EnableConfigurationProperties(HealthIndicatorProperties.class)
-class LegacyHealthEndpointCompatibilityConfiguration {
-
- @Bean
- @ConditionalOnMissingBean
- HealthAggregator healthAggregator(HealthIndicatorProperties healthIndicatorProperties) {
- OrderedHealthAggregator aggregator = new OrderedHealthAggregator();
- if (!CollectionUtils.isEmpty(healthIndicatorProperties.getOrder())) {
- aggregator.setStatusOrder(healthIndicatorProperties.getOrder());
- }
- return aggregator;
- }
-
- @Bean
- @ConditionalOnMissingBean
- HealthStatusHttpMapper healthStatusHttpMapper(HealthIndicatorProperties healthIndicatorProperties) {
- HealthStatusHttpMapper mapper = new HealthStatusHttpMapper();
- if (!CollectionUtils.isEmpty(healthIndicatorProperties.getHttpMapping())) {
- mapper.setStatusMapping(healthIndicatorProperties.getHttpMapping());
- }
- return mapper;
- }
-
- @Bean
- @ConditionalOnMissingBean(HealthIndicatorRegistry.class)
- HealthContributorRegistryHealthIndicatorRegistryAdapter healthIndicatorRegistry(
- HealthContributorRegistry healthContributorRegistry) {
- return new HealthContributorRegistryHealthIndicatorRegistryAdapter(healthContributorRegistry);
- }
-
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(Mono.class)
- static class LegacyReactiveHealthEndpointCompatibilityConfiguration {
-
- @Bean
- @ConditionalOnMissingBean(ReactiveHealthIndicatorRegistry.class)
- ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter reactiveHealthIndicatorRegistry(
- ReactiveHealthContributorRegistry reactiveHealthContributorRegistry) {
- return new ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(
- reactiveHealthContributorRegistry);
- }
-
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java
deleted file mode 100644
index 863edd6aea52..000000000000
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2012-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.actuate.autoconfigure.health;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.springframework.boot.actuate.health.NamedContributor;
-import org.springframework.boot.actuate.health.ReactiveHealthContributor;
-import org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry;
-import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
-import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry;
-import org.springframework.util.Assert;
-
-/**
- * Adapter class to convert a {@link ReactiveHealthContributorRegistry} to a legacy
- * {@link ReactiveHealthIndicatorRegistry}.
- *
- * @author Phillip Webb
- */
-@SuppressWarnings("deprecation")
-class ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter
- implements ReactiveHealthIndicatorRegistry {
-
- private final ReactiveHealthContributorRegistry contributorRegistry;
-
- ReactiveHealthContributorRegistryReactiveHealthIndicatorRegistryAdapter(
- ReactiveHealthContributorRegistry contributorRegistry) {
- Assert.notNull(contributorRegistry, "ContributorRegistry must not be null");
- this.contributorRegistry = contributorRegistry;
- }
-
- @Override
- public void register(String name, ReactiveHealthIndicator healthIndicator) {
- this.contributorRegistry.registerContributor(name, healthIndicator);
- }
-
- @Override
- public ReactiveHealthIndicator unregister(String name) {
- ReactiveHealthContributor contributor = this.contributorRegistry.unregisterContributor(name);
- if (contributor instanceof ReactiveHealthIndicator) {
- return (ReactiveHealthIndicator) contributor;
- }
- return null;
- }
-
- @Override
- public ReactiveHealthIndicator get(String name) {
- ReactiveHealthContributor contributor = this.contributorRegistry.getContributor(name);
- if (contributor instanceof ReactiveHealthIndicator) {
- return (ReactiveHealthIndicator) contributor;
- }
- return null;
- }
-
- @Override
- public Map getAll() {
- Map all = new LinkedHashMap<>();
- for (NamedContributor> namedContributor : this.contributorRegistry) {
- if (namedContributor.getContributor() instanceof ReactiveHealthIndicator) {
- all.put(namedContributor.getName(), (ReactiveHealthIndicator) namedContributor.getContributor());
- }
- }
- return all;
- }
-
-}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java
index 885c4e57de5e..26d2ba468166 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,19 +17,20 @@
package org.springframework.boot.actuate.autoconfigure.jdbc;
import java.util.Collection;
+import java.util.Iterator;
import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
-import org.springframework.boot.actuate.health.AbstractHealthIndicator;
-import org.springframework.boot.actuate.health.Health.Builder;
+import org.springframework.boot.actuate.health.CompositeHealthContributor;
import org.springframework.boot.actuate.health.HealthContributor;
-import org.springframework.boot.actuate.health.HealthIndicator;
+import org.springframework.boot.actuate.health.NamedContributor;
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -37,6 +38,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadata;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
@@ -44,6 +46,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
+import org.springframework.util.Assert;
/**
* {@link EnableAutoConfiguration Auto-configuration} for
@@ -54,6 +57,8 @@
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Arthur Kalimullin
+ * @author Julio Gomez
+ * @author Safeer Ansari
* @since 2.0.0
*/
@Configuration(proxyBeanMethods = false)
@@ -61,33 +66,48 @@
@ConditionalOnBean(DataSource.class)
@ConditionalOnEnabledHealthIndicator("db")
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
-public class DataSourceHealthContributorAutoConfiguration extends
- CompositeHealthContributorConfiguration implements InitializingBean {
+@EnableConfigurationProperties(DataSourceHealthIndicatorProperties.class)
+public class DataSourceHealthContributorAutoConfiguration implements InitializingBean {
private final Collection metadataProviders;
private DataSourcePoolMetadataProvider poolMetadataProvider;
- public DataSourceHealthContributorAutoConfiguration(Map dataSources,
+ public DataSourceHealthContributorAutoConfiguration(
ObjectProvider metadataProviders) {
this.metadataProviders = metadataProviders.orderedStream().collect(Collectors.toList());
}
@Override
- public void afterPropertiesSet() throws Exception {
+ public void afterPropertiesSet() {
this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider(this.metadataProviders);
}
@Bean
@ConditionalOnMissingBean(name = { "dbHealthIndicator", "dbHealthContributor" })
- public HealthContributor dbHealthContributor(Map dataSources) {
+ public HealthContributor dbHealthContributor(Map dataSources,
+ DataSourceHealthIndicatorProperties dataSourceHealthIndicatorProperties) {
+ if (dataSourceHealthIndicatorProperties.isIgnoreRoutingDataSources()) {
+ Map filteredDatasources = dataSources.entrySet().stream()
+ .filter((e) -> !(e.getValue() instanceof AbstractRoutingDataSource))
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ return createContributor(filteredDatasources);
+ }
return createContributor(dataSources);
}
- @Override
- protected AbstractHealthIndicator createIndicator(DataSource source) {
+ private HealthContributor createContributor(Map beans) {
+ Assert.notEmpty(beans, "Beans must not be empty");
+ if (beans.size() == 1) {
+ return createContributor(beans.values().iterator().next());
+ }
+ return CompositeHealthContributor.fromMap(beans, this::createContributor);
+ }
+
+ private HealthContributor createContributor(DataSource source) {
if (source instanceof AbstractRoutingDataSource) {
- return new RoutingDataSourceHealthIndicator();
+ AbstractRoutingDataSource routingDataSource = (AbstractRoutingDataSource) source;
+ return new RoutingDataSourceHealthContributor(routingDataSource, this::createContributor);
}
return new DataSourceHealthIndicator(source, getValidationQuery(source));
}
@@ -98,14 +118,32 @@ private String getValidationQuery(DataSource source) {
}
/**
- * {@link HealthIndicator} used for {@link AbstractRoutingDataSource} beans where we
- * can't actually query for the status.
+ * {@link CompositeHealthContributor} used for {@link AbstractRoutingDataSource} beans
+ * where the overall health is composed of a {@link DataSourceHealthIndicator} for
+ * each routed datasource.
*/
- static class RoutingDataSourceHealthIndicator extends AbstractHealthIndicator {
+ static class RoutingDataSourceHealthContributor implements CompositeHealthContributor {
+
+ private final CompositeHealthContributor delegate;
+
+ private static final String UNNAMED_DATASOURCE_KEY = "unnamed";
+
+ RoutingDataSourceHealthContributor(AbstractRoutingDataSource routingDataSource,
+ Function contributorFunction) {
+ Map routedDataSources = routingDataSource.getResolvedDataSources().entrySet().stream()
+ .collect(Collectors.toMap((e) -> Objects.toString(e.getKey(), UNNAMED_DATASOURCE_KEY),
+ Map.Entry::getValue));
+ this.delegate = CompositeHealthContributor.fromMap(routedDataSources, contributorFunction);
+ }
+
+ @Override
+ public HealthContributor getContributor(String name) {
+ return this.delegate.getContributor(name);
+ }
@Override
- protected void doHealthCheck(Builder builder) throws Exception {
- builder.unknown().withDetail("routing", true);
+ public Iterator> iterator() {
+ return this.delegate.iterator();
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorProperties.java
new file mode 100644
index 000000000000..5efe2583e7f0
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorProperties.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.jdbc;
+
+import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * External configuration properties for {@link DataSourceHealthIndicator}.
+ *
+ * @author Julio Gomez
+ * @since 2.4.0
+ */
+@ConfigurationProperties(prefix = "management.health.db")
+public class DataSourceHealthIndicatorProperties {
+
+ /**
+ * Whether to ignore AbstractRoutingDataSources when creating database health
+ * indicators.
+ */
+ private boolean ignoreRoutingDataSources = false;
+
+ public boolean isIgnoreRoutingDataSources() {
+ return this.ignoreRoutingDataSources;
+ }
+
+ public void setIgnoreRoutingDataSources(boolean ignoreRoutingDataSources) {
+ this.ignoreRoutingDataSources = ignoreRoutingDataSources;
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java
index a86bea91e234..8de4be5b8170 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,16 +56,15 @@ public LogFileWebEndpoint logFileWebEndpoint(ObjectProvider logFile,
private static class LogFileCondition extends SpringBootCondition {
- @SuppressWarnings("deprecation")
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
- String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY, LogFile.FILE_PROPERTY);
+ String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY);
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
if (StringUtils.hasText(config)) {
return ConditionOutcome.match(message.found(LogFile.FILE_NAME_PROPERTY).items(config));
}
- config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY, LogFile.PATH_PROPERTY);
+ config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY);
if (StringUtils.hasText(config)) {
return ConditionOutcome.match(message.found(LogFile.FILE_PATH_PROPERTY).items(config));
}
@@ -76,12 +75,8 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
return ConditionOutcome.noMatch(message.didNotFind("logging file").atAll());
}
- private String getLogFileConfig(Environment environment, String configName, String deprecatedConfigName) {
- String config = environment.resolvePlaceholders("${" + configName + ":}");
- if (StringUtils.hasText(config)) {
- return config;
- }
- return environment.resolvePlaceholders("${" + deprecatedConfigName + ":}");
+ private String getLogFileConfig(Environment environment, String configName) {
+ return environment.resolvePlaceholders("${" + configName + ":}");
}
}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/AutoConfiguredCompositeMeterRegistry.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/AutoConfiguredCompositeMeterRegistry.java
new file mode 100644
index 000000000000..d38b43c271b2
--- /dev/null
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/AutoConfiguredCompositeMeterRegistry.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012-2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.actuate.autoconfigure.metrics;
+
+import java.util.List;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
+
+/**
+ * Specialization of {@link CompositeMeterRegistry} used to identify the auto-configured
+ * composite.
+ *
+ * @author Andy Wilkinson
+ */
+class AutoConfiguredCompositeMeterRegistry extends CompositeMeterRegistry {
+
+ AutoConfiguredCompositeMeterRegistry(Clock clock, List registries) {
+ super(clock, registries);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryAutoConfiguration.java
index f9452356de92..a020c76eaf46 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.java
index cd15fac2caf8..4e7522156526 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,8 +42,8 @@ class CompositeMeterRegistryConfiguration {
@Bean
@Primary
- CompositeMeterRegistry compositeMeterRegistry(Clock clock, List registries) {
- return new CompositeMeterRegistry(clock, registries);
+ AutoConfiguredCompositeMeterRegistry compositeMeterRegistry(Clock clock, List registries) {
+ return new AutoConfiguredCompositeMeterRegistry(clock, registries);
}
static class MultipleNonPrimaryMeterRegistriesCondition extends NoneNestedConditions {
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java
index 98f50edf1db7..629e3dc8f32c 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/JvmMetricsAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@
* @since 2.1.0
*/
@Configuration(proxyBeanMethods = false)
-@AutoConfigureAfter(MetricsAutoConfiguration.class)
+@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnBean(MeterRegistry.class)
public class JvmMetricsAutoConfiguration {
diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java
index f2bbcfe6e196..3b43999a77b4 100644
--- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java
+++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2019 the original author or authors.
+ * Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,39 +16,70 @@
package org.springframework.boot.actuate.autoconfigure.metrics;
-import java.util.Collections;
-
-import javax.management.MBeanServer;
-
import io.micrometer.core.instrument.MeterRegistry;
-import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics;
-import org.apache.kafka.clients.consumer.KafkaConsumer;
+import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics;
+import io.micrometer.core.instrument.binder.kafka.KafkaStreamsMetrics;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
+import org.springframework.boot.autoconfigure.kafka.DefaultKafkaConsumerFactoryCustomizer;
+import org.springframework.boot.autoconfigure.kafka.DefaultKafkaProducerFactoryCustomizer;
+import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
+import org.springframework.boot.autoconfigure.kafka.StreamsBuilderFactoryBeanCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.config.StreamsBuilderFactoryBean;
+import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+import org.springframework.kafka.core.DefaultKafkaProducerFactory;
+import org.springframework.kafka.core.MicrometerConsumerListener;
+import org.springframework.kafka.core.MicrometerProducerListener;
+import org.springframework.kafka.core.ProducerFactory;
+import org.springframework.kafka.streams.KafkaStreamsMicrometerListener;
/**
* Auto-configuration for Kafka metrics.
*
* @author Andy Wilkinson
+ * @author Stephane Nicoll
+ * @author Eddú Meléndez
* @since 2.1.0
*/
@Configuration(proxyBeanMethods = false)
-@AutoConfigureAfter({ MetricsAutoConfiguration.class, JmxAutoConfiguration.class })
-@ConditionalOnClass({ KafkaConsumerMetrics.class, KafkaConsumer.class })
+@AutoConfigureBefore(KafkaAutoConfiguration.class)
+@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class })
+@ConditionalOnClass({ KafkaClientMetrics.class, ProducerFactory.class })
@ConditionalOnBean(MeterRegistry.class)
public class KafkaMetricsAutoConfiguration {
@Bean
- @ConditionalOnMissingBean
- @ConditionalOnBean(MBeanServer.class)
- public KafkaConsumerMetrics kafkaConsumerMetrics(MBeanServer mbeanServer) {
- return new KafkaConsumerMetrics(mbeanServer, Collections.emptyList());
+ public DefaultKafkaProducerFactoryCustomizer kafkaProducerMetrics(MeterRegistry meterRegistry) {
+ return (producerFactory) -> addListener(producerFactory, meterRegistry);
+ }
+
+ @Bean
+ public DefaultKafkaConsumerFactoryCustomizer kafkaConsumerMetrics(MeterRegistry meterRegistry) {
+ return (consumerFactory) -> addListener(consumerFactory, meterRegistry);
+ }
+
+ private void addListener(DefaultKafkaConsumerFactory