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
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "shell.auth",
|
||||
"name": "shell.auth.type",
|
||||
"values": [
|
||||
{
|
||||
"value": "simple",
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user