Modify the entry password in LDAP JNDI

Source: Internet
Author: User
Tags openldap

(1) Development and configuration scenarios

 

Ldapserver

OpenLDAP

Configure Password Storage

MD5

LDAP client Test

JNDI

LDAP client Test

Jldap

(2) Practice

 

  1. Confirm the LDAP server password storage method, such as MD5, Sha, and ssha.
  2. Confirm the LDAP server password storage rules. For example, the MD5 password string supported by OpenLDAP must be base64-encoded.
  3. MD5-based LDAP server entry password storage practices.
    1. Flowchart

 

 

 

  1. Sample Code

 

/** <Br/> * modify the password of the specified DN entry <br/> * <p> <strong> note: the entry must support the userpassword attribute </strong> </P> <br/> * @ Param DN for a given DN <br/> * @ Param passwd password <br/> * @ Param type password Storage Mode {MD5, sha, etc} <br/> * @ return rtnflag {true: Successful; false: Failed} <br/> */<br/> Public Boolean modifypassword (string DN, string passwd, int type) {<br/> attributes attrs = new basicattributes (); <br/> attrs. put ("userpassword", ldapsecurityutils. getopenldapmd5 (passwd); <br/> Boolean rtnflag = false; <br/> try {<br/> This. CTX. modifyattributes (DN, dircontext. replace_attribute, attrs); <br/> rtnflag = true; <br/>}catch (namingexception e) {<br/> E. printstacktrace (); <br/>}< br/> return rtnflag; <br/>}

 

  1. Problems
    1. Cache problem. I used the client to modify the password of a user, but the password did not change when querying from other clients.
      1. You need to restart the LDAP server to see the change.
      2. It is normal to use JNDI directly.
      3. Thus, the problem lies in the jldap connection configuration management module.
    1. The password stored in OpenLDAP uses MD5 as an example. Its MD5 is not a common MD5 and it has its own rules, as described below:
      1. First, convert the plaintext to the MD5 byte group.
      2. Base64 processing of byte groups
      3. Add the prefix {MD5} to the base64 processed string}
      4. Similarly, should Sha and ssha perform similar operations? (Verification not yet performed)

 

(3) References

  • Download Sample Code
  1. Http://download.csdn.net/source/3310678
  2. Http://download.csdn.net/source/3305804
  • Base64 principle http://baike.baidu.com/view/469071.htm
  • PHP method to achieve http://www.ixpub.net/thread-2055529-1-1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.