Commit 79eb9496 by Johannes Edmeier

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
parent 30d76a73
......@@ -24,6 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.embedded.Ssl;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.event.EventListener;
......@@ -94,8 +95,9 @@ public class AdminClientProperties {
"serviceUrl must be set when deployed to servlet-container");
}
return UriComponentsBuilder.newInstance().scheme(getScheme()).host(getServiceHost())
.port(serverPort).path(server.getContextPath()).toUriString();
return UriComponentsBuilder.newInstance().scheme(getScheme(server.getSsl()))
.host(getServiceHost()).port(serverPort).path(server.getContextPath())
.toUriString();
}
public String getManagementUrl() {
......@@ -110,7 +112,8 @@ public class AdminClientProperties {
.toUriString();
}
return UriComponentsBuilder.newInstance().scheme(getScheme()).host(getManagementHost())
Ssl ssl = management.getSsl() != null ? management.getSsl() : server.getSsl();
return UriComponentsBuilder.newInstance().scheme(getScheme(ssl)).host(getManagementHost())
.port(managementPort).path(management.getContextPath()).toUriString();
}
......@@ -151,8 +154,8 @@ public class AdminClientProperties {
return preferIp;
}
private String getScheme() {
return server.getSsl() != null && server.getSsl().isEnabled() ? "https" : "http";
private String getScheme(Ssl ssl) {
return ssl != null && ssl.isEnabled() ? "https" : "http";
}
private String getHost(InetAddress address) {
......
......@@ -133,6 +133,20 @@ public class AdminClientPropertiesTest {
}
@Test
public void test_ssl_managment() {
load("management.ssl.key-store=somefile.jks", "management.ssl.key-store-password=password",
"local.server.port=8080", "local.management.port=9090");
AdminClientProperties clientProperties = context.getBean(AdminClientProperties.class);
publishApplicationReadyEvent(clientProperties);
assertThat(clientProperties.getManagementUrl(), is("https://" + getHostname() + ":9090"));
assertThat(clientProperties.getHealthUrl(),
is("https://" + getHostname() + ":9090/health"));
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname() + ":8080"));
}
@Test
public void test_preferIpAddress_serveraddress_missing() {
load("spring.boot.admin.client.prefer-ip=true", "local.server.port=8080");
AdminClientProperties clientProperties = context.getBean(AdminClientProperties.class);
......
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