Expand test coverage so GrantedAuthorityEffectiveAclsResolver properly handles Authentication with a principal of type UserDetails.

This commit is contained in:
Ben Alex 2004-11-15 00:34:32 +00:00
parent f6b9ab0dde
commit e83c66bb37
1 changed files with 19 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.acl.AclEntry;
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import net.sf.acegisecurity.providers.dao.User;
/**
@ -53,6 +54,11 @@ public class GrantedAuthorityEffectiveAclsResolverTests extends TestCase {
private SimpleAclEntry entry100Marissa = new SimpleAclEntry(marissa
.getPrincipal(), new NamedEntityObjectIdentity("OBJECT", "100"),
null, 2);
private UsernamePasswordAuthenticationToken scottWithUserDetails = new UsernamePasswordAuthenticationToken(new User(
"scott", "NOT_USED", true,
new GrantedAuthority[] {new GrantedAuthorityImpl(
"ROLE_EVERYBODY")}), "not used",
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_EVERYBODY"), new GrantedAuthorityImpl("ROLE_TWO")});
// convenience group
private SimpleAclEntry[] acls = {entry100Marissa, entry100Scott, entry100RoleEverybody, entry100RoleOne, entry100RoleTwo};
@ -93,7 +99,7 @@ public class GrantedAuthorityEffectiveAclsResolverTests extends TestCase {
resolver.resolveEffectiveAcls(acls, marissa)[2]);
}
public void testResolveAclsForScott() {
public void testResolveAclsForScottWithStringObjectAsPrincipal() {
GrantedAuthorityEffectiveAclsResolver resolver = new GrantedAuthorityEffectiveAclsResolver();
assertEquals(3, resolver.resolveEffectiveAcls(acls, scott).length);
assertEquals(entry100Scott,
@ -104,6 +110,18 @@ public class GrantedAuthorityEffectiveAclsResolverTests extends TestCase {
resolver.resolveEffectiveAcls(acls, scott)[2]);
}
public void testResolveAclsForScottWithUserDetailsObjectAsPrincipal() {
GrantedAuthorityEffectiveAclsResolver resolver = new GrantedAuthorityEffectiveAclsResolver();
assertEquals(3,
resolver.resolveEffectiveAcls(acls, scottWithUserDetails).length);
assertEquals(entry100Scott,
resolver.resolveEffectiveAcls(acls, scottWithUserDetails)[0]);
assertEquals(entry100RoleEverybody,
resolver.resolveEffectiveAcls(acls, scottWithUserDetails)[1]);
assertEquals(entry100RoleTwo,
resolver.resolveEffectiveAcls(acls, scottWithUserDetails)[2]);
}
public void testResolveAclsReturnsNullIfNoAclsInFirstPlace() {
GrantedAuthorityEffectiveAclsResolver resolver = new GrantedAuthorityEffectiveAclsResolver();
assertNull(resolver.resolveEffectiveAcls(null, scott));