Uploaded image for project: 'Directory Client API'
  1. Directory Client API
  2. DIRAPI-283

We don't need to parse the DN when storing a name in the LDAP requests



    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.0.0-M33
    • 1.0.0-RC2
    • None


      When we store a name in a LDAP request, we usually parse it to see if it's a valid DN. For instance, in the BindRequestImpl class :

           * {@inheritDoc}
          public BindRequest setName( String name )
              this.name = name;
                  this.dn = new Dn( name );
              catch ( LdapInvalidDnException e )
                  // This might still be a valid DN (Windows AD binding for instance)
                  LOG.debug( "Unable to convert the name to a DN." );
                  this.dn = null;
              return this;

      which get called in the StoreName method :

           * {@inheritDoc}
          public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
              BindRequest bindRequestMessage = container.getMessage();
              // Get the Value and store it in the BindRequest
              TLV tlv = container.getCurrentTLV();
              // We have to handle the special case of a 0 length name
              if ( tlv.getLength() == 0 )
                  bindRequestMessage.setName( "" );
                  byte[] nameBytes = tlv.getValue().getData();
                  String nameStr = Strings.utf8ToString( nameBytes );
                      // Testing the name as a DN
                      new Dn( nameStr );
                      bindRequestMessage.setName( nameStr );
                  catch ( LdapInvalidDnException ine )
                      String msg = "Incorrect DN given : " + nameStr + " (" + Strings.dumpBytes( nameBytes )
                          + ") is invalid";

      As we can see, we first try to parse the DN, then we call the setName method with the String, and this method will parse the DN again...

      Even worse : on the server, we need a schema aware version of the DN, which means we process the {(DN}} again to apply the SchemaManager on it.

      That is clearly a waste of CPU : it's for the server to check the DN, this is not the decoder role.

      For all the other request, we are checking if the DN is valid, which is already overdoing, but at least, we don't parse the DN twice.




            Unassigned Unassigned
            elecharny Emmanuel L├ęcharny
            0 Vote for this issue
            1 Start watching this issue