Move `shell.auth` to `shell.auth.type`

This commit moves the `shell.auth` property to `shell.auth.type`. The
previous situation was unfortunate since `shell.auth` was both a group
and a particular property.

Closes gh-5139
pull/5706/head
Stephane Nicoll 9 years ago
parent 35270e939f
commit 6d11d73cbc

@ -185,10 +185,10 @@ public class CrshAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class) @ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
public SpringAuthenticationProperties springAuthenticationProperties() { 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 // based authentication and get role to access shell from
// ManagementServerProperties. // 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 // shell.auth.spring.roles the below default role will be overridden by
// ConfigurationProperties. // ConfigurationProperties.
SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties(); SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties();

@ -43,13 +43,7 @@ public class ShellProperties {
private static final Log logger = LogFactory.getLog(ShellProperties.class); private static final Log logger = LogFactory.getLog(ShellProperties.class);
/** private final Auth auth = new Auth();
* 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;
@Autowired(required = false) @Autowired(required = false)
private CrshShellProperties[] additionalProperties = new CrshShellProperties[] { private CrshShellProperties[] additionalProperties = new CrshShellProperties[] {
@ -86,13 +80,7 @@ public class ShellProperties {
private final Telnet telnet = new Telnet(); private final Telnet telnet = new Telnet();
public void setAuth(String auth) { public Auth getAuth() {
Assert.hasLength(auth, "Auth must not be empty");
this.auth = auth;
this.defaultAuth = false;
}
public String getAuth() {
return this.auth; return this.auth;
} }
@ -191,15 +179,7 @@ public class ShellProperties {
* @param properties the properties to validate * @param properties the properties to validate
*/ */
protected void validateCrshShellConfig(Properties properties) { protected void validateCrshShellConfig(Properties properties) {
String finalAuth = properties.getProperty("crash.auth"); getAuth().validateCrshShellConfig(properties);
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;
} }
/** /**
@ -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. * SSH properties.
*/ */

@ -255,7 +255,7 @@
] ]
}, },
{ {
"name": "shell.auth", "name": "shell.auth.type",
"values": [ "values": [
{ {
"value": "simple", "value": "simple",

@ -230,7 +230,7 @@ public class CrshAutoConfigurationTests {
@Test @Test
public void testJaasAuthenticationProvider() { public void testJaasAuthenticationProvider() {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "jaas"); env.setProperty("shell.auth.type", "jaas");
env.setProperty("shell.auth.jaas.domain", "my-test-domain"); env.setProperty("shell.auth.jaas.domain", "my-test-domain");
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env); this.context.setEnvironment(env);
@ -247,7 +247,7 @@ public class CrshAutoConfigurationTests {
@Test @Test
public void testKeyAuthenticationProvider() { public void testKeyAuthenticationProvider() {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "key"); env.setProperty("shell.auth.type", "key");
env.setProperty("shell.auth.key.path", "~/test.pem"); env.setProperty("shell.auth.key.path", "~/test.pem");
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env); this.context.setEnvironment(env);
@ -264,7 +264,7 @@ public class CrshAutoConfigurationTests {
@Test @Test
public void testSimpleAuthenticationProvider() throws Exception { public void testSimpleAuthenticationProvider() throws Exception {
MockEnvironment env = new MockEnvironment(); 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.name", "user");
env.setProperty("shell.auth.simple.user.password", "password"); env.setProperty("shell.auth.simple.user.password", "password");
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
@ -294,7 +294,7 @@ public class CrshAutoConfigurationTests {
@Test @Test
public void testSpringAuthenticationProvider() throws Exception { public void testSpringAuthenticationProvider() throws Exception {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "spring"); env.setProperty("shell.auth.type", "spring");
this.context = new AnnotationConfigWebApplicationContext(); this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env); this.context.setEnvironment(env);
this.context.setServletContext(new MockServletContext()); this.context.setServletContext(new MockServletContext());

@ -54,9 +54,9 @@ public class ShellPropertiesTests {
ShellProperties props = new ShellProperties(); ShellProperties props = new ShellProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.bind(new MutablePropertyValues( binder.bind(new MutablePropertyValues(
Collections.singletonMap("shell.auth", "spring"))); Collections.singletonMap("shell.auth.type", "spring")));
assertThat(binder.getBindingResult().hasErrors()).isFalse(); assertThat(binder.getBindingResult().hasErrors()).isFalse();
assertThat(props.getAuth()).isEqualTo("spring"); assertThat(props.getAuth().getType()).isEqualTo("spring");
} }
@Test @Test
@ -64,9 +64,9 @@ public class ShellPropertiesTests {
ShellProperties props = new ShellProperties(); ShellProperties props = new ShellProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell"); RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.bind( binder.bind(
new MutablePropertyValues(Collections.singletonMap("shell.auth", ""))); new MutablePropertyValues(Collections.singletonMap("shell.auth.type", "")));
assertThat(binder.getBindingResult().hasErrors()).isTrue(); assertThat(binder.getBindingResult().hasErrors()).isTrue();
assertThat(props.getAuth()).isEqualTo("simple"); assertThat(props.getAuth().getType()).isEqualTo("simple");
} }
@Test @Test
@ -299,7 +299,7 @@ public class ShellPropertiesTests {
@Test @Test
public void testCustomShellProperties() throws Exception { public void testCustomShellProperties() throws Exception {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.auth", "simple"); env.setProperty("shell.auth.type", "simple");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setEnvironment(env); context.setEnvironment(env);
context.setServletContext(new MockServletContext()); context.setServletContext(new MockServletContext());

@ -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. management.trace.include=request-headers,response-headers,errors # Items to be included in the trace.
# REMOTE SHELL # 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.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.key.path= # Path to the authentication key. This should point to a valid ".pem" file.
shell.auth.simple.user.name=user # Login user. shell.auth.simple.user.name=user # Login user.

Loading…
Cancel
Save