From e83c66bb3763fb1a0d27de1cea7fc89b30902a03 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Mon, 15 Nov 2004 00:34:32 +0000 Subject: [PATCH] Expand test coverage so GrantedAuthorityEffectiveAclsResolver properly handles Authentication with a principal of type UserDetails. --- ...edAuthorityEffectiveAclsResolverTests.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolverTests.java b/core/src/test/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolverTests.java index ba8babc322..deada7925e 100644 --- a/core/src/test/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolverTests.java +++ b/core/src/test/java/org/acegisecurity/acl/basic/GrantedAuthorityEffectiveAclsResolverTests.java @@ -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));