[英]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.