use of org.springframework.security.ldap.DefaultLdapUsernameToDnMapper in project spring-security by spring-projects.
the class LdapUserDetailsManagerTests method testLoadUserByUsernameReturnsCorrectData.
@Test
public void testLoadUserByUsernameReturnsCorrectData() {
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
mgr.setGroupSearchBase("ou=groups");
LdapUserDetails bob = (LdapUserDetails) mgr.loadUserByUsername("bob");
assertThat(bob.getUsername()).isEqualTo("bob");
assertThat(bob.getDn()).isEqualTo("uid=bob,ou=people,dc=springframework,dc=org");
assertThat(bob.getPassword()).isEqualTo("bobspassword");
assertThat(bob.getAuthorities()).hasSize(1);
}
use of org.springframework.security.ldap.DefaultLdapUsernameToDnMapper in project spring-security by spring-projects.
the class LdapUserDetailsManagerTests method setUp.
@Before
public void setUp() throws Exception {
mgr = new LdapUserDetailsManager(getContextSource());
template = new SpringSecurityLdapTemplate(getContextSource());
DirContextAdapter ctx = new DirContextAdapter();
ctx.setAttributeValue("objectclass", "organizationalUnit");
ctx.setAttributeValue("ou", "test people");
template.bind("ou=test people", ctx, null);
ctx.setAttributeValue("ou", "testgroups");
template.bind("ou=testgroups", ctx, null);
DirContextAdapter group = new DirContextAdapter();
group.setAttributeValue("objectclass", "groupOfNames");
group.setAttributeValue("cn", "clowns");
group.setAttributeValue("member", "cn=nobody,ou=test people,dc=springframework,dc=org");
template.bind("cn=clowns,ou=testgroups", group, null);
group.setAttributeValue("cn", "acrobats");
template.bind("cn=acrobats,ou=testgroups", group, null);
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=test people", "uid"));
mgr.setGroupSearchBase("ou=testgroups");
mgr.setGroupRoleAttributeName("cn");
mgr.setGroupMemberAttributeName("member");
mgr.setUserDetailsMapper(new PersonContextMapper());
}
use of org.springframework.security.ldap.DefaultLdapUsernameToDnMapper in project spring-security by spring-projects.
the class LdapUserDetailsManagerTests method testUserExistsReturnsTrueForValidUser.
@Test
public void testUserExistsReturnsTrueForValidUser() {
mgr.setUsernameMapper(new DefaultLdapUsernameToDnMapper("ou=people", "uid"));
assertThat(mgr.userExists("bob")).isTrue();
}
Aggregations