directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r674902 - in /directory: apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/ shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/
Date Tue, 08 Jul 2008 17:59:29 GMT
Author: elecharny
Date: Tue Jul  8 10:59:28 2008
New Revision: 674902

URL: http://svn.apache.org/viewvc?rev=674902&view=rev
Log:
Modifying the way DN are parsed to accept escaped chars like # into a value. 
Fixed DIRSERVER-1192

Modified:
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
    directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
Tue Jul  8 10:59:28 2008
@@ -502,11 +502,9 @@
         Attributes attributes = this.getPersonAttributes( snVal, cnVal );
         ctx.createSubcontext( oldRdn, attributes );
 
-        // modify Rdn from cn=Tori Amos to cn=<A Umlaut>\+
-        String newCnVal = new String( new byte[]
-            { ( byte ) 0xC3, ( byte ) 0x84, '+' }, "UTF-8" );
+        // modify Rdn from cn=Tori Amos to cn=<a Umlaut>\+
         String newCnEscapedVal = new String( new byte[]
-            { ( byte ) 0xC3, ( byte ) 0x84, '\\', '+' }, "UTF-8" );
+            { ( byte ) 0xC3, ( byte ) 0xA4, '\\', '+' }, "UTF-8" );
         ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
         String newRdn = "cn=" + newCnEscapedVal;
         ctx.rename( oldRdn, newRdn );
@@ -532,7 +530,7 @@
         // Check that cn contains the unescaped value
         Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
         assertEquals( "Number of cn occurences", 1, cn.size() );
-        assertTrue( cn.contains( newCnVal ) );
+        assertTrue( cn.contains( "\\C3\\A4\\+" ) );
 
         // Remove entry (use new rdn)
         ctx.unbind( newRdn );

Modified: directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/SearchITest.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
(original)
+++ directory/apacheds/trunk/server-unit/src/test/java/org/apache/directory/server/SearchITest.java
Tue Jul  8 10:59:28 2008
@@ -427,6 +427,7 @@
         assertFalse( results.hasMore() );
     }
     
+    
     /**
      * Search operation with a base DN with quotes
      *

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/AttributeTypeAndValue.java
Tue Jul  8 10:59:28 2008
@@ -28,6 +28,7 @@
 
 import javax.naming.InvalidNameException;
 
+import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/LdapDN.java
Tue Jul  8 10:59:28 2008
@@ -1478,21 +1478,20 @@
     /**
      * This private method is used to normalize the value, when we have found a normalizer.
      * 
-     * @param rdn 
-     * @param oidNormalizer 
-     * @param type 
+     * @param rdn the RDN we want to normalize. It will contain the resulting normalized
RDN
+     * @param oidNormalizer the normalizer to use for the RDN
      * @throws NamingException If something went wrong.
      */
-    public static void oidNormalize( Rdn rdn, OidNormalizer oidNormalizer, String type )
throws NamingException
+    public static void oidNormalize( Rdn rdn, OidNormalizer oidNormalizer ) throws NamingException
     {
         Object upValue = rdn.getUpValue();
         String upType = rdn.getUpType();
+        //String normalizedValue = rdn.getNormValue();
         rdn.clear();
-        Object normValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
-
-        rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue,

-                oidNormalizer.getNormalizer().normalize( normValue ) );
+        Object normStringValue = DefaultStringNormalizer.normalizeString( (String)upValue
);
+        Object normValue = oidNormalizer.getNormalizer().normalize( normStringValue );
 
+        rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue,
normValue );
     }
 
     /**
@@ -1537,7 +1536,7 @@
 
                     if ( oidNormalizer != null )
                     {
-                        oidNormalize( rdn, oidNormalizer, type );
+                        oidNormalize( rdn, oidNormalizer );
                     }
                     else
                     {
@@ -1550,7 +1549,7 @@
                             if ( oidNormalizer != null )
                             {
                                 // Ok, just normalize after having removed the 4 first chars
-                                oidNormalize( rdn, oidNormalizer, type );
+                                oidNormalize( rdn, oidNormalizer );
                             }
                             else
                             {

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
Tue Jul  8 10:59:28 2008
@@ -875,6 +875,7 @@
        }
    }
 
+
    /**
     * Return the normalized type, or the first one of we have more than one (the lowest)
     *
@@ -895,6 +896,28 @@
        }
    }
 
+   
+   /**
+    * Return the normalized value, or the first one of we have more than one (the lowest)
+    *
+    * @return The first normalized value of this RDN
+    */
+   public String getNormValue()
+   {
+       switch ( nbAtavs )
+       {
+           case 0:
+               return null;
+
+           case 1:
+               return (String)atav.getNormValue();
+
+           default:
+               return ((TreeSet<AttributeTypeAndValue>)atavs).first().getNormalizedValue();
+       }
+   }
+
+
    /**
     * Return the value, or the first one of we have more than one (the lowest)
     *

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/name/RdnParser.java
Tue Jul  8 10:59:28 2008
@@ -417,7 +417,6 @@
         else if ( c == '"' )
         {
             pos.start++;
-            pos.length = 0;
             pos.end = pos.start;
             int nbBytes = 0;
             int length = 0;
@@ -473,6 +472,7 @@
             if ( StringTools.isCharASCII( bytes, pos.end, '"' ) )
             {
                 pos.end++;
+                pos.length = length + 2;
                 return StringTools.utf8ToString( buffer, length );
                 //return StringTools.utf8ToString( bytes, pos.start, pos.length );
             }
@@ -969,13 +969,17 @@
         StringTools.trimLeft( dn, pos );
 
         pos.end = pos.start;
+        
+        int start2 = pos.start;
 
         if ( ( value = parseAttributeValue( dn, pos ) ) == null )
         {
             return DNUtils.PARSING_ERROR;
         }
 
-        rdn.addAttributeTypeAndValue( type, type, value, value );
+        String upValue = StringTools.utf8ToString( dn, start2, pos.length );
+        rdn.addAttributeTypeAndValue( type, type, upValue, value );
+
         rdn.normalize();
 
         pos.start = pos.end;

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/DNUtils.java
Tue Jul  8 10:59:28 2008
@@ -279,8 +279,21 @@
 
 
     /**
-     * Check if the current character is a Pair Char &lt;pairchar&gt; ::= ',' | '='
|
-     * '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
+     * Check if the given char is a pair char only
+     * &lt;pairCharOnly&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';'
| '\' | '"'
+     *
+     * @param c the char we want to test
+     * @return true if the char is a pair char only
+     */
+    public static boolean isPairCharOnly( char c )
+    {
+        return ( ( ( c | 0x7F ) == 0x7F ) && PAIR_CHAR_ONLY[c & 0x7f] );
+    }
+
+
+    /**
+     * Check if the current character is a Pair Char 
+     * &lt;pairchar&gt; ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' |
'\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
      * 
      * @param bytes The buffer which contains the data
      * @param index Current position in the buffer

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=674902&r1=674901&r2=674902&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Tue Jul  8 10:59:28 2008
@@ -3387,11 +3387,14 @@
         // create buffer and add everything before start of scan
         StringBuffer buf = new StringBuffer();
         ByteBuffer bb = new ByteBuffer();
+        boolean escaped = false;
         
         // start scaning until we find an escaped series of bytes
         for ( int ii = 0; ii < length; ii++ )
         {
-            if ( str.charAt( ii ) == '\\' )
+            char c = str.charAt( ii );
+            
+            if ( c == '\\' )
             {
                 // we have the start of a hex escape sequence
                 if ( isHex( str, ii+1 ) && isHex ( str, ii+2 ) )
@@ -3400,18 +3403,45 @@
                     int advancedBy = collectEscapedHexBytes( bb, str, ii );
                     ii+=advancedBy-1;
                     buf.append( StringTools.utf8ToString( bb.buffer(), bb.position() ) );
+                    escaped = false;
                     continue;
                 }
-                else
+                else if ( !escaped )
                 {
-                    buf.append( str.charAt( ii ) );
+                    // It may be an escaped char ( ' ', '"', '#', '+', ',', ';', '<',
'=', '>', '\' )
+                    escaped = true;
                     continue;
                 }
             }
 
-            buf.append( str.charAt( ii ) );
+            
+            if ( escaped )
+            {
+                if ( DNUtils.isPairCharOnly( c ) )
+                {
+                    // It is an escaped char ( ' ', '"', '#', '+', ',', ';', '<', '=',
'>', '\' )
+                    // Stores it into the buffer without the '\'
+                    escaped = false;
+                    buf.append( c );
+                    continue;
+                }
+                else
+                {
+                    throw new InvalidNameException( "The DN must contain valid escaped characters."
);
+                }
+            }
+            else
+            {
+                buf.append( str.charAt( ii ) );
+            }
         }
-        
+
+        if ( escaped )
+        {
+            // We should not have a '\' at the end of the string
+            throw new InvalidNameException( "The DN must not ends with a '\\'." );
+        }
+
         return buf.toString();
     }
 



Mime
View raw message