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,39 +298,61 @@ public class ShellProperties {
|
|||
private static Log logger = LogFactory
|
||||
.getLog(SimpleAuthenticationProperties.class);
|
||||
|
||||
private String username = "user";
|
||||
|
||||
private String password = UUID.randomUUID().toString();
|
||||
|
||||
private boolean defaultPassword = true;
|
||||
private User user = new User();
|
||||
|
||||
@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) {
|
||||
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.password + "\n\n");
|
||||
+ this.user.getPassword() + "\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
boolean isDefaultPassword() {
|
||||
return this.defaultPassword;
|
||||
public User getUser() {
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
Assert.hasLength(username, "username must have text");
|
||||
this.username = username;
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
if (password.startsWith("${") && password.endsWith("}")
|
||||
|| !StringUtils.hasLength(password)) {
|
||||
return;
|
||||
public static class User {
|
||||
|
||||
private String name = "user";
|
||||
|
||||
private String password = UUID.randomUUID().toString();
|
||||
|
||||
private boolean defaultPassword = true;
|
||||
|
||||
boolean isDefaultPassword() {
|
||||
return this.defaultPassword;
|
||||
}
|
||||
this.password = password;
|
||||
this.defaultPassword = false;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (password.startsWith("${") && password.endsWith("}")
|
||||
|| !StringUtils.hasLength(password)) {
|
||||
return;
|
||||
}
|
||||
this.password = password;
|
||||
this.defaultPassword = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -236,8 +236,8 @@ public class CrshAutoConfigurationTests {
|
|||
public void testSimpleAuthenticationProvider() throws Exception {
|
||||
MockEnvironment env = new MockEnvironment();
|
||||
env.setProperty("shell.auth", "simple");
|
||||
env.setProperty("shell.auth.simple.username", "user");
|
||||
env.setProperty("shell.auth.simple.password", "password");
|
||||
env.setProperty("shell.auth.simple.user.name", "user");
|
||||
env.setProperty("shell.auth.simple.user.password", "password");
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context.setEnvironment(env);
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
|
|
|
@ -243,8 +243,8 @@ public class ShellPropertiesTests {
|
|||
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.simple");
|
||||
binder.setConversionService(new DefaultConversionService());
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("shell.auth.simple.username", "username123");
|
||||
map.put("shell.auth.simple.password", "password123");
|
||||
map.put("shell.auth.simple.user.name", "username123");
|
||||
map.put("shell.auth.simple.user.password", "password123");
|
||||
binder.bind(new MutablePropertyValues(map));
|
||||
assertFalse(binder.getBindingResult().hasErrors());
|
||||
|
||||
|
@ -260,9 +260,9 @@ public class ShellPropertiesTests {
|
|||
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
||||
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
||||
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
||||
"shell.auth.simple.password", "${ADMIN_PASSWORD}")));
|
||||
"shell.auth.simple.user.password", "${ADMIN_PASSWORD}")));
|
||||
assertFalse(binder.getBindingResult().hasErrors());
|
||||
assertTrue(security.isDefaultPassword());
|
||||
assertTrue(security.getUser().isDefaultPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -270,9 +270,9 @@ public class ShellPropertiesTests {
|
|||
SimpleAuthenticationProperties security = new SimpleAuthenticationProperties();
|
||||
RelaxedDataBinder binder = new RelaxedDataBinder(security, "security");
|
||||
binder.bind(new MutablePropertyValues(Collections.singletonMap(
|
||||
"shell.auth.simple.password", "")));
|
||||
"shell.auth.simple.user.password", "")));
|
||||
assertFalse(binder.getBindingResult().hasErrors());
|
||||
assertTrue(security.isDefaultPassword());
|
||||
assertTrue(security.getUser().isDefaultPassword());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue