use of org.springframework.security.access.expression.SecurityExpressionRoot in project CzechIdMng by bcvsolutions.
the class WebSecurityConfig method securityExtension.
/**
* Support hasAuthority etc. in search queries
*
* @return
*/
@Bean
public EvaluationContextExtension securityExtension() {
return new EvaluationContextExtension() {
@Override
public String getExtensionId() {
return "security";
}
@Override
public SecurityExpressionRoot getRootObject() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
// not authenticated
return null;
}
SecurityExpressionRoot root = new SecurityExpressionRoot(authentication) {
};
root.setRoleHierarchy(roleHierarchy);
return root;
}
};
}
use of org.springframework.security.access.expression.SecurityExpressionRoot in project spring-security by spring-projects.
the class ReactiveMethodSecurityConfigurationTests method rolePrefixWithDefaultConfig.
@Test
public void rolePrefixWithDefaultConfig() throws NoSuchMethodException {
this.spring.register(ReactiveMethodSecurityConfiguration.class).autowire();
TestingAuthenticationToken authentication = new TestingAuthenticationToken("principal", "credential", "ROLE_ABC");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
EvaluationContext context = this.methodSecurityExpressionHandler.createEvaluationContext(authentication, methodInvocation);
SecurityExpressionRoot root = (SecurityExpressionRoot) context.getRootObject().getValue();
assertThat(root.hasRole("ROLE_ABC")).isTrue();
assertThat(root.hasRole("ABC")).isTrue();
}
use of org.springframework.security.access.expression.SecurityExpressionRoot in project spring-security by spring-projects.
the class ReactiveMethodSecurityConfigurationTests method rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled.
@Test
public void rolePrefixWithGrantedAuthorityDefaultsAndSubclassWithProxyingEnabled() throws NoSuchMethodException {
this.spring.register(SubclassConfig.class).autowire();
TestingAuthenticationToken authentication = new TestingAuthenticationToken("principal", "credential", "ROLE_ABC");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
EvaluationContext context = this.methodSecurityExpressionHandler.createEvaluationContext(authentication, methodInvocation);
SecurityExpressionRoot root = (SecurityExpressionRoot) context.getRootObject().getValue();
assertThat(root.hasRole("ROLE_ABC")).isTrue();
assertThat(root.hasRole("ABC")).isTrue();
}
use of org.springframework.security.access.expression.SecurityExpressionRoot in project spring-security by spring-projects.
the class ReactiveMethodSecurityConfigurationTests method rolePrefixWithGrantedAuthorityDefaults.
@Test
public void rolePrefixWithGrantedAuthorityDefaults() throws NoSuchMethodException {
this.spring.register(WithRolePrefixConfiguration.class).autowire();
TestingAuthenticationToken authentication = new TestingAuthenticationToken("principal", "credential", "CUSTOM_ABC");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new Foo(), Foo.class, "bar", String.class);
EvaluationContext context = this.methodSecurityExpressionHandler.createEvaluationContext(authentication, methodInvocation);
SecurityExpressionRoot root = (SecurityExpressionRoot) context.getRootObject().getValue();
assertThat(root.hasRole("ROLE_ABC")).isFalse();
assertThat(root.hasRole("ROLE_CUSTOM_ABC")).isFalse();
assertThat(root.hasRole("CUSTOM_ABC")).isTrue();
assertThat(root.hasRole("ABC")).isTrue();
}
Aggregations