2

Active Directory の jsp/servlet に検索フィルタを作成しました。実際には、Active Directory からユーザー プロファイルを検索したいと考えています。

これが私のサーブレットコードです(サーブレットの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 Filtersimsys.com ドメインから任意のオブジェクトを検索するための提案。

4

0 に答える 0