directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r528011 - /directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Date Thu, 12 Apr 2007 16:28:11 GMT
Author: elecharny
Date: Thu Apr 12 09:28:10 2007
New Revision: 528011

URL: http://svn.apache.org/viewvc?view=rev&rev=528011
Log:
Added the SyntaxCeck pass into the check method, so that Added and Modified attributes are
controled before being injected

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=528011&r1=528010&r2=528011
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Thu Apr 12 09:28:10 2007
@@ -88,8 +88,10 @@
 import org.apache.directory.shared.ldap.schema.SchemaUtils;
 import org.apache.directory.shared.ldap.schema.Syntax;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
 import org.apache.directory.shared.ldap.schema.syntax.NormalizerDescription;
+import org.apache.directory.shared.ldap.schema.syntax.SyntaxChecker;
 import org.apache.directory.shared.ldap.schema.syntax.SyntaxCheckerDescription;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.EmptyEnumeration;
@@ -1807,6 +1809,8 @@
 
     /**
      * Check that all the attributes exist in the schema for this entry.
+     * 
+     * We also check the syntaxes
      */
     private void check( LdapDN dn, Attributes entry ) throws NamingException
     {
@@ -1853,6 +1857,9 @@
 
         // Check the attributes values and transform them to String if necessary
         assertHumanReadible( entry );
+        
+        // Now check the syntaxes
+        assertSyntaxes( entry );
     }
 
     /**
@@ -1986,6 +1993,50 @@
     
 
     /**
+     * Check the entry attributes syntax, using the syntaxCheckers
+     */
+    private void assertSyntaxes( Attributes entry ) throws NamingException
+    {
+        NamingEnumeration attributes = entry.getAll();
+
+        // First, loop on all attributes
+        while ( attributes.hasMoreElements() )
+        {
+            Attribute attribute = ( Attribute ) attributes.nextElement();
+
+            AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( attribute.getID()
);
+            SyntaxChecker syntaxChecker =  attributeType.getSyntax().getSyntaxChecker();
+            
+            if ( syntaxChecker instanceof AcceptAllSyntaxChecker )
+            {
+                // This is a speedup : no need to check the syntax of any value
+                // if all the sytanxes are accepted...
+                continue;
+            }
+            
+            NamingEnumeration<?> values = attribute.getAll();
+
+            // Then loop on all values
+            while ( values.hasMoreElements() )
+            {
+                Object value = values.nextElement();
+                
+                try
+                {
+                    syntaxChecker.assertSyntax( value );
+                }
+                catch ( NamingException ne )
+                {
+                    log.error( "Attribute value '{}' for attribute '{}' is synatxically incorrect",

+                        (value instanceof String ? value : StringTools.dumpBytes( (byte[])value
) ), 
+                        attribute.getID());
+                    throw ne;
+                }
+            }
+        }
+    }
+    
+    /**
      * Check that all the attribute's values which are Human Readible can be transformed
      * to valid String if they are stored as byte[].
      */
@@ -2002,7 +2053,7 @@
 
             AttributeType attributeType = registries.getAttributeTypeRegistry().lookup( attribute.getID()
);
 
-            // If the attributeType is H-R, check alll of its values
+            // If the attributeType is H-R, check all of its values
             if ( attributeType.getSyntax().isHumanReadible() )
             {
                 Enumeration values = attribute.getAll();



Mime
View raw message