use of org.springframework.ldap.core.DistinguishedName in project spring-security by spring-projects.
the class LdapUserDetailsMapperTests method testNonRetrievedRoleAttributeIsIgnored.
/**
* SEC-303. Non-retrieved role attribute causes NullPointerException
*/
@Test
public void testNonRetrievedRoleAttributeIsIgnored() throws Exception {
LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
mapper.setRoleAttributes(new String[] { "userRole", "nonRetrievedAttribute" });
BasicAttributes attrs = new BasicAttributes();
attrs.put(new BasicAttribute("userRole", "x"));
DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName"));
ctx.setAttributeValue("uid", "ani");
LdapUserDetailsImpl user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES);
assertThat(user.getAuthorities()).hasSize(1);
assertThat(AuthorityUtils.authorityListToSet(user.getAuthorities())).contains("ROLE_X");
}
use of org.springframework.ldap.core.DistinguishedName in project spring-security by spring-projects.
the class LdapUserDetailsMapperTests method testPasswordAttributeIsMappedCorrectly.
@Test
public void testPasswordAttributeIsMappedCorrectly() throws Exception {
LdapUserDetailsMapper mapper = new LdapUserDetailsMapper();
mapper.setPasswordAttributeName("myappsPassword");
BasicAttributes attrs = new BasicAttributes();
attrs.put(new BasicAttribute("myappsPassword", "mypassword".getBytes()));
DirContextAdapter ctx = new DirContextAdapter(attrs, new DistinguishedName("cn=someName"));
ctx.setAttributeValue("uid", "ani");
LdapUserDetails user = (LdapUserDetailsImpl) mapper.mapUserFromContext(ctx, "ani", AuthorityUtils.NO_AUTHORITIES);
assertThat(user.getPassword()).isEqualTo("mypassword");
}
Aggregations