SEC-1245: Add role hierarchy support to expression handlers. Done.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package org.springframework.security.access.expression;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchy;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SecurityExpressionRootTests {
|
||||
|
||||
@Test
|
||||
public void roleHierarchySupportIsCorrectlyUsedInEvaluatingRoles() throws Exception {
|
||||
SecurityExpressionRoot root =
|
||||
new SecurityExpressionRoot(new TestingAuthenticationToken("joe", "pass", "A", "B")) {};
|
||||
|
||||
root.setRoleHierarchy(new RoleHierarchy() {
|
||||
public List<GrantedAuthority> getReachableGrantedAuthorities(List<GrantedAuthority> authorities) {
|
||||
return AuthorityUtils.createAuthorityList("C");
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue(root.hasRole("C"));
|
||||
assertFalse(root.hasRole("A"));
|
||||
assertFalse(root.hasRole("B"));
|
||||
assertTrue(root.hasAnyRole("C", "A", "B"));
|
||||
assertFalse(root.hasAnyRole("A", "B"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user