【问题标题】:How to get "supportedControl" from LDAP with com.novell.ldap如何使用 com.novell.ldap 从 LDAP 获取“supportedControl”
【发布时间】:2013-09-05 17:09:36
【问题描述】:

我想从 LDAP 的 control 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"

【问题讨论】:

    标签: java ldap novell


    【解决方案1】:

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

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

    -吉姆

    【讨论】:

      【解决方案2】:

      谢谢你的回答:)

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

      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();
      

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

               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 选项有误?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多