Skip to content

Commit cc0fc07

Browse files
committed
Move shell.* to management.shell.*
This commit moves the `shell` namespace to `management.shell` Closes spring-projectsgh-5703
1 parent 6d11d73 commit cc0fc07

File tree

10 files changed

+224
-293
lines changed

10 files changed

+224
-293
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfiguration.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@
8888
* The default shell authentication method uses a username and password combination. If no
8989
* configuration is provided the default username is 'user' and the password will be
9090
* printed to console during application startup. Those default values can be overridden
91-
* by using {@code shell.auth.simple.username} and {@code shell.auth.simple.password}.
91+
* by using {@code management.shell.auth.simple.username} and
92+
* {@code management.shell.auth.simple.password}.
9293
* <p>
9394
* If a Spring Security {@link AuthenticationManager} is detected, this configuration will
9495
* create a {@link CRaSHPlugin} to forward shell authentication requests to Spring
95-
* Security. This authentication method will get enabled if {@code shell.auth} is set to
96-
* {@code spring} or if no explicit {@code shell.auth} is provided and a
97-
* {@link AuthenticationManager} is available. In the latter case shell access will be
98-
* restricted to users having roles that match those configured in
96+
* Security. This authentication method will get enabled if {@code management.shell.auth.type}
97+
* is set to {@code spring} or if no explicit {@code management.shell.auth} is provided
98+
* and a {@link AuthenticationManager} is available. In the latter case shell access will
99+
* be restricted to users having roles that match those configured in
99100
* {@link ManagementServerProperties}. Required roles can be overridden by
100-
* {@code shell.auth.spring.roles}.
101+
* {@code management.shell.auth.spring.roles}.
101102
* <p>
102103
* To add customizations to the shell simply define beans of type {@link CRaSHPlugin} in
103104
* the application context. Those beans will get auto detected during startup and
@@ -109,7 +110,7 @@
109110
* <a href="http://www.crashub.org">crashub.org</a>. By default Boot will search for
110111
* commands using the following classpath scanning pattern {@code classpath*:/commands/**}
111112
* . To add different locations or override the default use
112-
* {@code shell.command_path_patterns} in your application configuration.
113+
* {@code management.shell.command-path-patterns} in your application configuration.
113114
*
114115
* @author Christian Dupuis
115116
* @author Matt Benson
@@ -122,6 +123,8 @@
122123
ManagementWebSecurityAutoConfiguration.class })
123124
public class CrshAutoConfiguration {
124125

126+
public static final String AUTH_PREFIX = ShellProperties.SHELL_PREFIX + ".auth";
127+
125128
private final ShellProperties properties;
126129

127130
public CrshAutoConfiguration(ShellProperties properties) {
@@ -140,21 +143,21 @@ public CrshBootstrapBean shellBootstrap() {
140143
static class CrshAdditionalPropertiesConfiguration {
141144

142145
@Bean
143-
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "jaas")
146+
@ConditionalOnProperty(prefix = AUTH_PREFIX, name = "type", havingValue = "jaas")
144147
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
145148
public JaasAuthenticationProperties jaasAuthenticationProperties() {
146149
return new JaasAuthenticationProperties();
147150
}
148151

149152
@Bean
150-
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "key")
153+
@ConditionalOnProperty(prefix = AUTH_PREFIX, name = "type", havingValue = "key")
151154
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
152155
public KeyAuthenticationProperties keyAuthenticationProperties() {
153156
return new KeyAuthenticationProperties();
154157
}
155158

156159
@Bean
157-
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "simple", matchIfMissing = true)
160+
@ConditionalOnProperty(prefix = AUTH_PREFIX, name = "type", havingValue = "simple", matchIfMissing = true)
158161
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
159162
public SimpleAuthenticationProperties simpleAuthenticationProperties() {
160163
return new SimpleAuthenticationProperties();
@@ -166,7 +169,7 @@ public SimpleAuthenticationProperties simpleAuthenticationProperties() {
166169
* Class to configure CRaSH to authenticate against Spring Security.
167170
*/
168171
@Configuration
169-
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "spring", matchIfMissing = true)
172+
@ConditionalOnProperty(prefix = AUTH_PREFIX, name = "type", havingValue = "spring", matchIfMissing = true)
170173
@ConditionalOnBean(AuthenticationManager.class)
171174
public static class AuthenticationManagerAdapterConfiguration {
172175

@@ -185,12 +188,12 @@ public AuthenticationManagerAdapter shellAuthenticationManager() {
185188
@Bean
186189
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
187190
public SpringAuthenticationProperties springAuthenticationProperties() {
188-
// In case no shell.auth.type property is provided fall back to Spring Security
189-
// based authentication and get role to access shell from
191+
// In case no management.shell.auth.type property is provided fall back to
192+
// Spring Security based authentication and get role to access shell from
190193
// ManagementServerProperties.
191-
// In case shell.auth.type is set to spring and roles are configured using
192-
// shell.auth.spring.roles the below default role will be overridden by
193-
// ConfigurationProperties.
194+
// In case management.shell.auth.type is set to spring and roles are
195+
// configured using shell.auth.spring.roles the below default role will be
196+
// overridden by ConfigurationProperties.
194197
SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties();
195198
if (this.management != null) {
196199
authenticationProperties.setRoles(

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
* @author Christian Dupuis
3838
* @author Phillip Webb
3939
* @author Eddú Meléndez
40+
* @author Stephane Nicoll
4041
*/
41-
@ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true)
42+
@ConfigurationProperties(prefix = ShellProperties.SHELL_PREFIX, ignoreUnknownFields = true)
4243
public class ShellProperties {
4344

45+
public static final String SHELL_PREFIX = "management.shell";
46+
4447
private static final Log logger = LogFactory.getLog(ShellProperties.class);
4548

4649
private final Auth auth = new Auth();
@@ -372,7 +375,7 @@ public Integer getPort() {
372375
/**
373376
* Auth specific properties for JAAS authentication.
374377
*/
375-
@ConfigurationProperties(prefix = "shell.auth.jaas", ignoreUnknownFields = false)
378+
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.jaas", ignoreUnknownFields = false)
376379
public static class JaasAuthenticationProperties
377380
extends CrshShellAuthenticationProperties {
378381

@@ -401,7 +404,7 @@ public String getDomain() {
401404
/**
402405
* Auth specific properties for key authentication.
403406
*/
404-
@ConfigurationProperties(prefix = "shell.auth.key", ignoreUnknownFields = false)
407+
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.key", ignoreUnknownFields = false)
405408
public static class KeyAuthenticationProperties
406409
extends CrshShellAuthenticationProperties {
407410

@@ -432,7 +435,7 @@ public String getPath() {
432435
/**
433436
* Auth specific properties for simple authentication.
434437
*/
435-
@ConfigurationProperties(prefix = "shell.auth.simple", ignoreUnknownFields = false)
438+
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.simple", ignoreUnknownFields = false)
436439
public static class SimpleAuthenticationProperties
437440
extends CrshShellAuthenticationProperties {
438441

@@ -508,7 +511,7 @@ public void setPassword(String password) {
508511
/**
509512
* Auth specific properties for Spring authentication.
510513
*/
511-
@ConfigurationProperties(prefix = "shell.auth.spring", ignoreUnknownFields = false)
514+
@ConfigurationProperties(prefix = SHELL_PREFIX + ".auth.spring", ignoreUnknownFields = false)
512515
public static class SpringAuthenticationProperties
513516
extends CrshShellAuthenticationProperties {
514517

spring-boot-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
]
256256
},
257257
{
258-
"name": "shell.auth.type",
258+
"name": "management.shell.auth.type",
259259
"values": [
260260
{
261261
"value": "simple",

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.junit.Test;
3838

3939
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
40+
import org.springframework.boot.test.util.EnvironmentTestUtils;
4041
import org.springframework.boot.testutil.Matched;
4142
import org.springframework.context.annotation.Bean;
4243
import org.springframework.context.annotation.Configuration;
@@ -64,6 +65,7 @@
6465
* @author Andreas Ahlenstorf
6566
* @author Eddú Meléndez
6667
* @author Matt Benson
68+
* @author Stephane Nicoll
6769
*/
6870
@SuppressWarnings({ "rawtypes", "unchecked" })
6971
public class CrshAutoConfigurationTests {
@@ -79,10 +81,8 @@ public void close() {
7981

8082
@Test
8183
public void testDisabledPlugins() throws Exception {
82-
MockEnvironment env = new MockEnvironment();
83-
env.setProperty("shell.disabled_plugins",
84+
load("management.shell.disabled_plugins=" +
8485
"termIOHandler, org.crsh.auth.AuthenticationPlugin, javaLanguage");
85-
load(env);
8686
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
8787
assertThat(lifeCycle).isNotNull();
8888
assertThat(lifeCycle.getContext().getPlugins(TermIOHandler.class))
@@ -98,9 +98,7 @@ public void testDisabledPlugins() throws Exception {
9898

9999
@Test
100100
public void testAttributes() throws Exception {
101-
this.context = new AnnotationConfigWebApplicationContext();
102-
this.context.register(CrshAutoConfiguration.class);
103-
this.context.refresh();
101+
load();
104102
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
105103
Map<String, Object> attributes = lifeCycle.getContext().getAttributes();
106104
assertThat(attributes.containsKey("spring.version")).isTrue();
@@ -111,11 +109,8 @@ public void testAttributes() throws Exception {
111109

112110
@Test
113111
public void testSshConfiguration() {
114-
MockEnvironment env = new MockEnvironment();
115-
env.setProperty("shell.ssh.enabled", "true");
116-
env.setProperty("shell.ssh.port", "3333");
117-
load(env);
118-
112+
load("management.shell.ssh.enabled=true",
113+
"management.shell.ssh.port=3333");
119114
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
120115
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.port")).isEqualTo("3333");
121116
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"))
@@ -126,41 +121,29 @@ public void testSshConfiguration() {
126121

127122
@Test
128123
public void testSshConfigurationWithKeyPath() {
129-
MockEnvironment env = new MockEnvironment();
130-
env.setProperty("shell.ssh.enabled", "true");
131-
env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem");
132-
load(env);
124+
load("management.shell.ssh.enabled=true",
125+
"management.shell.ssh.key_path=~/.ssh/id.pem");
133126
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
134127
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.keypath"))
135128
.isEqualTo("~/.ssh/id.pem");
136129
}
137130

138131
@Test
139132
public void testSshConfigurationCustomTimeouts() {
140-
MockEnvironment env = new MockEnvironment();
141-
env.setProperty("shell.ssh.enabled", "true");
142-
env.setProperty("shell.ssh.auth-timeout", "300000");
143-
env.setProperty("shell.ssh.idle-timeout", "400000");
144-
load(env);
133+
load("management.shell.ssh.enabled=true",
134+
"management.shell.ssh.auth-timeout=300000",
135+
"management.shell.ssh.idle-timeout=400000");
145136
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
146137
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"))
147138
.isEqualTo("300000");
148139
assertThat(lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"))
149140
.isEqualTo("400000");
150141
}
151142

152-
private void load(MockEnvironment env) {
153-
this.context = new AnnotationConfigWebApplicationContext();
154-
this.context.setEnvironment(env);
155-
this.context.register(CrshAutoConfiguration.class);
156-
this.context.refresh();
157-
}
158143

159144
@Test
160145
public void testCommandResolution() {
161-
this.context = new AnnotationConfigWebApplicationContext();
162-
this.context.register(CrshAutoConfiguration.class);
163-
this.context.refresh();
146+
load();
164147
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
165148
int count = 0;
166149
Iterator<Resource> resources = lifeCycle.getContext()
@@ -182,9 +165,7 @@ public void testCommandResolution() {
182165

183166
@Test
184167
public void testDisabledCommandResolution() {
185-
this.context = new AnnotationConfigWebApplicationContext();
186-
this.context.register(CrshAutoConfiguration.class);
187-
this.context.refresh();
168+
load();
188169
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
189170
int count = 0;
190171
Iterator<Resource> resources = lifeCycle.getContext()
@@ -229,11 +210,10 @@ public void testDefaultAuthenticationProvider() {
229210

230211
@Test
231212
public void testJaasAuthenticationProvider() {
232-
MockEnvironment env = new MockEnvironment();
233-
env.setProperty("shell.auth.type", "jaas");
234-
env.setProperty("shell.auth.jaas.domain", "my-test-domain");
235213
this.context = new AnnotationConfigWebApplicationContext();
236-
this.context.setEnvironment(env);
214+
EnvironmentTestUtils.addEnvironment(this.context,
215+
"management.shell.auth.type=jaas",
216+
"management.shell.auth.jaas.domain=my-test-domain");
237217
this.context.setServletContext(new MockServletContext());
238218
this.context.register(SecurityConfiguration.class);
239219
this.context.register(CrshAutoConfiguration.class);
@@ -246,11 +226,10 @@ public void testJaasAuthenticationProvider() {
246226

247227
@Test
248228
public void testKeyAuthenticationProvider() {
249-
MockEnvironment env = new MockEnvironment();
250-
env.setProperty("shell.auth.type", "key");
251-
env.setProperty("shell.auth.key.path", "~/test.pem");
252229
this.context = new AnnotationConfigWebApplicationContext();
253-
this.context.setEnvironment(env);
230+
EnvironmentTestUtils.addEnvironment(this.context,
231+
"management.shell.auth.type=key",
232+
"management.shell.auth.key.path=~/test.pem");
254233
this.context.setServletContext(new MockServletContext());
255234
this.context.register(SecurityConfiguration.class);
256235
this.context.register(CrshAutoConfiguration.class);
@@ -263,12 +242,11 @@ public void testKeyAuthenticationProvider() {
263242

264243
@Test
265244
public void testSimpleAuthenticationProvider() throws Exception {
266-
MockEnvironment env = new MockEnvironment();
267-
env.setProperty("shell.auth.type", "simple");
268-
env.setProperty("shell.auth.simple.user.name", "user");
269-
env.setProperty("shell.auth.simple.user.password", "password");
270245
this.context = new AnnotationConfigWebApplicationContext();
271-
this.context.setEnvironment(env);
246+
EnvironmentTestUtils.addEnvironment(this.context,
247+
"management.shell.auth.type=simple",
248+
"management.shell.auth.simple.user.name=user",
249+
"management.shell.auth.simple.user.password=password");
272250
this.context.setServletContext(new MockServletContext());
273251
this.context.register(SecurityConfiguration.class);
274252
this.context.register(CrshAutoConfiguration.class);
@@ -293,10 +271,9 @@ public void testSimpleAuthenticationProvider() throws Exception {
293271

294272
@Test
295273
public void testSpringAuthenticationProvider() throws Exception {
296-
MockEnvironment env = new MockEnvironment();
297-
env.setProperty("shell.auth.type", "spring");
298274
this.context = new AnnotationConfigWebApplicationContext();
299-
this.context.setEnvironment(env);
275+
EnvironmentTestUtils.addEnvironment(this.context,
276+
"management.shell.auth.type=spring");
300277
this.context.setServletContext(new MockServletContext());
301278
this.context.register(SecurityConfiguration.class);
302279
this.context.register(CrshAutoConfiguration.class);
@@ -345,6 +322,14 @@ public void testSpringAuthenticationProviderAsDefaultConfiguration()
345322
SecurityConfiguration.PASSWORD)).isFalse();
346323
}
347324

325+
private void load(String... environment) {
326+
this.context = new AnnotationConfigWebApplicationContext();
327+
EnvironmentTestUtils.addEnvironment(this.context, environment);
328+
this.context.register(CrshAutoConfiguration.class);
329+
this.context.refresh();
330+
}
331+
332+
348333
@Configuration
349334
public static class SecurityConfiguration {
350335

0 commit comments

Comments
 (0)