修改ladp属性.

来源:互联网 发布:稀疏a算法一致性条件 编辑:程序博客网 时间:2024/06/04 19:12

添加ldapjdk.jar库..

如:关闭ldap帐号认证.

 

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2008</p>
 * <p>Company: Geong</p>
 * @author Will he
 * @date 2008-4-02
 * @version 1.0
 */
  package ldap;

import netscape.ldap.LDAPAttribute;
import netscape.ldap.LDAPConnection;
import netscape.ldap.LDAPException;
import netscape.ldap.LDAPModification;
import netscape.ldap.LDAPModificationSet;

/**
 * 
@author willhe
 *  修改ldap属性..
 *  关闭ldap帐号..
 
*/

public class LdapModifyAttributeTest {

    
/**
     * 
@param args
     
*/

    
public static void main(String[] args) {
        test();
    }


    
public static void test(){
        
/**
         * 在原有基础上添加一个属性,用来关闭ldap帐号
         
*/

        LDAPConnection ldapCon 
= null;
        String hostname 
="";
        
int port = 389;
        String ldapdn 
="ou=People,o=bankcomm.com,o=bankcomm";
        String uid 
= "";
        
        
try {
            ldapCon 
= new LDAPConnection();
            ldapCon.connect(hostname, port);
            
//管理端密码.
            ldapCon.authenticate("cn=directory manager""******");
            String dn 
= "uid=" + uid + "," + ldapdn;
            LDAPModificationSet set 
= new LDAPModificationSet();
            set.add(LDAPModification.REPLACE, 
new LDAPAttribute("uid", uid));
            set.add(LDAPModification.ADD, 
new LDAPAttribute("nsaccountlock""true"));
            ldapCon.modify(dn, set);
            

        }
 catch (LDAPException e) {
            System.out.println(
"-------LDAPException:" +e.getMessage());
            
        }
 finally {
            
try {
                
if (ldapCon != null)
                    ldapCon.disconnect();
            }
 catch (LDAPException e) {
                System.out.println(
"LDAPException closed ldapCon;" +e.getMessage());
            }

        }


    }

    
}
原创粉丝点击