How to get "supportedControl" from LDAP with com.novell.ldap

776 views Asked by At

I want to get value from control oid from LDAP: For example when I use 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"

I get results:

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

My java code looks:

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

and the result is:

    ...

    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

      ...

Please suggest me or advice how can I get the additional value "false AgEB" in java as I get it in ldapsearch?

2

There are 2 answers

0
jwilleke On

You would need to add the control to the search request and be able to interpret the response.

There are soem examples available: http://www.novell.com/documentation/developer/samplecode/jldap_sample/

-jim

0
elpasso On

Thank you for your answer :)

I made something like this from samples available on this site and from others soruces:

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

but my "controls" varaible is always null, even if supportedControls are listed

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

Maybe the searchResults options are wrong?