diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java index 7c68ebba45..9cb691523b 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java @@ -185,10 +185,10 @@ public class CrshAutoConfiguration { @Bean @ConditionalOnMissingBean(CrshShellAuthenticationProperties.class) public SpringAuthenticationProperties springAuthenticationProperties() { - // In case no shell.auth property is provided fall back to Spring Security + // In case no shell.auth.type property is provided fall back to Spring Security // based authentication and get role to access shell from // ManagementServerProperties. - // In case shell.auth is set to spring and roles are configured using + // In case shell.auth.type is set to spring and roles are configured using // shell.auth.spring.roles the below default role will be overridden by // ConfigurationProperties. SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java index a6083ab9ac..ffa10c66ae 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java @@ -43,13 +43,7 @@ public class ShellProperties { private static final Log logger = LogFactory.getLog(ShellProperties.class); - /** - * Authentication type. Auto-detected according to the environment (i.e. if Spring - * Security is available, "spring" is used by default). - */ - private String auth = "simple"; - - private boolean defaultAuth = true; + private final Auth auth = new Auth(); @Autowired(required = false) private CrshShellProperties[] additionalProperties = new CrshShellProperties[] { @@ -86,13 +80,7 @@ public class ShellProperties { private final Telnet telnet = new Telnet(); - public void setAuth(String auth) { - Assert.hasLength(auth, "Auth must not be empty"); - this.auth = auth; - this.defaultAuth = false; - } - - public String getAuth() { + public Auth getAuth() { return this.auth; } @@ -191,15 +179,7 @@ public class ShellProperties { * @param properties the properties to validate */ protected void validateCrshShellConfig(Properties properties) { - String finalAuth = properties.getProperty("crash.auth"); - if (!this.defaultAuth && !this.auth.equals(finalAuth)) { - logger.warn(String.format( - "Shell authentication fell back to method '%s' opposed to " - + "configured method '%s'. Please check your classpath.", - finalAuth, this.auth)); - } - // Make sure we keep track of final authentication method - this.auth = finalAuth; + getAuth().validateCrshShellConfig(properties); } /** @@ -223,6 +203,44 @@ public class ShellProperties { } + public static class Auth { + + /** + * Authentication type. Auto-detected according to the environment (i.e. if Spring + * Security is available, "spring" is used by default). + */ + private String type = "simple"; + + private boolean defaultAuth = true; + + public String getType() { + return this.type; + } + + public void setType(String type) { + Assert.hasLength(type, "Auth type must not be empty"); + this.type = type; + this.defaultAuth = false; + } + + /** + * Basic validation of applied CRaSH shell configuration. + * @param properties the properties to validate + */ + protected void validateCrshShellConfig(Properties properties) { + String finalAuth = properties.getProperty("crash.auth"); + if (!this.defaultAuth && !this.type.equals(finalAuth)) { + logger.warn(String.format( + "Shell authentication fell back to method '%s' opposed to " + + "configured method '%s'. Please check your classpath.", + finalAuth, this.type)); + } + // Make sure we keep track of final authentication method + this.type = finalAuth; + } + + } + /** * SSH properties. */ diff --git a/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json index be5aab1f2c..d67373739a 100644 --- a/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -255,7 +255,7 @@ ] }, { - "name": "shell.auth", + "name": "shell.auth.type", "values": [ { "value": "simple", diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java index 9b8286ea8d..09910bdb7b 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java @@ -230,7 +230,7 @@ public class CrshAutoConfigurationTests { @Test public void testJaasAuthenticationProvider() { MockEnvironment env = new MockEnvironment(); - env.setProperty("shell.auth", "jaas"); + env.setProperty("shell.auth.type", "jaas"); env.setProperty("shell.auth.jaas.domain", "my-test-domain"); this.context = new AnnotationConfigWebApplicationContext(); this.context.setEnvironment(env); @@ -247,7 +247,7 @@ public class CrshAutoConfigurationTests { @Test public void testKeyAuthenticationProvider() { MockEnvironment env = new MockEnvironment(); - env.setProperty("shell.auth", "key"); + env.setProperty("shell.auth.type", "key"); env.setProperty("shell.auth.key.path", "~/test.pem"); this.context = new AnnotationConfigWebApplicationContext(); this.context.setEnvironment(env); @@ -264,7 +264,7 @@ public class CrshAutoConfigurationTests { @Test public void testSimpleAuthenticationProvider() throws Exception { MockEnvironment env = new MockEnvironment(); - env.setProperty("shell.auth", "simple"); + env.setProperty("shell.auth.type", "simple"); env.setProperty("shell.auth.simple.user.name", "user"); env.setProperty("shell.auth.simple.user.password", "password"); this.context = new AnnotationConfigWebApplicationContext(); @@ -294,7 +294,7 @@ public class CrshAutoConfigurationTests { @Test public void testSpringAuthenticationProvider() throws Exception { MockEnvironment env = new MockEnvironment(); - env.setProperty("shell.auth", "spring"); + env.setProperty("shell.auth.type", "spring"); this.context = new AnnotationConfigWebApplicationContext(); this.context.setEnvironment(env); this.context.setServletContext(new MockServletContext()); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java index ffd4bff3e3..1f23fd1acb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/ShellPropertiesTests.java @@ -54,9 +54,9 @@ public class ShellPropertiesTests { ShellProperties props = new ShellProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); binder.bind(new MutablePropertyValues( - Collections.singletonMap("shell.auth", "spring"))); + Collections.singletonMap("shell.auth.type", "spring"))); assertThat(binder.getBindingResult().hasErrors()).isFalse(); - assertThat(props.getAuth()).isEqualTo("spring"); + assertThat(props.getAuth().getType()).isEqualTo("spring"); } @Test @@ -64,9 +64,9 @@ public class ShellPropertiesTests { ShellProperties props = new ShellProperties(); RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); binder.bind( - new MutablePropertyValues(Collections.singletonMap("shell.auth", ""))); + new MutablePropertyValues(Collections.singletonMap("shell.auth.type", ""))); assertThat(binder.getBindingResult().hasErrors()).isTrue(); - assertThat(props.getAuth()).isEqualTo("simple"); + assertThat(props.getAuth().getType()).isEqualTo("simple"); } @Test @@ -299,7 +299,7 @@ public class ShellPropertiesTests { @Test public void testCustomShellProperties() throws Exception { MockEnvironment env = new MockEnvironment(); - env.setProperty("shell.auth", "simple"); + env.setProperty("shell.auth.type", "simple"); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setEnvironment(env); context.setServletContext(new MockServletContext()); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 50f5aaa543..f16d779510 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1011,7 +1011,7 @@ content into your application; rather pick only the properties that you need. management.trace.include=request-headers,response-headers,errors # Items to be included in the trace. # REMOTE SHELL - shell.auth=simple # Authentication type. Auto-detected according to the environment. + shell.auth.type=simple # Authentication type. Auto-detected according to the environment. shell.auth.jaas.domain=my-domain # JAAS domain. shell.auth.key.path= # Path to the authentication key. This should point to a valid ".pem" file. shell.auth.simple.user.name=user # Login user.