JAVA操作LDAP互動

2021-09-24 21:49:42 字數 3169 閱讀 5327

首先定義全域性的ldap的ip位址等 看截圖  ↓p1j#yz@gg*ae

開啟ldap服務, 每次進行curd操作都需開服務 類似於jdbc那種

/** 關閉ldap連線     */

public void close() catch (namingexception e) }}

/** 新增 */

public static void add() ;

arrays.sort(attrobjectclassperson);

for (string ocp : attrobjectclassperson)

attrs.put(objclass);

string userdn = "cn=" + newusername + "," + "ou=人力資源,ou=集團,ou=hq,dc=iamtest,dc=com";

int uf_passwd_notreqd = 0x0020;

int uf_normal_account = 0x0200;

int uf_dont_expire_passwd = 0x10000;

attrs.put("name",newusername);

attrs.put("cn",newusername);

attrs.put("objectcategory","cn=group,cn=schema,cn=configuration,dc=iamtest,dc=com");

attrs.put("distinguishedname","cn=ai技術部門,ou=人力資源,ou=集團,ou=hq,dc=iamtest,dc=com");

/*** 建立組內成員

*//*string attrobjectclassperson = ;

arrays.sort(attrobjectclassperson);

for (string ocp : attrobjectclassperson)

attrs.put(objclass);

attrs.put("sn", "ai");

attrs.put("givenname", "nbai");

attrs.put("cn", newusername);

attrs.put("displayname", newusername);

attrs.put("mail", "[email protected]");

attrs.put("description", "test1");

attrs.put("userprincipalname", "[email protected]");

attrs.put("samaccountname", newusername);

attrs.put("msds-supportedencryptiontypes", "0");

attrs.put("facsimiletelephonenumber", "1232342");

attrs.put("pager", "****");

attrs.put("ipphone", "****");

attrs.put("homephone", "********");

attrs.put("mobile", "***********");

attrs.put("useraccountcontrol",integer.tostring(uf_dont_expire_passwd + uf_normal_account + uf_passwd_notreqd)); */

/*** 建立單個ou 目錄

*//*basicattributes attrs = new basicattributes();

basicattribute objclassset = new basicattribute("objectclass");

objclassset.add("organizationalunit");

objclassset.add("top");

attrs.put(objclassset);

attrs.put("ou", "permissions group");

dc.createsubcontext("ou=permissions group," + "ou=people,dc=iamtest,dc=com",attrs);*/

dc.createsubcontext(userdn, attrs); 

system.out.println("新增節點目錄成功!!!");

} catch (exception e)

}/**

* 修改  

* @throws exception

*/public static void testmodify() throws exception  

/** 查詢

* @param base :根節點(在這裡是"dc=example,dc=com")

* @param scope :搜尋範圍,分為"base"(本節點),"one"(單層),""(遍歷)

* @param filter :指定子節點(格式為"(objectclass=*)",*是指全部,你也可以指定某一特定型別的樹節點)

*/public static void searchinformation() else if (scope.equals("one")) else

namingenumeration ne = null;

try else

attributes at = sr.getattributes();

namingenumeration ane = at.getall();

while (ane.hasmore()) else }}

}} catch (exception nex)

}/** 刪除  */

public static void delete() catch (exception e)

}廢話真多 直接上** 真好1

JAVA 基本LDAP操作例項

一 簡介 cd cas,dc mydc cn users uid zhangsan 二 示例 1 通過ldapcontext連線ldap 連線ldap suppresswarnings public ldapcontext connetldap throws namingexception2 增加使...

ldap資訊互動未完成

1 error reporting e all e notice 45 class ldap 18return false 19 2021 關閉連線 22public function close 27return true 28 2930 新增使用者 31public function addus...

LDAP操作例子

查詢的 include ldap.h include stdio.h int main 設定伺服器版本 version ldap version3 ldap set option ld,ldap opt protocol version,version 繫結伺服器 if ldap bind s ld...