Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C9CFB2009EE for ; Wed, 18 May 2016 11:03:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C8770160A00; Wed, 18 May 2016 09:03:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2980B160A1B for ; Wed, 18 May 2016 11:03:14 +0200 (CEST) Received: (qmail 28078 invoked by uid 500); 18 May 2016 09:03:13 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 27923 invoked by uid 99); 18 May 2016 09:03:13 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 May 2016 09:03:13 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id E2B892C1F61 for ; Wed, 18 May 2016 09:03:12 +0000 (UTC) Date: Wed, 18 May 2016 09:03:12 +0000 (UTC) From: "Emmanuel Lecharny (JIRA)" To: dev@directory.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (DIRAPI-283) We don't need to parse the DN when storing a name in the LDAP requests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Wed, 18 May 2016 09:03:15 -0000 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 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)