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
URL: https://issues.apache.org/jira/browse/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 :
{noformat}
/**
* {@inheritDoc}
*/
public BindRequest setName( String name )
{
this.name = name;
try
{
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;
}
{noformat}
which get called in the {{StoreName}} method :
{noformat}
/**
* {@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( "" );
}
else
{
byte[] nameBytes = tlv.getValue().getData();
String nameStr = Strings.utf8ToString( nameBytes );
try
{
// 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";
...
{noformat}
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
(v6.3.4#6332)