簡體   English   中英

從LDAP獲取Manager的電子郵件ID?

[英]getting Manager's email ID from LDAP?

我想獲取一個人的電子郵件ID以及他/她經理的電子郵件ID。 以下是我試過的代碼。

DirContext ctx = new InitialDirContext(LDAPDetails());
String[] attrIDs = {"sAMAccountName", "cn", "title", "mailnickname", "mail", "manager", "department", "telephoneNumber"};
    SearchControls ctls = new SearchControls();
    ctls.setReturningAttributes(attrIDs);
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    String filter = "(CN=285263)";
    NamingEnumeration<SearchResult> answer = ctx.search("OU=users,DC=cts,DC=com", filter , ctls);
    answer = ctx.search("OU=xyz,DC=cts,DC=com", filter , ctls);

   while (answer.hasMore()) {
   SearchResult sr = (SearchResult) retEnum.next();
   Attribute mailAttribute=sr.getAttributes().get("mail");
   System.out.println("Team Member's eMail: "+mailAttribute.get()); //Here I am able to get the person's email.
   Attribute managerAttribute=sr.getAttributes().get("manager"); // this is just getting the manager's CN value. Not the email ID.
   }

有人可以幫我拿到經理的電子郵件ID嗎? 提前致謝。

您必須查找經理以獲取他(他們)的電子郵件地址:

DirContext ctx = new InitialDirContext(LDAPDetails());
String[] attrIDs = { "sAMAccountName", "cn", "title", "mailnickname", "mail", "manager", "department", "telephoneNumber" };
SearchControls ctls = new SearchControls();
ctls.setReturningAttributes(attrIDs);
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String filter = "(CN=285263)";
NamingEnumeration<SearchResult> answer = ctx.search("OU=users,DC=cts,DC=com", filter, ctls);

while (answer.hasMore()) {
    SearchResult sr = (SearchResult) retEnum.next();
    Attribute mailAttribute = sr.getAttributes().get("mail");
    System.out.println("Team Member's eMail: " + mailAttribute.get()); // Here I am able to get the person's email.
    Attribute managerAttribute = sr.getAttributes().get("manager"); // this is just getting the manager's CN value. Not the email ID.

    // now lookup the manger
    NamingEnumeration<SearchResult> managerAnswer = ctx.search(managerAttribute.get(), "", ctls);
    while (answer.hasMore()) {
        SearchResult managerSr = (SearchResult) retEnum.next();
        Attribute mailAttribute = sr.getAttributes().get("mail");
        System.out.println("Managers eMail: " + mailAttribute.get()); 
    }
}

這是我的方法......

1..Connecto到LDAP

2 ..搜索用戶並獲取經理姓名

3 ..在過濾條件中使用管理員名稱和對象類作為用戶搜索LDAP。

NamingEnumeration answermanager = context.search(managerAttribute.get()。toString(),“(objectClass = user)”,searchCtls);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM