Commit 39e77e6f by Stephen Oakey Committed by Johannes Stelzer

Auto-detection of HTTPS in AdminClientProperties

Checks for the presence of Ssl in ServerProperties and that it is enabled, uses https in that case for client URL. Added test case for option.
parent 621ff8d7
......@@ -175,7 +175,8 @@ public class AdminClientProperties implements ApplicationListener<ApplicationEve
}
private String createLocalUri(int port, String path) {
return append("http://" + getHostname() + ":" + port + "/", path);
String scheme = server.getSsl() != null && server.getSsl().isEnabled() ? "https" : "http";
return append(scheme + "://" + getHostname() + ":" + port + "/", path);
}
private String append(String uri, String path) {
......
......@@ -145,6 +145,22 @@ public class AdminClientPropertiesTest {
assertThat(clientProperties.getServiceUrl(), is("http://" + getHostname()
+ ":8080/"));
}
@Test
public void testSsl() {
load("server.ssl.key-store=somefile.jks", "server.ssl.key-store-password=password");
AdminClientProperties clientProperties = new AdminClientProperties();
context.getAutowireCapableBeanFactory().autowireBean(clientProperties);
publishServletContainerInitializedEvent(clientProperties, 8080, null);
assertThat(clientProperties.getManagementUrl(), is("https://" + getHostname()
+ ":8080/"));
assertThat(clientProperties.getHealthUrl(), is("https://" + getHostname()
+ ":8080/health/"));
assertThat(clientProperties.getServiceUrl(), is("https://" + getHostname()
+ ":8080/"));
}
private String getHostname() {
try {
......
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