Allow management server SSL to be configured independently

Closes gh-6057
pull/6018/merge
Alex Antonov 9 years ago committed by Andy Wilkinson
parent 5840a69150
commit 3546ae399e

@ -188,6 +188,9 @@ public class EndpointWebMvcChildContextConfiguration {
container.setContextPath(""); container.setContextPath("");
// and add the management-specific bits // and add the management-specific bits
container.setPort(this.managementServerProperties.getPort()); container.setPort(this.managementServerProperties.getPort());
if (this.managementServerProperties.getSsl() != null) {
container.setSsl(this.managementServerProperties.getSsl());
}
container.setServerHeader(this.server.getServerHeader()); container.setServerHeader(this.server.getServerHeader());
container.setAddress(this.managementServerProperties.getAddress()); container.setAddress(this.managementServerProperties.getAddress());
container.addErrorPages(new ErrorPage(this.server.getError().getPath())); container.addErrorPages(new ErrorPage(this.server.getError().getPath()));

@ -25,7 +25,9 @@ import javax.validation.constraints.NotNull;
import org.springframework.boot.autoconfigure.security.SecurityPrerequisite; import org.springframework.boot.autoconfigure.security.SecurityPrerequisite;
import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.embedded.Ssl;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -68,6 +70,9 @@ public class ManagementServerProperties implements SecurityPrerequisite {
*/ */
private Integer port; private Integer port;
@NestedConfigurationProperty
private Ssl ssl;
/** /**
* Network address that the management endpoints should bind to. * Network address that the management endpoints should bind to.
*/ */
@ -112,6 +117,14 @@ public class ManagementServerProperties implements SecurityPrerequisite {
this.port = port; this.port = port;
} }
public Ssl getSsl() {
return this.ssl;
}
public void setSsl(Ssl ssl) {
this.ssl = ssl;
}
public InetAddress getAddress() { public InetAddress getAddress() {
return this.address; return this.address;
} }

@ -175,6 +175,32 @@ public class EndpointWebMvcAutoConfigurationTests {
assertThat(interceptors).hasSize(1); assertThat(interceptors).hasSize(1);
} }
@Test
public void onDifferentPortManagementSslDisabled() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.ssl.enabled:false");
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
this.applicationContext.refresh();
assertContent("/controller", ports.get().server, "controlleroutput");
assertContent("/endpoint", ports.get().server, null);
assertContent("/controller", ports.get().management, null);
assertContent("/endpoint", ports.get().management, "endpointoutput");
assertContent("/error", ports.get().management, startsWith("{"));
ApplicationContext managementContext = this.applicationContext
.getBean(ManagementContextResolver.class).getApplicationContext();
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
assertThat(interceptors).hasSize(1);
ManagementServerProperties managementServerProperties = this.applicationContext
.getBean(ManagementServerProperties.class);
assertThat(managementServerProperties.getSsl()).isNotNull();
assertThat(managementServerProperties.getSsl().isEnabled()).isFalse();
this.applicationContext.close();
assertAllClosed();
}
@Test @Test
public void onDifferentPortWithSpecificContainer() throws Exception { public void onDifferentPortWithSpecificContainer() throws Exception {
this.applicationContext.register(SpecificContainerConfig.class, RootConfig.class, this.applicationContext.register(SpecificContainerConfig.class, RootConfig.class,

Loading…
Cancel
Save