Skip to content

Commit dc4dbd1

Browse files
committed
Rename management.server.accesslog.prefix
Closes gh-44196
1 parent 8ff1e63 commit dc4dbd1

File tree

6 files changed

+182
-26
lines changed

6 files changed

+182
-26
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/reactive/ReactiveManagementChildContextConfiguration.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
*
5757
* @author Andy Wilkinson
5858
* @author Phillip Webb
59+
* @author Moritz Halbritter
5960
* @since 2.0.0
6061
*/
6162
@EnableWebFlux
@@ -99,18 +100,23 @@ JettyAccessLogCustomizer jettyManagementAccessLogCustomizer(ManagementServerProp
99100

100101
abstract static class AccessLogCustomizer implements Ordered {
101102

102-
private final ManagementServerProperties properties;
103+
private final String prefix;
103104

104-
AccessLogCustomizer(ManagementServerProperties properties) {
105-
this.properties = properties;
105+
AccessLogCustomizer(String prefix) {
106+
this.prefix = prefix;
106107
}
107108

108-
protected String customizePrefix(String prefix) {
109-
prefix = (prefix != null) ? prefix : "";
110-
if (prefix.startsWith(this.properties.getAccesslog().getPrefix())) {
111-
return prefix;
109+
protected String customizePrefix(String existingPrefix) {
110+
if (this.prefix == null) {
111+
return existingPrefix;
112112
}
113-
return this.properties.getAccesslog().getPrefix() + prefix;
113+
if (existingPrefix == null) {
114+
return this.prefix;
115+
}
116+
if (existingPrefix.startsWith(this.prefix)) {
117+
return existingPrefix;
118+
}
119+
return this.prefix + existingPrefix;
114120
}
115121

116122
@Override
@@ -124,7 +130,7 @@ static class TomcatAccessLogCustomizer extends AccessLogCustomizer
124130
implements WebServerFactoryCustomizer<TomcatReactiveWebServerFactory> {
125131

126132
TomcatAccessLogCustomizer(ManagementServerProperties properties) {
127-
super(properties);
133+
super(properties.getTomcat().getAccesslog().getPrefix());
128134
}
129135

130136
@Override
@@ -151,7 +157,7 @@ static class UndertowAccessLogCustomizer extends AccessLogCustomizer
151157
implements WebServerFactoryCustomizer<UndertowReactiveWebServerFactory> {
152158

153159
UndertowAccessLogCustomizer(ManagementServerProperties properties) {
154-
super(properties);
160+
super(properties.getUndertow().getAccesslog().getPrefix());
155161
}
156162

157163
@Override
@@ -165,7 +171,7 @@ static class JettyAccessLogCustomizer extends AccessLogCustomizer
165171
implements WebServerFactoryCustomizer<JettyReactiveWebServerFactory> {
166172

167173
JettyAccessLogCustomizer(ManagementServerProperties properties) {
168-
super(properties);
174+
super(properties.getJetty().getAccesslog().getPrefix());
169175
}
170176

171177
@Override

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerProperties.java

+46-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @author Dave Syer
3131
* @author Stephane Nicoll
3232
* @author Vedran Pavic
33+
* @author Moritz Halbritter
3334
* @since 2.0.0
3435
* @see ServerProperties
3536
*/
@@ -57,7 +58,11 @@ public class ManagementServerProperties {
5758
@NestedConfigurationProperty
5859
private Ssl ssl;
5960

60-
private final Accesslog accesslog = new Accesslog();
61+
private final Jetty jetty = new Jetty();
62+
63+
private final Tomcat tomcat = new Tomcat();
64+
65+
private final Undertow undertow = new Undertow();
6166

6267
/**
6368
* Returns the management port or {@code null} if the
@@ -103,6 +108,18 @@ public void setSsl(Ssl ssl) {
103108
this.ssl = ssl;
104109
}
105110

111+
public Jetty getJetty() {
112+
return this.jetty;
113+
}
114+
115+
public Tomcat getTomcat() {
116+
return this.tomcat;
117+
}
118+
119+
public Undertow getUndertow() {
120+
return this.undertow;
121+
}
122+
106123
private String cleanBasePath(String basePath) {
107124
String candidate = null;
108125
if (StringUtils.hasLength(basePath)) {
@@ -119,8 +136,34 @@ private String cleanBasePath(String basePath) {
119136
return candidate;
120137
}
121138

122-
public Accesslog getAccesslog() {
123-
return this.accesslog;
139+
public static class Jetty {
140+
141+
private final Accesslog accesslog = new Accesslog();
142+
143+
public Accesslog getAccesslog() {
144+
return this.accesslog;
145+
}
146+
147+
}
148+
149+
public static class Tomcat {
150+
151+
private final Accesslog accesslog = new Accesslog();
152+
153+
public Accesslog getAccesslog() {
154+
return this.accesslog;
155+
}
156+
157+
}
158+
159+
public static class Undertow {
160+
161+
private final Accesslog accesslog = new Accesslog();
162+
163+
public Accesslog getAccesslog() {
164+
return this.accesslog;
165+
}
166+
124167
}
125168

126169
public static class Accesslog {

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ServletManagementChildContextConfiguration.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @author Andy Wilkinson
6464
* @author Eddú Meléndez
6565
* @author Phillip Webb
66+
* @author Moritz Halbritter
6667
*/
6768
@ManagementContextConfiguration(value = ManagementContextType.CHILD, proxyBeanMethods = false)
6869
@ConditionalOnWebApplication(type = Type.SERVLET)
@@ -136,18 +137,23 @@ private String getContextPath(ManagementServerProperties managementServerPropert
136137

137138
abstract static class AccessLogCustomizer implements Ordered {
138139

139-
private final ManagementServerProperties properties;
140+
private final String prefix;
140141

141-
AccessLogCustomizer(ManagementServerProperties properties) {
142-
this.properties = properties;
142+
AccessLogCustomizer(String prefix) {
143+
this.prefix = prefix;
143144
}
144145

145-
protected String customizePrefix(String prefix) {
146-
prefix = (prefix != null) ? prefix : "";
147-
if (prefix.startsWith(this.properties.getAccesslog().getPrefix())) {
148-
return prefix;
146+
protected String customizePrefix(String existingPrefix) {
147+
if (this.prefix == null) {
148+
return existingPrefix;
149149
}
150-
return this.properties.getAccesslog().getPrefix() + prefix;
150+
if (existingPrefix == null) {
151+
return this.prefix;
152+
}
153+
if (existingPrefix.startsWith(this.prefix)) {
154+
return existingPrefix;
155+
}
156+
return this.prefix + existingPrefix;
151157
}
152158

153159
@Override
@@ -161,7 +167,7 @@ static class TomcatAccessLogCustomizer extends AccessLogCustomizer
161167
implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
162168

163169
TomcatAccessLogCustomizer(ManagementServerProperties properties) {
164-
super(properties);
170+
super(properties.getTomcat().getAccesslog().getPrefix());
165171
}
166172

167173
@Override
@@ -188,7 +194,7 @@ static class UndertowAccessLogCustomizer extends AccessLogCustomizer
188194
implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> {
189195

190196
UndertowAccessLogCustomizer(ManagementServerProperties properties) {
191-
super(properties);
197+
super(properties.getUndertow().getAccesslog().getPrefix());
192198
}
193199

194200
@Override
@@ -202,7 +208,7 @@ static class JettyAccessLogCustomizer extends AccessLogCustomizer
202208
implements WebServerFactoryCustomizer<JettyServletWebServerFactory> {
203209

204210
JettyAccessLogCustomizer(ManagementServerProperties properties) {
205-
super(properties);
211+
super(properties.getJetty().getAccesslog().getPrefix());
206212
}
207213

208214
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.web.reactive;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.boot.actuate.autoconfigure.web.reactive.ReactiveManagementChildContextConfiguration.AccessLogCustomizer;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link ReactiveManagementChildContextConfiguration}.
27+
*
28+
* @author Moritz Halbritter
29+
*/
30+
class ReactiveManagementChildContextConfigurationTests {
31+
32+
@Test
33+
void accessLogCustomizer() {
34+
AccessLogCustomizer customizer = new AccessLogCustomizer("prefix") {
35+
};
36+
assertThat(customizer.customizePrefix(null)).isEqualTo("prefix");
37+
assertThat(customizer.customizePrefix("existing")).isEqualTo("prefixexisting");
38+
assertThat(customizer.customizePrefix("prefixexisting")).isEqualTo("prefixexisting");
39+
}
40+
41+
@Test
42+
void accessLogCustomizerWithNullPrefix() {
43+
AccessLogCustomizer customizer = new AccessLogCustomizer(null) {
44+
};
45+
assertThat(customizer.customizePrefix(null)).isEqualTo(null);
46+
assertThat(customizer.customizePrefix("existing")).isEqualTo("existing");
47+
}
48+
49+
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementServerPropertiesTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*
2626
* @author Phillip Webb
2727
* @author Stephane Nicoll
28+
* @author Moritz Halbritter
2829
*/
2930
class ManagementServerPropertiesTests {
3031

@@ -71,7 +72,9 @@ void slashOfBasePathIsDefaultValue() {
7172
@Test
7273
void accessLogsArePrefixedByDefault() {
7374
ManagementServerProperties properties = new ManagementServerProperties();
74-
assertThat(properties.getAccesslog().getPrefix()).isEqualTo("management_");
75+
assertThat(properties.getTomcat().getAccesslog().getPrefix()).isEqualTo("management_");
76+
assertThat(properties.getJetty().getAccesslog().getPrefix()).isEqualTo("management_");
77+
assertThat(properties.getUndertow().getAccesslog().getPrefix()).isEqualTo("management_");
7578
}
7679

7780
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.web.servlet;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.boot.actuate.autoconfigure.web.servlet.ServletManagementChildContextConfiguration.AccessLogCustomizer;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link ServletManagementChildContextConfiguration}.
27+
*
28+
* @author Moritz Halbritter
29+
*/
30+
class ServletManagementChildContextConfigurationTests {
31+
32+
@Test
33+
void accessLogCustomizer() {
34+
AccessLogCustomizer customizer = new AccessLogCustomizer("prefix") {
35+
};
36+
assertThat(customizer.customizePrefix(null)).isEqualTo("prefix");
37+
assertThat(customizer.customizePrefix("existing")).isEqualTo("prefixexisting");
38+
assertThat(customizer.customizePrefix("prefixexisting")).isEqualTo("prefixexisting");
39+
}
40+
41+
@Test
42+
void accessLogCustomizerWithNullPrefix() {
43+
AccessLogCustomizer customizer = new AccessLogCustomizer(null) {
44+
};
45+
assertThat(customizer.customizePrefix(null)).isEqualTo(null);
46+
assertThat(customizer.customizePrefix("existing")).isEqualTo("existing");
47+
}
48+
49+
}

0 commit comments

Comments
 (0)