Skip to content

Commit

Permalink
Respect management.ssl.* settings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joshiste committed Nov 16, 2016
1 parent 30d76a7 commit 79eb949
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -94,8 +95,9 @@ public String getServiceUrl() {
"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() {
Expand All @@ -110,7 +112,8 @@ public String getManagementUrl() {
.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();
}

Expand Down Expand Up @@ -151,8 +154,8 @@ public boolean isPreferIp() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public void test_ssl() {
assertThat(clientProperties.getServiceUrl(), is("https://" + getHostname() + ":8080"));
}

@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");
Expand Down

0 comments on commit 79eb949

Please sign in to comment.