Merge pull request #4456 from eddumelendez/gh-4325

* pr/4456:
  Polish contribution
  Add timeout configuration for CRaSH
pull/4455/merge
Stephane Nicoll 9 years ago
commit b27d66fedd

@ -36,6 +36,7 @@ import org.springframework.util.StringUtils;
* *
* @author Christian Dupuis * @author Christian Dupuis
* @author Phillip Webb * @author Phillip Webb
* @author Eddú Meléndez
*/ */
@ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true) @ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true)
public class ShellProperties { public class ShellProperties {
@ -242,10 +243,22 @@ public class ShellProperties {
*/ */
private Integer port = 2000; private Integer port = 2000;
/**
* Number of milliseconds after user will be prompted to login again.
*/
private Integer authTimeout = 600000;
/**
* Number of milliseconds after which unused connections are closed.
*/
private Integer idleTimeout = 600000;
@Override @Override
protected void applyToCrshShellConfig(Properties config) { protected void applyToCrshShellConfig(Properties config) {
if (this.enabled) { if (this.enabled) {
config.put("crash.ssh.port", String.valueOf(this.port)); 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) { if (this.keyPath != null) {
config.put("crash.ssh.keypath", this.keyPath); config.put("crash.ssh.keypath", this.keyPath);
} }
@ -278,6 +291,21 @@ public class ShellProperties {
return this.port; 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 Christian Dupuis
* @author Andreas Ahlenstorf * @author Andreas Ahlenstorf
* @author Eddú Meléndez
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
public class CrshAutoConfigurationTests { public class CrshAutoConfigurationTests {
@ -80,10 +81,7 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.disabled_plugins", env.setProperty("shell.disabled_plugins",
"GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin"); "GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
this.context = new AnnotationConfigWebApplicationContext(); load(env);
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertNotNull(lifeCycle); assertNotNull(lifeCycle);
@ -112,14 +110,13 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true"); env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.port", "3333"); env.setProperty("shell.ssh.port", "3333");
this.context = new AnnotationConfigWebApplicationContext(); load(env);
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port")); 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 @Test
@ -127,10 +124,7 @@ public class CrshAutoConfigurationTests {
MockEnvironment env = new MockEnvironment(); MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true"); env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem"); env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem");
this.context = new AnnotationConfigWebApplicationContext(); load(env);
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
@ -138,6 +132,27 @@ public class CrshAutoConfigurationTests {
lifeCycle.getConfig().getProperty("crash.ssh.keypath")); 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", "400000");
load(env);
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
assertEquals("400000", 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 @Test
public void testCommandResolution() { public void testCommandResolution() {
this.context = new AnnotationConfigWebApplicationContext(); 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.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-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.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.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.key-path= # Path to the SSH server key.
shell.ssh.port=2000 # SSH port. shell.ssh.port=2000 # SSH port.
shell.telnet.enabled=false # Enable CRaSH telnet support. Enabled by default if the TelnetPlugin is available. shell.telnet.enabled=false # Enable CRaSH telnet support. Enabled by default if the TelnetPlugin is available.

Loading…
Cancel
Save