Announcement Announcement Module
Collapse
No announcement yet.
Null response controls with dereference control implementation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Null response controls with dereference control implementation

    Hello everyone!

    I am trying to implement the dereference control with spring-ldap. The problem is that although the control is passed to the server correctly and is properly processed (as I can see in the server logs), I always get null response controls.
    The dereference control is working correctly for sure, because it has been tested successfully with the ldapsearch tool. Furthermore, the log entry for the same search operation through ldapsearch and through my implementation is exactly the same.

    framework: spring-ldap 1.3.1
    server: openldap 2.4.28
    deref control rfc: http://tools.ietf.org/html/draft-masarati-ldap-deref-00
    Also, I should note that my implementation is based on the implementation of the same control in the ldapsearch tool.

    RequestControl.java source:
    Code:
    package derefTest;
    
    import org.springframework.ldap.control.AbstractRequestControlDirContextProcessor;
    import javax.naming.ldap.Control;
    import javax.naming.ldap.LdapContext;
    import javax.naming.directory.DirContext;
    import javax.naming.NamingException;
    
    public class RequestControl
    extends AbstractRequestControlDirContextProcessor
    {
        private static final boolean critical = false;
        private static final String[] attrs={"cn","ou"};
        private static final String derefAttr="derefDN";
    
        @Override
        public Control createRequestControl()
        {
            return new DerefControl(attrs,derefAttr,critical);
        }
    
        @Override
        public void postProcess(DirContext ctx)
        throws NamingException
        {
            LdapContext ldapContext;
    
            if (ctx instanceof LdapContext)
            {
                ldapContext = (LdapContext) ctx;
            }
            else
            {
                throw new IllegalArgumentException("Request Control operations require LDAPv3 - " +
                                                   "Context must be of type LdapContext");
            }
    
            Control[] responseControls = ldapContext.getResponseControls();
    
            if( responseControls != null )
            {
                for (int i = 0; i < responseControls.length; i++)
                {
                    if (responseControls[i] instanceof DerefRespControl)
                    {
                         //do something with it (decode it etc)
                    }
                }
            }
            else
            {
                System.out.println("No response controls sent!");
            }
        }
    
        @Override
        public void preProcess(DirContext ctx)
        throws NamingException
        {
            LdapContext ldapContext;
    
            if (ctx instanceof LdapContext)
            {
                ldapContext = (LdapContext) ctx;
            }
            else
            {
                throw new IllegalArgumentException("Request Control operations require LDAPv3 - " +
                                                   "Context must be of type LdapContext");
            }
    
            Control[] requestControls = ldapContext.getRequestControls();
            Control newControl = createRequestControl();
            Control[] newControls = new Control[requestControls.length + 1];
    
            for (int i = 0; i < requestControls.length; i++)
            {
                newControls[i] = requestControls[i];
            }
    
            newControls[requestControls.length]=newControl;
            ldapContext.setRequestControls(newControls);
        }
    }
    DerefControl.java source:
    Code:
    package derefTest;
    
    import javax.naming.ldap.Control;
    import com.sun.jndi.ldap.Ber;
    import com.sun.jndi.ldap.BerDecoder;
    import com.sun.jndi.ldap.BerEncoder;
    
    public class DerefControl implements Control
    {
    
        public static final String OID = "1.3.6.1.4.1.4203.666.5.16";
        private final boolean critical;
        private String[] attrs;
        private String derefAttr;
        private byte[] berVal;
    
        public DerefControl()
        {
            this(null,null,Control.NONCRITICAL);
        }
    
        public DerefControl(String[] attrs, String derefAttr, boolean critical)
        {
            this.critical = critical;
            this.attrs = attrs;
            this.derefAttr = derefAttr;
    
            BerEncoder ber = new BerEncoder(1);
            ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
            try
            {
                ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
                ber.encodeString(derefAttr, Ber.ASN_SIMPLE_STRING , true);
                ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
                for(int i=0;i<attrs.length;i++)
                {
                    ber.encodeString(attrs[i], Ber.ASN_SIMPLE_STRING, true);
                }
                ber.endSeq();
                ber.endSeq();
                ber.endSeq();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
            this.berVal=ber.getBuf();
        }
    
        @Override
        public byte[] getEncodedValue()
        {
            return berVal;
        }
    
        @Override
        public String getID() {
            return OID;
        }
    
        @Override
        public boolean isCritical() {
            return critical;
        }
    
        public String getDerefAttr()
        {
            return this.derefAttr;
        }
    
        public String[] getAttrs()
        {
            return this.attrs;
        }
    }
    In case that more info is needed, ask!
    Thanks in advance!

  • #2
    bump? (10chars)

    Comment

    Working...
    X