Added test for non-String role.

This commit is contained in:
Luke Taylor 2006-06-14 23:20:51 +00:00
parent 49da801096
commit aaf51c4bee
1 changed files with 15 additions and 0 deletions

View File

@ -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);
}
}