繁体   English   中英

LDAP查询从Java(employeeID)访问慢响应属性

[英]LDAP Query Accessing a Slow Response Attribute from Java (employeeID)

我目前正在一家公司维护一些图书馆扫描软件,并且正在为(我在读高中)工作。 我必须能够将员工ID值从扫描仪传递到LDAP查找,以返回“ CN”值。

不幸的是,我在Java程序中没有得到任何结果。 我可以使用Windows中的Active Directory程序进行搜索,但是要显示employeeID的任何结果需要6到10秒钟。 我试图通过对查询使用非常大的超时限制来解决此问题,但我认为我必须做错了什么。

有数据库经验的人有什么想法吗?

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

您需要确保对employeeID属性建立索引。

您还应该进一步限定过滤器。 我将至少添加一个objectClass过滤器,设置为您用于人员的任何对象类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM