use of org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl in project spring-security by spring-projects.
the class DefaultMessageSecurityExpressionHandlerTests method roleHierarchy.
@Test
public void roleHierarchy() {
authentication = new TestingAuthenticationToken("admin", "pass", "ROLE_ADMIN");
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER");
handler.setRoleHierarchy(roleHierarchy);
EvaluationContext context = handler.createEvaluationContext(authentication, message);
Expression expression = handler.getExpressionParser().parseExpression("hasRole('ROLE_USER')");
assertThat(ExpressionUtils.evaluateAsBoolean(expression, context)).isTrue();
}
use of org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl in project spring-security by spring-projects.
the class RoleHierarchyVoterTests method hierarchicalRoleIsIncludedInDecision.
@Test
public void hierarchicalRoleIsIncludedInDecision() {
RoleHierarchyImpl roleHierarchyImpl = new RoleHierarchyImpl();
roleHierarchyImpl.setHierarchy("ROLE_A > ROLE_B");
// User has role A, role B is required
TestingAuthenticationToken auth = new TestingAuthenticationToken("user", "password", "ROLE_A");
RoleHierarchyVoter voter = new RoleHierarchyVoter(roleHierarchyImpl);
assertThat(voter.vote(auth, new Object(), SecurityConfig.createList("ROLE_B"))).isEqualTo(RoleHierarchyVoter.ACCESS_GRANTED);
}
use of org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl in project ocvn by devgateway.
the class WebSecurityConfig method roleHierarchy.
/**
* Enable hierarchical roles. This bean can be used to extract all effective roles.
*/
@Bean
RoleHierarchy roleHierarchy() {
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
roleHierarchy.setHierarchy(roleHierarchyStringRepresentation);
return roleHierarchy;
}
Aggregations