Commit 674a909b authored by Phillip Webb's avatar Phillip Webb

Support mixed case endpoint IDs with enabled

Update `OnEnabledEndpointCondition` so that mixed case endpoint IDs
are supported. Prior to this commit an
`InvalidConfigurationPropertyNameException` would be thrown when trying
to enabled or disable an endpoint with a camel case ID.

See gh-14773
parent 138d8547
......@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.condition;
import java.util.Map;
import java.util.Optional;
import org.springframework.boot.actuate.endpoint.EndpointId;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
......@@ -54,8 +55,8 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
AnnotationAttributes attributes = getEndpointAttributes(context, metadata);
String id = attributes.getString("id");
String key = "management.endpoint." + id + ".enabled";
EndpointId id = EndpointId.of(attributes.getString("id"));
String key = "management.endpoint." + id.toLowerCaseString() + ".enabled";
Boolean userDefinedEnabled = environment.getProperty(key, Boolean.class);
if (userDefinedEnabled != null) {
return new ConditionOutcome(userDefinedEnabled,
......
......@@ -140,6 +140,14 @@ public class ConditionalOnEnabledEndpointTests {
});
}
@Test
public void outcomeWhenEndpointEnabledPropertyIsTrueAndMixedCaseShouldMatch() {
this.contextRunner.withPropertyValues("management.endpoint.foo-bar.enabled=true")
.withUserConfiguration(
FooBarEndpointEnabledByDefaultFalseConfiguration.class)
.run((context) -> assertThat(context).hasBean("fooBar"));
}
@Endpoint(id = "foo", enableByDefault = true)
static class FooEndpointEnabledByDefaultTrue {
......@@ -150,6 +158,11 @@ public class ConditionalOnEnabledEndpointTests {
}
@Endpoint(id = "fooBar", enableByDefault = false)
static class FooBarEndpointEnabledByDefaultFalse {
}
@EndpointExtension(endpoint = FooEndpointEnabledByDefaultTrue.class, filter = TestFilter.class)
static class FooEndpointExtensionEnabledByDefaultTrue {
......@@ -191,6 +204,17 @@ public class ConditionalOnEnabledEndpointTests {
}
@Configuration
static class FooBarEndpointEnabledByDefaultFalseConfiguration {
@Bean
@ConditionalOnEnabledEndpoint
public FooBarEndpointEnabledByDefaultFalse fooBar() {
return new FooBarEndpointEnabledByDefaultFalse();
}
}
@Configuration
static class FooEndpointAndExtensionEnabledByDefaultTrueConfiguration {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment