From 41300c35ab9adbdeef763f93f32522b0e912ed88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Thu, 12 Nov 2015 22:06:14 -0500 Subject: [PATCH 1/2] Add timeout configuration for CRaSH Closes gh-4325 --- .../autoconfigure/ShellProperties.java | 28 +++++++++++++ .../CrshAutoConfigurationTests.java | 39 +++++++++++++------ .../appendix-application-properties.adoc | 2 + 3 files changed, 57 insertions(+), 12 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java index eebb24d8a44..bf86cc59bae 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java @@ -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; + } } /** diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java index 15ce38d80f2..ec9029040bb 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java @@ -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(); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 76066e052ff..88de48b232b 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -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. From ba2aea4ef1a8d3ead424d295f5df7c19077dae07 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 13 Nov 2015 10:13:44 +0100 Subject: [PATCH 2/2] Polish contribution Closes gh-4456 --- .../boot/actuate/autoconfigure/ShellProperties.java | 10 +++++----- .../autoconfigure/CrshAutoConfigurationTests.java | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java index bf86cc59bae..6a2ec643323 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java @@ -243,16 +243,16 @@ 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; + /** + * Number of milliseconds after which unused connections are closed. + */ + private Integer idleTimeout = 600000; + @Override protected void applyToCrshShellConfig(Properties config) { if (this.enabled) { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java index ec9029040bb..c8b155282e7 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java @@ -137,13 +137,13 @@ public class CrshAutoConfigurationTests { MockEnvironment env = new MockEnvironment(); env.setProperty("shell.ssh.enabled", "true"); env.setProperty("shell.ssh.auth-timeout", "300000"); - env.setProperty("shell.ssh.idle-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("300000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")); + assertEquals("400000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout")); } private void load(MockEnvironment env) {