Make shell username and password configuration properties consistent with general security properties
Now simple authentication for the crsh shell can we configured using shell.auth.simple.user.name and shell.auth.simple.user.password. This is consistent with security.user.name and security.user.password. fixes #113
This commit is contained in:
parent
86334403ed
commit
1b49605749
|
|
@ -298,30 +298,50 @@ public class ShellProperties {
|
||||||
private static Log logger = LogFactory
|
private static Log logger = LogFactory
|
||||||
.getLog(SimpleAuthenticationProperties.class);
|
.getLog(SimpleAuthenticationProperties.class);
|
||||||
|
|
||||||
private String username = "user";
|
private User user = new User();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void applyToCrshShellConfig(Properties config) {
|
||||||
|
config.put("crash.auth", "simple");
|
||||||
|
config.put("crash.auth.simple.username", this.user.getName());
|
||||||
|
config.put("crash.auth.simple.password", this.user.getPassword());
|
||||||
|
if (this.user.isDefaultPassword()) {
|
||||||
|
logger.info("\n\nUsing default password for shell access: "
|
||||||
|
+ this.user.getPassword() + "\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return this.user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class User {
|
||||||
|
|
||||||
|
private String name = "user";
|
||||||
|
|
||||||
private String password = UUID.randomUUID().toString();
|
private String password = UUID.randomUUID().toString();
|
||||||
|
|
||||||
private boolean defaultPassword = true;
|
private boolean defaultPassword = true;
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void applyToCrshShellConfig(Properties config) {
|
|
||||||
config.put("crash.auth", "simple");
|
|
||||||
config.put("crash.auth.simple.username", this.username);
|
|
||||||
config.put("crash.auth.simple.password", this.password);
|
|
||||||
if (this.defaultPassword) {
|
|
||||||
logger.info("\n\nUsing default password for shell access: "
|
|
||||||
+ this.password + "\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDefaultPassword() {
|
boolean isDefaultPassword() {
|
||||||
return this.defaultPassword;
|
return this.defaultPassword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername(String username) {
|
public String getName() {
|
||||||
Assert.hasLength(username, "username must have text");
|
return this.name;
|
||||||
this.username = username;
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return this.password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
Assert.hasLength(name, "name must have text");
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
|
|
@ -335,6 +355,8 @@ public class ShellProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth specific properties for Spring authentication
|
* Auth specific properties for Spring authentication
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -236,8 +236,8 @@ public class CrshAutoConfigurationTests {
|
||||||
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", "simple");
|
||||||
env.setProperty("shell.auth.simple.username", "user");
|
env.setProperty("shell.auth.simple.user.name", "user");
|
||||||
env.setProperty("shell.auth.simple.password", "password");
|
env.setProperty("shell.auth.simple.user.password", "password");
|
||||||
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());
|
||||||
|
|
|
||||||
|
|
@ -243,8 +243,8 @@ public class ShellPropertiesTests {
|
||||||
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.simple");
|
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.simple");
|
||||||
binder.setConversionService(new DefaultConversionService());
|
binder.setConversionService(new DefaultConversionService());
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("shell.auth.simple.username", "username123");
|
map.put("shell.auth.simple.user.name", "username123");
|
||||||
map.put("shell.auth.simple.password", "password123");
|
map.put("shell.auth.simple.user.password", "password123");
|
||||||
binder.bind(new MutablePropertyValues(map));
|
binder.bind(new MutablePropertyValues(map));
|
||||||
assertFalse(binder.getBindingResult().hasErrors());
|
assertFalse(binder.getBindingResult().hasErrors());
|
||||||
|
|
||||||
|
|
@ -260,9 +260,9 @@ public class ShellPropertiesTests {
|
||||||
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
||||||
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
||||||
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
||||||
"shell.auth.simple.password", "${ADMIN_PASSWORD}")));
|
"shell.auth.simple.user.password", "${ADMIN_PASSWORD}")));
|
||||||
assertFalse(binder.getBindingResult().hasErrors());
|
assertFalse(binder.getBindingResult().hasErrors());
|
||||||
assertTrue(security.isDefaultPassword());
|
assertTrue(security.getUser().isDefaultPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -270,9 +270,9 @@ public class ShellPropertiesTests {
|
||||||
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
||||||
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
||||||
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
||||||
"shell.auth.simple.password", "")));
|
"shell.auth.simple.user.password", "")));
|
||||||
assertFalse(binder.getBindingResult().hasErrors());
|
assertFalse(binder.getBindingResult().hasErrors());
|
||||||
assertTrue(security.isDefaultPassword());
|
assertTrue(security.getUser().isDefaultPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue