一、簡介
cd=cas,dc=mydc
—-cn=users
—-uid=zhangsan
二、示例
1、通過ldapcontext連線ldap
/**
* 連線ldap
*/@suppresswarnings()
public ldapcontext connetldap() throws namingexception
2、增加使用者zhangsan
// 新增
public void testadd() throws exception ;
arrays.sort(attrobjectclassperson);
for (string ocp : attrobjectclassperson)
attrs.put(objclass);
string uid = "zhangsan";
string userdn = "uid=" + uid + "," + "cn=users,dc=cas,dc=mydc";
// 密碼處理
// attrs.put("uid", uid);
attrs.put("cn", uid);
attrs.put("sn", uid);
attrs.put("displayname", "張三");
attrs.put("mail", "[email protected]");
attrs.put("description", "");
attrs.put("userpassword", "passw0rd".getbytes("utf-8"));
ctx.createsubcontext(userdn, attrs);
}
3、刪除使用者zhangsan
//刪除
public
void
testremove() throws exception
4、修改zhangsan的郵件位址
//修改
public
boolean
testmodify() throws exception
5、查詢使用者
//查詢
public
void
testsearch() throws exception ;
searchcontrols searchcontrols = new searchcontrols();
searchcontrols.setsearchscope(searchcontrols.subtree_scope);
// 設定將被返回的attribute
searchcontrols.setreturningattributes(attrpersonarray);
// 三個引數分別為:
// 上下文;
// 要搜尋的屬性,如果為空或 null,則返回目標上下文中的所有物件;
// 控制搜尋的搜尋控制項,如果為 null,則使用預設的搜尋控制項
namingenumerationanswer = ctx.search("cn=users,dc=cas,dc=mydc", filter.tostring(), searchcontrols);
// 輸出查到的資料
while (answer.hasmore())
system.out.println("**********==");
} }
JAVA操作LDAP互動
首先定義全域性的ldap的ip位址等 看截圖 p1j yz gg ae 開啟ldap服務,每次進行curd操作都需開服務 類似於jdbc那種 關閉ldap連線 public void close catch namingexception e 新增 public static void add ar...
基本 LDAP 語法
等於 此 ldap 引數表明某個屬性等於某個值的條件得到滿足。例如,如果希望查詢 名 屬性為 john 的所有物件,可以使用 givenname john 這會返回 名 屬性為 john 的所有物件。圓括號是必需的,以便強調 ldap 語句的開始和結束。邏輯與 如果具有多個條件並且希望全部條件都得到...
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...