[英]LDAP Query Accessing a Slow Response Attribute from Java (employeeID)
I am currently maintaining some library scanning software at a company, and I am at a coop for (I am in high school). 我目前正在一家公司维护一些图书馆扫描软件,并且正在为(我在读高中)工作。 I have to be able to pass an employeeID value from the scanner to the LDAP lookup to return a "CN" value. 我必须能够将员工ID值从扫描仪传递到LDAP查找,以返回“ CN”值。
Unfortunately, I am not getting any results returned in the Java program. 不幸的是,我在Java程序中没有得到任何结果。 I am able to search using the Active Directory program in Windows, but it takes 6 to 10 seconds to display any results from employeeID. 我可以使用Windows中的Active Directory程序进行搜索,但是要显示employeeID的任何结果需要6到10秒钟。 I attempted to solve this issue by using a very large timeout limit on the query, but I think I must be doing something wrong. 我试图通过对查询使用非常大的超时限制来解决此问题,但我认为我必须做错了什么。
Anyone with database experience have any ideas? 有数据库经验的人有什么想法吗?
try
{
System.out.println("Début du test Active Directory");
Hashtable<String, String> env = new Hashtable<String, String>(11);
env.put(INSERT CREDENTIALS HERE);
env.put("com.sun.jndi.ldap.timeout", "80000");
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_PROTOCOL, "simple");
ldapContext = new InitialDirContext(env);
// Create the search controls
SearchControls searchCtls = new SearchControls();
//Specify the attributes to return
String returnedAtts[]={"cn","givenName", "samAccountName"};
searchCtls.setReturningAttributes(returnedAtts);
//Specify the search scope
searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);
//specify the LDAP search filter
id = "********";
String searchFilter = "(&(employeeID="+id+"))";
//Specify the Base for the search
String searchBase = "dc=ericsson,dc=se";
//initialize counter to total the results
SearchResult sr = null;
int totalResults = 0;
NamingEnumeration<SearchResult> answer = ldapContext.search(searchBase, searchFilter, searchCtls);
// Search for objects using the filter
while (totalResults == 0){
answer = ldapContext.search(searchBase, searchFilter, searchCtls);
System.out.println("Total results: " + totalResults);
while (answer.hasMoreElements())
{
sr = answer.next();
System.out.println(sr);
totalResults++;
System.out.println(">>>" + sr.getName());
Attributes attrs = sr.getAttributes();
cn = (">>>>>>>>>" + attrs.get("cn"));
signum = cn.substring(13,20);
System.out.println("Total results: " + totalResults);
}
}
//Loop through the search results
You need to ensure that the employeeID
attribute is indexed. 您需要确保对employeeID
属性建立索引。
You should also qualify your filter further. 您还应该进一步限定过滤器。 I would add at least an objectClass
filter, set to whatever object class you're using for people. 我将至少添加一个objectClass
过滤器,设置为您用于人员的任何对象类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.