From aaf51c4bee04076558ecd2ad6806865673bf15c3 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Wed, 14 Jun 2006 23:20:51 +0000 Subject: [PATCH] Added test for non-String role. --- .../ldap/LdapUserDetailsMapperTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsMapperTests.java b/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsMapperTests.java index e11749b5a6..2c1dc600b1 100644 --- a/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsMapperTests.java +++ b/core/src/main/java/org/acegisecurity/userdetails/ldap/LdapUserDetailsMapperTests.java @@ -20,6 +20,8 @@ import junit.framework.TestCase; import javax.naming.directory.BasicAttributes; import javax.naming.directory.BasicAttribute; +import org.acegisecurity.GrantedAuthorityImpl; + /** * Tests {@link LdapUserDetailsMapper}. * @@ -64,4 +66,17 @@ public class LdapUserDetailsMapperTests extends TestCase { assertEquals(1, user.getGrantedAuthorities().length); assertEquals("ROLE_X", user.getGrantedAuthorities()[0].getAuthority()); } + + public void testNonStringRoleAttributeIsIgnoredByDefault() throws Exception { + LdapUserDetailsMapper mapper = new LdapUserDetailsMapper(); + + mapper.setRoleAttributes(new String[] {"userRole"}); + + BasicAttributes attrs = new BasicAttributes(); + attrs.put(new BasicAttribute("userRole", new GrantedAuthorityImpl("X"))); + + LdapUserDetailsImpl.Essence user = (LdapUserDetailsImpl.Essence) mapper.mapAttributes("cn=someName", attrs); + + assertEquals(0, user.getGrantedAuthorities().length); + } }