开发者

How do I access the user's password from LDAP in a LdapUserDetailsMapper using spring security?

We are using spring security in our web application based on spring MVC.

We are doing authentication using LDAP module of spring security which is working properly. Now I need to get the user password from LDAP for saving in the database.

For this I am using this in my code.

    public class PersonContextMapper implements UserDetailsContextMa开发者_如何转开发pper {

    public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection<GrantedAuthority> authorities) {
    Person.Essence p = new Person.Essence(ctx);

    p.setUsername(username);
    p.setAuthorities(authorities);

        Object passwordValue = ctx.getObjectAttribute("userPassword");

    return p.createUserDetails();

    }

    public void mapUserToContext(UserDetails user, DirContextAdapter ctx) {
    Assert.isInstanceOf(Person.class, user, "UserDetails must be a Person instance");

    Person p = (Person) user;
    p.populateContext(ctx);
    }
}

But I am not getting the any value for the password. Its always null.

Please help.

PS. My authentication is successful. It means password entered in the login form is matches properly with the password stored in the LDAP.


It might be that the authentication state of the connection does not have permission to read the value of the userPassword attribute. Most often, applications issue a BIND request to the directory server, including appropriate controls as necessary. The password is included in the BIND request and the directory server changes the authentication state of the connection upon successful completion of the BIND request. In any case, the value of the userPassword attribute is encrypted or hashed more often than not, and applications have no need to read the value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜