Search in sources :

Example 1 with DefaultLdapUsernameToDnMapper

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);
}
Also used : DefaultLdapUsernameToDnMapper(org.springframework.security.ldap.DefaultLdapUsernameToDnMapper) Test(org.junit.Test)

Example 2 with DefaultLdapUsernameToDnMapper

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());
}
Also used : SpringSecurityLdapTemplate(org.springframework.security.ldap.SpringSecurityLdapTemplate) DirContextAdapter(org.springframework.ldap.core.DirContextAdapter) DefaultLdapUsernameToDnMapper(org.springframework.security.ldap.DefaultLdapUsernameToDnMapper) Before(org.junit.Before)

Example 3 with DefaultLdapUsernameToDnMapper

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();
}
Also used : DefaultLdapUsernameToDnMapper(org.springframework.security.ldap.DefaultLdapUsernameToDnMapper) Test(org.junit.Test)

Aggregations

DefaultLdapUsernameToDnMapper (org.springframework.security.ldap.DefaultLdapUsernameToDnMapper)3 Test (org.junit.Test)2 Before (org.junit.Before)1 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)1 SpringSecurityLdapTemplate (org.springframework.security.ldap.SpringSecurityLdapTemplate)1