Skip to content

Commit 674a909

Browse files
committed
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
1 parent 138d854 commit 674a909

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Optional;
2121

22+
import org.springframework.boot.actuate.endpoint.EndpointId;
2223
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
2324
import org.springframework.boot.actuate.endpoint.annotation.EndpointExtension;
2425
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
@@ -54,8 +55,8 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
5455
AnnotatedTypeMetadata metadata) {
5556
Environment environment = context.getEnvironment();
5657
AnnotationAttributes attributes = getEndpointAttributes(context, metadata);
57-
String id = attributes.getString("id");
58-
String key = "management.endpoint." + id + ".enabled";
58+
EndpointId id = EndpointId.of(attributes.getString("id"));
59+
String key = "management.endpoint." + id.toLowerCaseString() + ".enabled";
5960
Boolean userDefinedEnabled = environment.getProperty(key, Boolean.class);
6061
if (userDefinedEnabled != null) {
6162
return new ConditionOutcome(userDefinedEnabled,

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ public void outcomeWithNoReferenceShouldFail() {
140140
});
141141
}
142142

143+
@Test
144+
public void outcomeWhenEndpointEnabledPropertyIsTrueAndMixedCaseShouldMatch() {
145+
this.contextRunner.withPropertyValues("management.endpoint.foo-bar.enabled=true")
146+
.withUserConfiguration(
147+
FooBarEndpointEnabledByDefaultFalseConfiguration.class)
148+
.run((context) -> assertThat(context).hasBean("fooBar"));
149+
}
150+
143151
@Endpoint(id = "foo", enableByDefault = true)
144152
static class FooEndpointEnabledByDefaultTrue {
145153

@@ -150,6 +158,11 @@ static class FooEndpointEnabledByDefaultFalse {
150158

151159
}
152160

161+
@Endpoint(id = "fooBar", enableByDefault = false)
162+
static class FooBarEndpointEnabledByDefaultFalse {
163+
164+
}
165+
153166
@EndpointExtension(endpoint = FooEndpointEnabledByDefaultTrue.class, filter = TestFilter.class)
154167
static class FooEndpointExtensionEnabledByDefaultTrue {
155168

@@ -191,6 +204,17 @@ public FooEndpointEnabledByDefaultFalse foo() {
191204

192205
}
193206

207+
@Configuration
208+
static class FooBarEndpointEnabledByDefaultFalseConfiguration {
209+
210+
@Bean
211+
@ConditionalOnEnabledEndpoint
212+
public FooBarEndpointEnabledByDefaultFalse fooBar() {
213+
return new FooBarEndpointEnabledByDefaultFalse();
214+
}
215+
216+
}
217+
194218
@Configuration
195219
static class FooEndpointAndExtensionEnabledByDefaultTrueConfiguration {
196220

0 commit comments

Comments
 (0)