Skip to content

Commit 6d11d73

Browse files
committed
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 spring-projectsgh-5139
1 parent 35270e9 commit 6d11d73

File tree

6 files changed

+54
-36
lines changed

6 files changed

+54
-36
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public AuthenticationManagerAdapter shellAuthenticationManager() {
185185
@Bean
186186
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
187187
public SpringAuthenticationProperties springAuthenticationProperties() {
188-
// In case no shell.auth property is provided fall back to Spring Security
188+
// In case no shell.auth.type property is provided fall back to Spring Security
189189
// based authentication and get role to access shell from
190190
// ManagementServerProperties.
191-
// In case shell.auth is set to spring and roles are configured using
191+
// In case shell.auth.type is set to spring and roles are configured using
192192
// shell.auth.spring.roles the below default role will be overridden by
193193
// ConfigurationProperties.
194194
SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties();

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

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ public class ShellProperties {
4343

4444
private static final Log logger = LogFactory.getLog(ShellProperties.class);
4545

46-
/**
47-
* Authentication type. Auto-detected according to the environment (i.e. if Spring
48-
* Security is available, "spring" is used by default).
49-
*/
50-
private String auth = "simple";
51-
52-
private boolean defaultAuth = true;
46+
private final Auth auth = new Auth();
5347

5448
@Autowired(required = false)
5549
private CrshShellProperties[] additionalProperties = new CrshShellProperties[] {
@@ -86,13 +80,7 @@ public class ShellProperties {
8680

8781
private final Telnet telnet = new Telnet();
8882

89-
public void setAuth(String auth) {
90-
Assert.hasLength(auth, "Auth must not be empty");
91-
this.auth = auth;
92-
this.defaultAuth = false;
93-
}
94-
95-
public String getAuth() {
83+
public Auth getAuth() {
9684
return this.auth;
9785
}
9886

@@ -191,15 +179,7 @@ public Properties asCrshShellConfig() {
191179
* @param properties the properties to validate
192180
*/
193181
protected void validateCrshShellConfig(Properties properties) {
194-
String finalAuth = properties.getProperty("crash.auth");
195-
if (!this.defaultAuth && !this.auth.equals(finalAuth)) {
196-
logger.warn(String.format(
197-
"Shell authentication fell back to method '%s' opposed to "
198-
+ "configured method '%s'. Please check your classpath.",
199-
finalAuth, this.auth));
200-
}
201-
// Make sure we keep track of final authentication method
202-
this.auth = finalAuth;
182+
getAuth().validateCrshShellConfig(properties);
203183
}
204184

205185
/**
@@ -223,6 +203,44 @@ public static abstract class CrshShellAuthenticationProperties
223203

224204
}
225205

206+
public static class Auth {
207+
208+
/**
209+
* Authentication type. Auto-detected according to the environment (i.e. if Spring
210+
* Security is available, "spring" is used by default).
211+
*/
212+
private String type = "simple";
213+
214+
private boolean defaultAuth = true;
215+
216+
public String getType() {
217+
return this.type;
218+
}
219+
220+
public void setType(String type) {
221+
Assert.hasLength(type, "Auth type must not be empty");
222+
this.type = type;
223+
this.defaultAuth = false;
224+
}
225+
226+
/**
227+
* Basic validation of applied CRaSH shell configuration.
228+
* @param properties the properties to validate
229+
*/
230+
protected void validateCrshShellConfig(Properties properties) {
231+
String finalAuth = properties.getProperty("crash.auth");
232+
if (!this.defaultAuth && !this.type.equals(finalAuth)) {
233+
logger.warn(String.format(
234+
"Shell authentication fell back to method '%s' opposed to "
235+
+ "configured method '%s'. Please check your classpath.",
236+
finalAuth, this.type));
237+
}
238+
// Make sure we keep track of final authentication method
239+
this.type = finalAuth;
240+
}
241+
242+
}
243+
226244
/**
227245
* SSH properties.
228246
*/

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",
258+
"name": "shell.auth.type",
259259
"values": [
260260
{
261261
"value": "simple",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public void testDefaultAuthenticationProvider() {
230230
@Test
231231
public void testJaasAuthenticationProvider() {
232232
MockEnvironment env = new MockEnvironment();
233-
env.setProperty("shell.auth", "jaas");
233+
env.setProperty("shell.auth.type", "jaas");
234234
env.setProperty("shell.auth.jaas.domain", "my-test-domain");
235235
this.context = new AnnotationConfigWebApplicationContext();
236236
this.context.setEnvironment(env);
@@ -247,7 +247,7 @@ public void testJaasAuthenticationProvider() {
247247
@Test
248248
public void testKeyAuthenticationProvider() {
249249
MockEnvironment env = new MockEnvironment();
250-
env.setProperty("shell.auth", "key");
250+
env.setProperty("shell.auth.type", "key");
251251
env.setProperty("shell.auth.key.path", "~/test.pem");
252252
this.context = new AnnotationConfigWebApplicationContext();
253253
this.context.setEnvironment(env);
@@ -264,7 +264,7 @@ public void testKeyAuthenticationProvider() {
264264
@Test
265265
public void testSimpleAuthenticationProvider() throws Exception {
266266
MockEnvironment env = new MockEnvironment();
267-
env.setProperty("shell.auth", "simple");
267+
env.setProperty("shell.auth.type", "simple");
268268
env.setProperty("shell.auth.simple.user.name", "user");
269269
env.setProperty("shell.auth.simple.user.password", "password");
270270
this.context = new AnnotationConfigWebApplicationContext();
@@ -294,7 +294,7 @@ public void testSimpleAuthenticationProvider() throws Exception {
294294
@Test
295295
public void testSpringAuthenticationProvider() throws Exception {
296296
MockEnvironment env = new MockEnvironment();
297-
env.setProperty("shell.auth", "spring");
297+
env.setProperty("shell.auth.type", "spring");
298298
this.context = new AnnotationConfigWebApplicationContext();
299299
this.context.setEnvironment(env);
300300
this.context.setServletContext(new MockServletContext());

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ public void testBindingAuth() {
5454
ShellProperties props = new ShellProperties();
5555
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
5656
binder.bind(new MutablePropertyValues(
57-
Collections.singletonMap("shell.auth", "spring")));
57+
Collections.singletonMap("shell.auth.type", "spring")));
5858
assertThat(binder.getBindingResult().hasErrors()).isFalse();
59-
assertThat(props.getAuth()).isEqualTo("spring");
59+
assertThat(props.getAuth().getType()).isEqualTo("spring");
6060
}
6161

6262
@Test
6363
public void testBindingAuthIfEmpty() {
6464
ShellProperties props = new ShellProperties();
6565
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
6666
binder.bind(
67-
new MutablePropertyValues(Collections.singletonMap("shell.auth", "")));
67+
new MutablePropertyValues(Collections.singletonMap("shell.auth.type", "")));
6868
assertThat(binder.getBindingResult().hasErrors()).isTrue();
69-
assertThat(props.getAuth()).isEqualTo("simple");
69+
assertThat(props.getAuth().getType()).isEqualTo("simple");
7070
}
7171

7272
@Test
@@ -299,7 +299,7 @@ public void testBindingSpring() {
299299
@Test
300300
public void testCustomShellProperties() throws Exception {
301301
MockEnvironment env = new MockEnvironment();
302-
env.setProperty("shell.auth", "simple");
302+
env.setProperty("shell.auth.type", "simple");
303303
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
304304
context.setEnvironment(env);
305305
context.setServletContext(new MockServletContext());

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ content into your application; rather pick only the properties that you need.
10111011
management.trace.include=request-headers,response-headers,errors # Items to be included in the trace.
10121012
10131013
# REMOTE SHELL
1014-
shell.auth=simple # Authentication type. Auto-detected according to the environment.
1014+
shell.auth.type=simple # Authentication type. Auto-detected according to the environment.
10151015
shell.auth.jaas.domain=my-domain # JAAS domain.
10161016
shell.auth.key.path= # Path to the authentication key. This should point to a valid ".pem" file.
10171017
shell.auth.simple.user.name=user # Login user.

0 commit comments

Comments
 (0)