mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-25 13:32:30 +00:00
Polish MethodSecurityEvaluationContext
Issue: gh-6224
This commit is contained in:
parent
150b66824d
commit
924b9e95a1
@ -17,7 +17,6 @@
|
|||||||
package org.springframework.security.config.annotation.method.configuration;
|
package org.springframework.security.config.annotation.method.configuration;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -44,12 +43,12 @@ public class ReactiveMethodSecurityConfigurationTests {
|
|||||||
DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler;
|
DefaultMethodSecurityExpressionHandler methodSecurityExpressionHandler;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rolePrefixWithGrantedAuthorityDefaults() {
|
public void rolePrefixWithGrantedAuthorityDefaults() throws NoSuchMethodException {
|
||||||
this.spring.register(WithRolePrefixConfiguration.class).autowire();
|
this.spring.register(WithRolePrefixConfiguration.class).autowire();
|
||||||
|
|
||||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
||||||
"principal", "credential", "CUSTOM_ABC");
|
"principal", "credential", "CUSTOM_ABC");
|
||||||
MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class);
|
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
|
||||||
|
|
||||||
EvaluationContext context = this.methodSecurityExpressionHandler
|
EvaluationContext context = this.methodSecurityExpressionHandler
|
||||||
.createEvaluationContext(authentication, methodInvocation);
|
.createEvaluationContext(authentication, methodInvocation);
|
||||||
@ -63,12 +62,12 @@ public class ReactiveMethodSecurityConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rolePrefixWithDefaultConfig() {
|
public void rolePrefixWithDefaultConfig() throws NoSuchMethodException {
|
||||||
this.spring.register(ReactiveMethodSecurityConfiguration.class).autowire();
|
this.spring.register(ReactiveMethodSecurityConfiguration.class).autowire();
|
||||||
|
|
||||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
||||||
"principal", "credential", "ROLE_ABC");
|
"principal", "credential", "ROLE_ABC");
|
||||||
MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class);
|
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
|
||||||
|
|
||||||
EvaluationContext context = this.methodSecurityExpressionHandler
|
EvaluationContext context = this.methodSecurityExpressionHandler
|
||||||
.createEvaluationContext(authentication, methodInvocation);
|
.createEvaluationContext(authentication, methodInvocation);
|
||||||
@ -89,12 +88,12 @@ public class ReactiveMethodSecurityConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled() {
|
public void rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled() throws NoSuchMethodException {
|
||||||
this.spring.register(SubclassConfig.class).autowire();
|
this.spring.register(SubclassConfig.class).autowire();
|
||||||
|
|
||||||
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
TestingAuthenticationToken authentication = new TestingAuthenticationToken(
|
||||||
"principal", "credential", "ROLE_ABC");
|
"principal", "credential", "ROLE_ABC");
|
||||||
MockMethodInvocation methodInvocation = mock(MockMethodInvocation.class);
|
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
|
||||||
|
|
||||||
EvaluationContext context = this.methodSecurityExpressionHandler
|
EvaluationContext context = this.methodSecurityExpressionHandler
|
||||||
.createEvaluationContext(authentication, methodInvocation);
|
.createEvaluationContext(authentication, methodInvocation);
|
||||||
@ -108,4 +107,9 @@ public class ReactiveMethodSecurityConfigurationTests {
|
|||||||
@Configuration
|
@Configuration
|
||||||
static class SubclassConfig extends ReactiveMethodSecurityConfiguration {
|
static class SubclassConfig extends ReactiveMethodSecurityConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Foo {
|
||||||
|
public void bar(String param){
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user