Polish contribution
Closes gh-5074
This commit is contained in:
@@ -196,7 +196,7 @@ public class CrshAutoConfiguration {
|
||||
// overridden by ConfigurationProperties.
|
||||
SpringAuthenticationProperties authenticationProperties = new SpringAuthenticationProperties();
|
||||
if (this.management != null) {
|
||||
List<String> roles = this.management.getSecurity().getRole();
|
||||
List<String> roles = this.management.getSecurity().getRoles();
|
||||
authenticationProperties.setRoles(roles.toArray(new String[roles.size()]));
|
||||
}
|
||||
return authenticationProperties;
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -164,9 +163,9 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Roles required to access the management endpoint.
|
||||
* Comma-separated list of roles that can access the management endpoint.
|
||||
*/
|
||||
private List<String> role = new ArrayList<String>(Arrays.asList("ADMIN"));
|
||||
private List<String> roles = Collections.singletonList("ADMIN");
|
||||
|
||||
/**
|
||||
* Session creating policy to use (always, never, if_required, stateless).
|
||||
@@ -181,12 +180,17 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
||||
public void setRole(List<String> role) {
|
||||
this.role = role;
|
||||
public void setRoles(List<String> roles) {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public List<String> getRole() {
|
||||
return this.role;
|
||||
@Deprecated
|
||||
public void setRole(String role) {
|
||||
this.roles = Collections.singletonList(role);
|
||||
}
|
||||
|
||||
public List<String> getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ManagementWebSecurityAutoConfiguration {
|
||||
public void init() {
|
||||
if (this.management != null && this.security != null) {
|
||||
this.security.getUser().getRole()
|
||||
.addAll(this.management.getSecurity().getRole());
|
||||
.addAll(this.management.getSecurity().getRoles());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ public class ManagementWebSecurityAutoConfiguration {
|
||||
requests.requestMatchers(new LazyEndpointPathRequestMatcher(
|
||||
this.contextResolver, EndpointPaths.NON_SENSITIVE)).permitAll();
|
||||
// Restrict the rest to the configured roles
|
||||
List<String> roles = this.management.getSecurity().getRole();
|
||||
List<String> roles = this.management.getSecurity().getRoles();
|
||||
requests.anyRequest().hasAnyRole(roles.toArray(new String[roles.size()]));
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,15 @@
|
||||
"description": "Enable git info.",
|
||||
"defaultValue": true
|
||||
},
|
||||
{
|
||||
"name": "management.security.role",
|
||||
"type": "java.lang.String",
|
||||
"description": "Roles required to access the management endpoint.",
|
||||
"defaultValue": "ADMIN",
|
||||
"deprecation": {
|
||||
"replacement": "management.security.roles"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.git.properties",
|
||||
"type": "java.lang.String",
|
||||
|
||||
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -28,6 +34,15 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class ManagementServerPropertiesAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultManagementServerProperties() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
@@ -58,4 +73,32 @@ public class ManagementServerPropertiesAutoConfigurationTests {
|
||||
assertThat(properties.getContextPath()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void managementRoleSetRolesProperly() {
|
||||
ManagementServerProperties properties = load("management.security.role=FOO");
|
||||
assertThat(properties.getSecurity().getRoles()).containsOnly("FOO");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void managementRolesSetMultipleRoles() {
|
||||
ManagementServerProperties properties = load("management.security.roles=FOO,BAR,BIZ");
|
||||
assertThat(properties.getSecurity().getRoles()).containsOnly("FOO", "BAR", "BIZ");
|
||||
}
|
||||
|
||||
public ManagementServerProperties load(String... environment) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
||||
ctx.register(TestConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
return this.context.getBean(ManagementServerProperties.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ManagementServerProperties.class)
|
||||
static class TestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user