Skip to content

Commit 20fa1b3

Browse files
vpavicsnicoll
authored andcommitted
Support configuration of multiple management roles
Closes gh-5045
1 parent e9a226c commit 20fa1b3

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
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
@@ -196,8 +196,8 @@ public SpringAuthenticationProperties springAuthenticationProperties() {
196196
// overridden by ConfigurationProperties.
197197
SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties();
198198
if (this.management != null) {
199-
authenticationProperties.setRoles(
200-
new String[] { this.management.getSecurity().getRole() });
199+
List<String> roles = this.management.getSecurity().getRole();
200+
authenticationProperties.setRoles(roles.toArray(new String[roles.size()]));
201201
}
202202
return authenticationProperties;
203203
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
package org.springframework.boot.actuate.autoconfigure;
1818

1919
import java.net.InetAddress;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.List;
2023

2124
import javax.validation.constraints.NotNull;
2225

@@ -33,6 +36,7 @@
3336
*
3437
* @author Dave Syer
3538
* @author Stephane Nicoll
39+
* @author Vedran Pavic
3640
* @see ServerProperties
3741
*/
3842
@ConfigurationProperties(prefix = "management", ignoreUnknownFields = true)
@@ -160,9 +164,9 @@ public static class Security {
160164
private boolean enabled = true;
161165

162166
/**
163-
* Role required to access the management endpoint.
167+
* Roles required to access the management endpoint.
164168
*/
165-
private String role = "ADMIN";
169+
private List<String> role = new ArrayList<String>(Arrays.asList("ADMIN"));
166170

167171
/**
168172
* Session creating policy to use (always, never, if_required, stateless).
@@ -177,11 +181,11 @@ public void setSessions(SessionCreationPolicy sessions) {
177181
this.sessions = sessions;
178182
}
179183

180-
public void setRole(String role) {
184+
public void setRole(List<String> role) {
181185
this.role = role;
182186
}
183187

184-
public String getRole() {
188+
public List<String> getRole() {
185189
return this.role;
186190
}
187191

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public ManagementSecurityPropertiesConfiguration(
124124
public void init() {
125125
if (this.management != null && this.security != null) {
126126
this.security.getUser().getRole()
127-
.add(this.management.getSecurity().getRole());
127+
.addAll(this.management.getSecurity().getRole());
128128
}
129129
}
130130

@@ -296,8 +296,9 @@ private void configurePermittedRequests(
296296
// Permit access to the non-sensitive endpoints
297297
requests.requestMatchers(new LazyEndpointPathRequestMatcher(
298298
this.contextResolver, EndpointPaths.NON_SENSITIVE)).permitAll();
299-
// Restrict the rest to the configured role
300-
requests.anyRequest().hasRole(this.management.getSecurity().getRole());
299+
// Restrict the rest to the configured roles
300+
List<String> roles = this.management.getSecurity().getRole();
301+
requests.anyRequest().hasAnyRole(roles.toArray(new String[roles.size()]));
301302
}
302303

303304
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ content into your application; rather pick only the properties that you need.
996996
management.context-path= # Management endpoint context-path. For instance `/actuator`
997997
management.port= # Management endpoint HTTP port. Use the same port as the application by default.
998998
management.security.enabled=true # Enable security.
999-
management.security.role=ADMIN # Role required to access the management endpoint.
999+
management.security.role=ADMIN # Roles required to access the management endpoint.
10001000
management.security.sessions=stateless # Session creating policy to use (always, never, if_required, stateless).
10011001
10021002
# HEALTH INDICATORS (previously health.*)

spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ TIP: Generated passwords are logged as the application starts. Search for '`Usin
520520
security password`'.
521521

522522
You can use Spring properties to change the username and password and to change the
523-
security role required to access the endpoints. For example, you might set the following
523+
security roles required to access the endpoints. For example, you might set the following
524524
in your `application.properties`:
525525

526526
[source,properties,indent=0]

0 commit comments

Comments
 (0)