directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <>
Subject [jira] [Created] (DIRAPI-283) We don't need to parse the DN when storing a name in the LDAP requests
Date Wed, 18 May 2016 09:03:12 GMT
Emmanuel Lecharny created DIRAPI-283:

             Summary: We don't need to parse the DN when storing a name in the LDAP requests
                 Key: DIRAPI-283
             Project: Directory Client API
          Issue Type: Improvement
    Affects Versions: 1.0.0-M33
            Reporter: Emmanuel Lecharny
             Fix For: 2.0.0

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 )
    { = 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
        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.

This message was sent by Atlassian JIRA

View raw message