directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r497684 - in /directory/branches/apacheds/1.0: core-unit/src/test/java/org/apache/directory/server/core/jndi/ core/src/main/java/org/apache/directory/server/core/schema/
Date Fri, 19 Jan 2007 02:13:23 GMT
Author: elecharny
Date: Thu Jan 18 18:13:22 2007
New Revision: 497684

URL: http://svn.apache.org/viewvc?view=rev&rev=497684
Log:
WORK IN PROGRESS svn status! Fixed a lot of errors in integration tests. Modified the way
schema is checked. svn status! WORK IN PROGRESS

Modified:
    directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
    directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchContextITest.java
    directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java?view=diff&rev=497684&r1=497683&r2=497684
==============================================================================
--- directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
(original)
+++ directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/ReferralITest.java
Thu Jan 18 18:13:22 2007
@@ -190,7 +190,7 @@
     {
         assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/cn=alex karasulu,ou=apache,ou=users,dc=example,dc=com",
e.getReferralInfo() );
+        assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com",
e.getReferralInfo() );
         assertTrue( e.skipReferral() );
         assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
         assertFalse( e.skipReferral() );
@@ -201,7 +201,7 @@
     {
         assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
-        assertEquals( "ldap://hertz:10389/cn=alex karasulu,ou=users,dc=example,dc=com", e.getReferralInfo()
);
+        assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com",
e.getReferralInfo() );
         assertTrue( e.skipReferral() );
         assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
         assertFalse( e.skipReferral() );
@@ -828,6 +828,7 @@
         LdapContext userCtx = null;
         Attributes referral = new AttributesImpl( "objectClass", "top", true );
         referral.get( "objectClass" ).add( "person" );
+        referral.get( "objectClass" ).add( "organizationalUnit" );
         referral.put( "cn", "akarasulu" );
         referral.put( "sn", "karasulu" );
 

Modified: directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchContextITest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchContextITest.java?view=diff&rev=497684&r1=497683&r2=497684
==============================================================================
--- directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchContextITest.java
(original)
+++ directory/branches/apacheds/1.0/core-unit/src/test/java/org/apache/directory/server/core/jndi/SearchContextITest.java
Thu Jan 18 18:13:22 2007
@@ -574,6 +574,9 @@
         
         // First let's add a some binary data representing a userCertificate
         Attributes attrs = getPersonAttributes( "Bush", "Kate Bush" );
+        Attribute objectClasses = attrs.get( "objectClass" );
+        objectClasses.add( "strongAuthenticationUser" );
+
         attrs.put( "userCertificate", certData );
         sysRoot.createSubcontext( "cn=Kate Bush", attrs );
         

Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?view=diff&rev=497684&r1=497683&r2=497684
==============================================================================
--- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
(original)
+++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
Thu Jan 18 18:13:22 2007
@@ -577,7 +577,119 @@
                 throw new InternalError( "" );
         }
     }
+    
+    private boolean getObjectClasses( Attribute objectClasses, List result ) throws NamingException
+    {
+        Set ocSeen = new HashSet();
+        ObjectClassRegistry registry = globalRegistries.getObjectClassRegistry();
+        
+        // We must select all the ObjectClasses, except 'top',
+        // but including all the inherited ObjectClasses
+        NamingEnumeration ocs = objectClasses.getAll();
+        boolean hasExtensibleObject = false;
+
+        
+        while ( ocs.hasMoreElements() )
+        {
+            String objectClassName = (String)ocs.nextElement();
+
+            if ( "top".equals( objectClassName ) )
+            {
+                continue;
+            }
+            
+            if ( "extensibleObject".equalsIgnoreCase( objectClassName ) )
+            {
+                hasExtensibleObject = true;
+            }
+            
+            ObjectClass oc = registry.lookup( objectClassName );
+            
+            // Add all unseen objectclasses to the list, except 'top'
+            if ( !ocSeen.contains( oc.getOid() ) )
+            {
+                ocSeen.add( oc.getOid() );
+                result.add( oc );
+            }
+            
+            // Loop on all the current OC parents
+            ObjectClass[] superiors = oc.getSuperClasses();
+            
+            for ( int i = 0; i < superiors.length; i++ )
+            {
+                ObjectClass parent = superiors[i];
+                
+                // Skip 'top'
+                if ( "top".equals( parent.getName() ) )
+                {
+                    continue;
+                }
+                
+                if ( !ocSeen.contains( parent.getOid() ) )
+                {
+                    ocSeen.add( parent.getOid() );
+                    result.add( parent );
+                }
+            }
+        }
+        
+        return hasExtensibleObject;
+    }
+
+    private Set getAllMust( List objectClasses ) throws NamingException
+    {
+        Set must = new HashSet();
+        
+        // Loop on all objectclasses
+        for ( int i = 0; i < objectClasses.size(); i++ )
+        {
+            ObjectClass oc = (ObjectClass)objectClasses.get( i );
+            
+            AttributeType[] types = oc.getMustList();
+            
+            // For each objectClass, loop on all MUST attributeTypes, if any
+            if ( ( types != null ) && ( types.length > 0 ) )
+            {
+                for ( int j = 0; j < types.length; j++ )
+                {
+                    String oid = types[j].getOid();
+                    
+                    must.add( oid );
+                }
+            }
+        }
+        
+        return must;
+    }
 
+    private Set getAllAllowed( List objectClasses, Set must ) throws NamingException
+    {
+        Set allowed = new HashSet( must );
+        
+        // Add the 'ObjectClass' attribute ID
+        allowed.add( globalRegistries.getOidRegistry().getOid( "ObjectClass" ) );
+        
+        // Loop on all objectclasses
+        for ( int i = 0; i < objectClasses.size(); i++ )
+        {
+            ObjectClass oc = (ObjectClass)objectClasses.get( i );
+            
+            AttributeType[] types = oc.getMayList();
+            
+            // For each objectClass, loop on all MUST attributeTypes, if any
+            if ( ( types != null ) && ( types.length > 0 ) )
+            {
+                for ( int j = 0; j < types.length; j++ )
+                {
+                    String oid = types[j].getOid();
+                    
+                    allowed.add( oid );
+                }
+            }
+        }
+        
+        return allowed;
+    }
 
     /**
      * Given the objectClasses for an entry, this method adds missing ancestors 
@@ -1176,10 +1288,29 @@
             }
         }
 
-        alterObjectClasses( attrs.get( "objectClass" ), this.globalRegistries.getObjectClassRegistry()
);
-        assertRequiredAttributesPresent( attrs );
+        // We will check some elements :
+        // 1) the entry must have all the MUST attributes of all its ObjectClass
+        // 2) The SingleValued attributes must be SingleValued
+        // 3) No attributes should be used if they are not part of MUST and MAY
+        // 3-1) Except if the extensibleObject ObjectClass is used
+        // 3-2) or if the AttributeType is COLLECTIVE
+        //
+        // First, create the Set of all Must and May attributes
+        Attribute objectClassAttr = attrs.get( "objectClass" );
+        List ocs = new ArrayList();
+        boolean hasExtensibleObject = getObjectClasses( objectClassAttr, ocs );
+        Set must = getAllMust( ocs );
+        Set allowed = getAllAllowed( ocs, must );
+        
+        //alterObjectClasses( attrs.get( "objectClass" ), this.globalRegistries.getObjectClassRegistry()
);
+        assertRequiredAttributesPresent( attrs, must );
         assertNumberOfAttributeValuesValid( attrs );
-        assertAllAttributesAllowed( attrs );
+
+        if ( !hasExtensibleObject )
+        {
+            assertAllAttributesAllowed( attrs, allowed );
+        }
+        
         next.add(normName, attrs );
     }
     
@@ -1215,30 +1346,25 @@
     /**
      * Checks to see the presence of all required attributes within an entry.
      */
-    private void assertRequiredAttributesPresent( Attributes entry ) 
+    private void assertRequiredAttributesPresent( Attributes entry, Set must ) 
         throws NamingException
     {
-        AttributeType[] required = getRequiredAttributes( entry.get( "objectClass" ), 
-            this.globalRegistries.getObjectClassRegistry() );
-        for ( int ii = 0; ii < required.length; ii++ )
+        NamingEnumeration attributes = entry.getAll();
+        
+        while ( attributes.hasMoreElements() )
         {
-            boolean aliasFound = false;
-            String[] aliases = required[ii].getNames();
-            for ( int jj = 0; jj < aliases.length; jj++ )
-            {
-                if ( entry.get( aliases[jj] ) != null )
-                {
-                    aliasFound = true;
-                    break;
-                }
-            }
+            Attribute attribute = (Attribute)attributes.nextElement();
             
-            if ( ! aliasFound )
-            {
-                throw new LdapSchemaViolationException( "Required attribute " + 
-                    required[ii].getName() + " not found within entry.", 
-                    ResultCodeEnum.OBJECTCLASSVIOLATION );
-            }
+            String oid = globalRegistries.getOidRegistry().getOid( attribute.getID() );
+            
+            must.remove( oid );
+        }
+        
+        if ( must.size() != 0 )
+        {
+            throw new LdapSchemaViolationException( "Required attributes " + 
+                must.toArray() + " not found within entry.", 
+                ResultCodeEnum.OBJECTCLASSVIOLATION );
         }
     }
     
@@ -1251,7 +1377,7 @@
      * @return true if the objectClass values require the attribute, false otherwise
      * @throws NamingException if the attribute is not recognized
      */
-    private void assertAllAttributesAllowed( Attributes attributes ) throws NamingException
+    private void assertAllAttributesAllowed( Attributes attributes, Set allowed ) throws
NamingException
     {
         // Never check the attributes if the extensibleObject objectClass is
         // declared for this entry
@@ -1262,13 +1388,6 @@
             return;
         }
         
-        Set allowed = getAllowedAttributes( attributes.get( "objectClass" ), 
-            globalRegistries.getObjectClassRegistry() );
-
-        // Add the 'ObjectClass' attribute ID
-        allowed.add( globalRegistries.getOidRegistry().getOid( "ObjectClass" ) );
-        
-
         NamingEnumeration attrs = attributes.getAll();
         
         while ( attrs.hasMoreElements() )
@@ -1277,11 +1396,16 @@
             String attrId = attribute.getID();
             String attrOid = globalRegistries.getOidRegistry().getOid( attrId );
             
-            if ( !allowed.contains( attrOid ) )
+            AttributeType attributeType = globalRegistries.getAttributeTypeRegistry().lookup(
attrOid );
+            
+            if ( !attributeType.isCollective() )
             {
-                throw new LdapSchemaViolationException( "Attribute " + 
-                    attribute.getID() + " not declared in entry's objectClasses.", 
-                    ResultCodeEnum.OBJECTCLASSVIOLATION );
+                if ( !allowed.contains( attrOid ) )
+                {
+                    throw new LdapSchemaViolationException( "Attribute " + 
+                        attribute.getID() + " not declared in entry's objectClasses.", 
+                        ResultCodeEnum.OBJECTCLASSVIOLATION );
+                }
             }
         }
     }



Mime
View raw message