1

我想从 LDAP 的控制 oid 中获取值:例如,当我使用 Linux ldapsearch 时:

ldapsearch -H ldap://host:port -x -wsecret -D "cn=manager,managedElementId=HSS1"
           -b "dn" "objectClass=ConfigOAM"  -E"1.3.6.1.4.1.637.81.2.10.10"

我得到结果:

...
**control: 1.3.6.1.4.1.637.81.2.10.10 false AgEB**
objectClass: top
objectClass: ConfigOAM
confOAMId: 1
...

我的java代码看起来:

LDAPConnection connection = new LDAPConnection();
connection.connect(hostName, port);
connection.bind(LDAPConnection.LDAP_V3, userDN, password);

String         returnedAttributes[] = {"+", "*"};
boolean        attributeOnly = false;
String         oid;
LDAPSearchResults results = connection.search("", LDAPConnection.SCOPE_BASE, "(objectClass=*)", returnedAttributes, attributeOnly);

                        LDAPEntry entry = results.next();
            System.out.println("\n" + entry.getDN());
            System.out.println("    Attributes: ");
            LDAPAttributeSet attributeSet = entry.getAttributeSet();
            Iterator allAttributes = attributeSet.iterator();

            while(allAttributes.hasNext()) {
                LDAPAttribute attribute = (LDAPAttribute)allAttributes.next();
                String attrName = attribute.getName();
                System.out.println("        " + attrName);
                Enumeration allValues = attribute.getStringValues();

                while(allValues.hasMoreElements()) {

                    oid = (String) allValues.nextElement();
                      if ( (attrName.equalsIgnoreCase("supportedExtension")) || (attrName.equalsIgnoreCase("supportedControl"))) {
                                System.out.println("          " + oid);
                      }
                    }
            }

结果是:

    ...

    supportedControl

      2.16.840.1.113730.3.4.2

      1.2.840.113556.1.4.319

      1.2.826.0.1.3344810.2.3

      1.3.6.1.1.12

      1.3.6.1.4.1.637.81.2.10.11

      **1.3.6.1.4.1.637.81.2.10.10**

      1.3.6.1.4.1.637.81.2.10.9

      1.3.6.1.4.1.637.81.2.10.6

      ...

请建议我或建议我如何在 ldapsearch 中获得附加值“false AgEB”

4

2 回答 2

1

谢谢您的回答 :)

我从本网站上的可用样本和其他资源中制作了类似的东西:

lc.connect( ldapHost, ldapPort );
lc.bind( ldapVersion, loginDN, password.getBytes("UTF8"));

LDAPControl ldapCtrl = new LDAPControl("1.3.6.1.4.1.637.81.2.10.10", false, null);
LDAPSearchConstraints cons = lc.getSearchConstraints();
cons.setControls( ldapCtrl );

lc.setConstraints(cons);

LDAPSearchResults searchResults = lc.search("",LDAPConnection.SCOPE_BASE, "(objectclass=*)", returnedAttributes,attributeOnly  , cons);


LDAPControl[] controls = searchResults.getResponseControls();

但我的“控件”变量始终为空,即使列出了supportedControls

         LDAPEntry entry1 = searchResults.next();
         System.out.println("\n" + entry1.getDN());
         System.out.println("    Attributes: ");
         LDAPAttributeSet attributeSet1 = entry1.getAttributeSet();
         Iterator allAttributes1 = attributeSet1.iterator();

         while(allAttributes1.hasNext()) {
             LDAPAttribute attribute = (LDAPAttribute)allAttributes1.next();
             String attrName = attribute.getName();
             System.out.println("        " + attrName);
             Enumeration allValues1 = attribute.getStringValues();

             while(allValues1.hasMoreElements()) {

                 oid = (String) allValues1.nextElement();
                   if ( (attrName.equalsIgnoreCase("supportedExtension")) || (attrName.equalsIgnoreCase("supportedControl"))) {
                             System.out.println("          " + oid);
                   }
                 }
         }

也许 searchResults 选项是错误的?

于 2013-09-06T10:52:10.483 回答
1

您需要将控件添加到搜索请求并能够解释响应。

有一些可用的示例: http ://www.novell.com/documentation/developer/samplecode/jldap_sample/

-吉姆

于 2013-09-06T10:14:40.390 回答