You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Emmanuel Lecharny (JIRA)" <ji...@apache.org> on 2016/10/14 15:57:20 UTC
[jira] [Resolved] (DIRAPI-283) We don't need to parse the DN when
storing a name in the LDAP requests
[ https://issues.apache.org/jira/browse/DIRAPI-283?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Emmanuel Lecharny resolved DIRAPI-283.
--------------------------------------
Resolution: Fixed
Fix Version/s: (was: 2.0.0)
1.0.0-RC2
Fixed with http://svn.apache.org/viewvc?rev=1764905&view=rev
> 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: 1.0.0-RC2
>
>
> 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)