Skip to content

Commit 79eb949

Browse files
committed
Respect management.ssl.* settings
The managment.ssl.* properties needs to be taken into account when they are explicitly set and the managment.port differs from server.port fixes #333
1 parent 30d76a7 commit 79eb949

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

spring-boot-admin-starter-client/src/main/java/de/codecentric/boot/admin/config/AdminClientProperties.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.beans.factory.annotation.Value;
2525
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
2626
import org.springframework.boot.autoconfigure.web.ServerProperties;
27+
import org.springframework.boot.context.embedded.Ssl;
2728
import org.springframework.boot.context.event.ApplicationReadyEvent;
2829
import org.springframework.boot.context.properties.ConfigurationProperties;
2930
import org.springframework.context.event.EventListener;
@@ -94,8 +95,9 @@ public String getServiceUrl() {
9495
"serviceUrl must be set when deployed to servlet-container");
9596
}
9697

97-
return UriComponentsBuilder.newInstance().scheme(getScheme()).host(getServiceHost())
98-
.port(serverPort).path(server.getContextPath()).toUriString();
98+
return UriComponentsBuilder.newInstance().scheme(getScheme(server.getSsl()))
99+
.host(getServiceHost()).port(serverPort).path(server.getContextPath())
100+
.toUriString();
99101
}
100102

101103
public String getManagementUrl() {
@@ -110,7 +112,8 @@ public String getManagementUrl() {
110112
.toUriString();
111113
}
112114

113-
return UriComponentsBuilder.newInstance().scheme(getScheme()).host(getManagementHost())
115+
Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl();
116+
return UriComponentsBuilder.newInstance().scheme(getScheme(ssl)).host(getManagementHost())
114117
.port(managementPort).path(management.getContextPath()).toUriString();
115118
}
116119

@@ -151,8 +154,8 @@ public boolean isPreferIp() {
151154
return preferIp;
152155
}
153156

154-
private String getScheme() {
155-
return server.getSsl() != null && server.getSsl().isEnabled() ? "https" : "http";
157+
private String getScheme(Ssl ssl) {
158+
return ssl != null && ssl.isEnabled() ? "https" : "http";
156159
}
157160

158161
private String getHost(InetAddress address) {

spring-boot-admin-starter-client/src/test/java/de/codecentric/boot/admin/config/AdminClientPropertiesTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ public void test_ssl() {
132132
assertThat(clientProperties.getServiceUrl(), is("https://" + getHostname() + ":8080"));
133133
}
134134

135+
@Test
136+
public void test_ssl_managment() {
137+
load("management.ssl.key-store=somefile.jks", "management.ssl.key-store-password=password",
138+
"local.server.port=8080", "local.management.port=9090");
139+
AdminClientProperties clientProperties = context.getBean(AdminClientProperties.class);
140+
141+
publishApplicationReadyEvent(clientProperties);
142+
143+
assertThat(clientProperties.getManagementUrl(), is("https://" + getHostname() + ":9090"));
144+
assertThat(clientProperties.getHealthUrl(),
145+
is("https://" + getHostname() + ":9090/health"));
146+
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname() + ":8080"));
147+
}
148+
135149
@Test
136150
public void test_preferIpAddress_serveraddress_missing() {
137151
load("spring.boot.admin.client.prefer-ip=true", "local.server.port=8080");

0 commit comments

Comments
 (0)