搜索过滤器异常发生在Active Directory中

时间:2012-09-17 07:20:27

标签: java exception active-directory

我在jsp / servlet中为Active Directory创建了一个搜索过滤器。实际上我想从我的Active Directory中搜索用户配置文件:

这是我的Servlet代码(在Servlet的dopost中并使用netscape api):

        int port=0;
        String hostname=request.getParameter("hostname");

        String authenticationId = request.getParameter("authId");
        String authenticationPassword = request.getParameter("authPass");
        String distinguishedName = request.getParameter("dn");

        String searchFilter = request.getParameter("searchFilter");
        String[] attributes = request.getParameterValues("attribute");
        String sn = null,cn=null,mail=null,telephone=null;

        LDAPConnection ldi=new LDAPConnection();

        try {
//          scopeOfSearch = Integer.parseInt(request.getParameter("scope"));
            port = Integer.parseInt(request.getParameter("port"));
            System.out.println("Wait... Identifying the Active Directory / LDAP server.");
            ldi.connect(hostname,port,authenticationId,authenticationPassword);
            System.out.println("LDAP Server "+ hostname +" is connected on port " +port);
            LDAPConnectionInfo.ldapSearchResults = ldi.search(distinguishedName, LDAPConnectionInfo.MY_SCOPE, searchFilter, attributes, false);
            System.out.println("LDAP Search function working.......");


            while (LDAPConnectionInfo.ldapSearchResults.hasMoreElements()) {
                LDAPConnectionInfo.ldapEntry = (LDAPEntry) LDAPConnectionInfo.ldapSearchResults.nextElement();

                try {

                    LDAPConnectionInfo.ldapEntry= LDAPConnectionInfo.ldapSearchResults.next();
                    } 
                catch (LDAPReferralException e) {
                    // TODO: handle exception
                        System.out.println("Search reference: ");
                        LDAPUrl refUrls[]=e.getURLs();
                        for(int i=0;i < refUrls.length; i++){
                            System.out.println("\t" +refUrls[i].getUrl());
                        }
                        continue;
                }
                catch (LDAPException e) {
                    System.out.println("Error: " + e.toString());
                    continue;

            }
                LDAPConnectionInfo.ldapAttributeSet = LDAPConnectionInfo.ldapEntry.getAttributeSet();
                LDAPConnectionInfo.enumAttribute = LDAPConnectionInfo.ldapAttributeSet.getAttributes();

                /* While loop starts get Attribute of Entry */
                while (LDAPConnectionInfo.enumAttribute.hasMoreElements()) {
                    LDAPConnectionInfo.ldapAttribute = (LDAPAttribute) LDAPConnectionInfo.enumAttribute.nextElement();

                    String attributeName = LDAPConnectionInfo.ldapAttribute.getName();
                    if(attributeName.equals("cn")){
                        System.out.println("Full Name : "+cn);
                        request.setAttribute(cn, attributeName.getBytes(cn));
                    }
                    else if (attributeName.equals("sn")) {
                    System.out.println("Surname : ");
                    request.setAttribute(sn, attributeName.getBytes("sn"));
                    }
                    else if (attributeName.equals("mail")) {
                    System.out.println("Email : "); 
                    request.setAttribute(mail, attributeName.getBytes("mail"));
                    }
                    else if (attributeName.equals("telephoneNumber : ")) {
                    System.out.println("Telephone Number : ");  
                    request.setAttribute(telephone, attributeName.getBytes("telephoneNumber"));
                    }

                    Enumeration enumvalues= LDAPConnectionInfo.ldapAttribute.getStringValues();
                    if(enumvalues!=null){
                        while (enumvalues.hasMoreElements()) {
                            String aVal = (String) enumvalues.nextElement();
                            System.out.println("\t" +aVal);

                        }
                    }

                }

            }
            ldi.disconnect();
        }

            catch (NumberFormatException e) {
                // TODO: handle exception
                System.out.println("Error is : "+e.toString());
            }
            catch (LDAPException e) {
                // TODO: handle exception
                System.out.println("Error : "+e.toString());
            }

        getServletContext().getRequestDispatcher("/jsp/searchLDAPResult.jsp").forward(request , response);
        }

我正在获取 例外 ,例如: Error : netscape.ldap.LDAPException: error result (1); 000004DC: LdapErr: DSID-0C0906DD, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1771

我的Search Filter有任何关于从simsys.com域搜索任何对象的建议。

0 个答案:

没有答案