Minor fix to enable LDAP customization of first and last name.

This commit is contained in:
Paulo Gustavo Veiga 2013-02-24 17:46:05 -03:00
parent 9ab0637690
commit 846ad24bf3
3 changed files with 27 additions and 3 deletions

View File

@ -19,6 +19,8 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
private UserService userService;
private String adminUser;
private String ldapAttributeFirstName;
private String ldapAttributeLastName;
public UserService getUserService() {
@ -51,10 +53,10 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
user = new User();
user.setEmail(email);
final String firstName = userData.getStringAttribute("givenName");
final String firstName = userData.getStringAttribute(ldapAttributeFirstName);
user.setFirstname(firstName);
final String lastName = userData.getStringAttribute("sn");
final String lastName = userData.getStringAttribute(ldapAttributeLastName);
user.setLastname(lastName);
user.setPassword(email);
@ -62,7 +64,7 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
user.setActivationDate(now);
try {
userService.createUser(user, false,false);
userService.createUser(user, false, false);
} catch (WiseMappingException e) {
throw new IllegalStateException(e);
}
@ -70,6 +72,22 @@ public class LdapUserDetailsContextMapper implements UserDetailsContextMapper {
return new UserDetails(user, isAdmin(email));
}
public String getLdapAttributeLastName() {
return ldapAttributeLastName;
}
public void setLdapAttributeLastName(String ldapAttributLastName) {
this.ldapAttributeLastName = ldapAttributLastName;
}
public String getLdapAttrbutFirstName() {
return ldapAttributeFirstName;
}
public void setLdapAttributeFirstName(String ldapAttributeFirstName) {
this.ldapAttributeFirstName = ldapAttributeFirstName;
}
@Override
public void mapUserToContext(org.springframework.security.core.userdetails.UserDetails userDetails, DirContextAdapter dirContextAdapter) {
// To be implemented ...

View File

@ -128,6 +128,10 @@ security.ldap.basedn=dc=wisemapping,dc=com
security.ldap.subDn=people
security.ldap.auth.attribute=mail
security.ldap.lastName.attribute=sn
security.ldap.firstName.attribute=givenName

View File

@ -39,6 +39,8 @@
<bean id="userDetailsContextMapper" class="com.wisemapping.security.ldap.LdapUserDetailsContextMapper">
<property name="userService" ref="userService"/>
<property name="ldapAttributeFirstName" value="${security.ldap.firstName.attribute}"/>
<property name="ldapAttributeLastName" value="${security.ldap.lastName.attribute}"/>
</bean>
<bean id="ldapUserSearch"