Commit 41300c35 authored by Eddú Meléndez's avatar Eddú Meléndez Committed by Stephane Nicoll

Add timeout configuration for CRaSH

Closes gh-4325
parent 0c8d302a
......@@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
*
* @author Christian Dupuis
* @author Phillip Webb
* @author Eddú Meléndez
*/
@ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true)
public class ShellProperties {
......@@ -242,10 +243,22 @@ public class ShellProperties {
*/
private Integer port = 2000;
/**
* Number of milliseconds after which unused connections are closed.
*/
private Integer idleTimeout = 600000;
/**
* Number of milliseconds after user will be prompted to login again.
*/
private Integer authTimeout = 600000;
@Override
protected void applyToCrshShellConfig(Properties config) {
if (this.enabled) {
config.put("crash.ssh.port", String.valueOf(this.port));
config.put("crash.ssh.auth_timeout", String.valueOf(this.authTimeout));
config.put("crash.ssh.idle_timeout", String.valueOf(this.idleTimeout));
if (this.keyPath != null) {
config.put("crash.ssh.keypath", this.keyPath);
}
......@@ -278,6 +291,21 @@ public class ShellProperties {
return this.port;
}
public Integer getIdleTimeout() {
return this.idleTimeout;
}
public void setIdleTimeout(Integer idleTimeout) {
this.idleTimeout = idleTimeout;
}
public Integer getAuthTimeout() {
return this.authTimeout;
}
public void setAuthTimeout(Integer authTimeout) {
this.authTimeout = authTimeout;
}
}
/**
......
......@@ -62,6 +62,7 @@ import static org.junit.Assert.assertTrue;
*
* @author Christian Dupuis
* @author Andreas Ahlenstorf
* @author Eddú Meléndez
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class CrshAutoConfigurationTests {
......@@ -80,10 +81,7 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.disabled_plugins",
"GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertNotNull(lifeCycle);
......@@ -112,14 +110,13 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.port", "3333");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port"));
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
}
@Test
......@@ -127,10 +124,7 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
......@@ -138,6 +132,27 @@ public class CrshAutoConfigurationTests {
lifeCycle.getConfig().getProperty("crash.ssh.keypath"));
}
@Test
public void testSshConfigurationCustomTimeouts() {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.auth-timeout", "300000");
env.setProperty("shell.ssh.idle-timeout", "300000");
load(env);
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
}
private void load(MockEnvironment env) {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
}
@Test
public void testCommandResolution() {
this.context = new AnnotationConfigWebApplicationContext();
......
......@@ -846,7 +846,9 @@ content into your application; rather pick only the properties that you need.
shell.config-path-patterns=classpath*:/crash/* # Patterns to use to look for configurations.
shell.disabled-commands=jpa*,jdbc*,jndi* # Comma-separated list of commands to disable.
shell.disabled-plugins= # Comma-separated list of plugins to disable. Certain plugins are disabled by default based on the environment.
shell.ssh.auth-timeout = # Number of milliseconds after user will be prompted to login again.
shell.ssh.enabled=true # Enable CRaSH SSH support.
shell.ssh.idle-timeout = # Number of milliseconds after which unused connections are closed.
shell.ssh.key-path= # Path to the SSH server key.
shell.ssh.port=2000 # SSH port.
shell.telnet.enabled=false # Enable CRaSH telnet support. Enabled by default if the TelnetPlugin is available.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment