directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 55926 - in incubator/directory/eve/trunk/backend/core/src: java/org/apache/eve java/org/apache/eve/db java/org/apache/eve/jndi/ibs test/org/apache/eve/jndi test/org/apache/eve/jndi/ibs
Date Fri, 29 Oct 2004 01:47:59 GMT
Author: akarasulu
Date: Thu Oct 28 18:47:58 2004
New Revision: 55926

Modified:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/SystemPartition.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ResultFilteringEnumeration.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/FilterServiceImpl.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/BinaryAttributeFilterTest.java
   incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributeServiceTest.java
Log:
Changes ...

 o added code to system partition to add creation operational attribs
 o added code to protect against a nasty bug in ResultFilterEnumeration where
   the first prefetched item to return was never filtered since no filters
   were added yet.  I changed things around so a filter can be added or a 
   list of them can be added before prefetch is called
 o added test case to OpAttSvcTest to make sure the root ou=system node 
   was behaving properly now with operational attributes for create 
   automatically added on creation
  


Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/SystemPartition.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/SystemPartition.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/SystemPartition.java
Thu Oct 28 18:47:58 2004
@@ -23,6 +23,7 @@
 
 import org.apache.ldap.common.name.LdapName ;
 import org.apache.ldap.common.util.NamespaceTools ;
+import org.apache.ldap.common.util.DateUtils;
 import org.apache.ldap.common.schema.AttributeType;
 import org.apache.ldap.common.message.LockableAttributesImpl ;
 
@@ -40,6 +41,9 @@
  */
 public final class SystemPartition extends AbstractContextPartition
 {
+    /** the default user principal or DN */
+    public final static String DEFAULT_PRINCIPAL = "uid=admin,ou=system";
+
     /**
      * System backend suffix constant.  Should be kept down to a single Dn name 
      * component or the default constructor will have to parse it instead of 
@@ -88,18 +92,18 @@
         }
 
         // add the root entry for the system root context if it does not exist
-        Attributes l_attributes = db.getSuffixEntry() ;
-        if ( null == l_attributes )
+        Attributes attributes = db.getSuffixEntry() ;
+        if ( null == attributes )
         {
-            l_attributes = new LockableAttributesImpl() ;
-            l_attributes.put( "objectClass", "top" ) ;
-            l_attributes.put( "objectClass", "organizationalUnit" ) ;
-            l_attributes.put( NamespaceTools.getRdnAttribute( SUFFIX ),
+            attributes = new LockableAttributesImpl() ;
+            attributes.put( "objectClass", "top" ) ;
+            attributes.put( "objectClass", "organizationalUnit" ) ;
+            attributes.put( "creatorsName", DEFAULT_PRINCIPAL ) ;
+            attributes.put( "createTimestamp", DateUtils.getGeneralizedTime() ) ;
+            attributes.put( NamespaceTools.getRdnAttribute( SUFFIX ),
                 NamespaceTools.getRdnValue( SUFFIX ) ) ;
 
-            getDb().add( SUFFIX, suffix, l_attributes ) ;
-            //m_logger.info( "Added suffix '" + SUFFIX
-            //    + "' for system backend" ) ;
+            getDb().add( SUFFIX, suffix, attributes ) ;
         }
     }
 

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ResultFilteringEnumeration.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ResultFilteringEnumeration.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ResultFilteringEnumeration.java
Thu Oct 28 18:47:58 2004
@@ -18,8 +18,8 @@
 
 
 import java.util.List;
-import java.util.ArrayList;
 import java.util.Collections;
+import java.util.ArrayList;
 
 import javax.naming.NamingException;
 import javax.naming.NamingEnumeration;
@@ -38,7 +38,7 @@
 public class ResultFilteringEnumeration implements NamingEnumeration
 {
     /** the list of filters to be applied */
-    private final ArrayList filters;
+    private final List filters;
     /** the underlying decorated enumeration */
     private final NamingEnumeration decorated;
 
@@ -69,12 +69,46 @@
      */
     public ResultFilteringEnumeration( NamingEnumeration decorated,
                                        SearchControls searchControls,
-                                       LdapContext ctx )
+                                       LdapContext ctx,
+                                       SearchResultFilter filter )
+            throws NamingException
+    {
+        this.searchControls = searchControls;
+        this.ctx = ctx;
+        this.filters = new ArrayList();
+        this.filters.add( filter );
+        this.decorated = decorated;
+
+        if ( ! decorated.hasMore() )
+        {
+            close();
+            return;
+        }
+
+        prefetch();
+    }
+
+
+    /**
+     * Creates a new database result filtering enumeration to decorate an
+     * underlying enumeration.
+     *
+     * @param decorated the underlying decorated enumeration
+     * @param searchControls the search controls associated with the search
+     * creating this enumeration
+     * @param ctx the LDAP context that made the search creating this
+     * enumeration
+     */
+    public ResultFilteringEnumeration( NamingEnumeration decorated,
+                                       SearchControls searchControls,
+                                       LdapContext ctx,
+                                       List filters )
             throws NamingException
     {
         this.searchControls = searchControls;
         this.ctx = ctx;
         this.filters = new ArrayList();
+        this.filters.addAll( filters );
         this.decorated = decorated;
 
         if ( ! decorated.hasMore() )

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/FilterServiceImpl.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/FilterServiceImpl.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/FilterServiceImpl.java
Thu Oct 28 18:47:58 2004
@@ -150,16 +150,16 @@
             ResultFilteringEnumeration retval;
             LdapContext ctx = ( LdapContext ) invocation.getContextStack().peek();
             enum = ( SearchResultEnumeration ) invocation.getReturnValue();
-            retval = new ResultFilteringEnumeration( enum, searchControls, ctx );
-            retval.addResultFilter( new SearchResultFilter()
-            {
-                public boolean accept( LdapContext ctx, DbSearchResult result,
-                                       SearchControls controls )
-                        throws NamingException
+            retval = new ResultFilteringEnumeration( enum, searchControls, ctx,
+                new SearchResultFilter()
                 {
-                    return FilterServiceImpl.this.accept( ctx, result, controls );
-                }
-            } );
+                    public boolean accept( LdapContext ctx, DbSearchResult result,
+                                           SearchControls controls )
+                            throws NamingException
+                    {
+                        return FilterServiceImpl.this.accept( ctx, result, controls );
+                    }
+                } );
             invocation.setReturnValue( retval );
         }
     }

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
Thu Oct 28 18:47:58 2004
@@ -25,6 +25,7 @@
 import javax.naming.directory.*;
 
 import org.apache.eve.RootNexus;
+import org.apache.eve.SystemPartition;
 import org.apache.eve.db.DbSearchResult;
 import org.apache.eve.db.SearchResultFilter;
 import org.apache.eve.jndi.Invocation;
@@ -47,8 +48,6 @@
  */
 public class OperationalAttributeService extends BaseInterceptor
 {
-    /** the default user principal or DN */
-    private final String DEFAULT_PRINCIPAL = "cn=admin,ou=system";
     /** the database search result filter to register with filter service */
     private final SearchResultFilter SEARCH_FILTER = new SearchResultFilter()
     {
@@ -290,6 +289,6 @@
         String principal;
         Context ctx = ( ( Context ) invocation.getContextStack().peek() );
         principal = ( String ) ctx.getEnvironment().get( Context.SECURITY_PRINCIPAL );
-        return principal == null ? DEFAULT_PRINCIPAL : principal;
+        return principal == null ? SystemPartition.DEFAULT_PRINCIPAL : principal;
     }
 }

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/AbstractJndiTest.java
Thu Oct 28 18:47:58 2004
@@ -86,7 +86,7 @@
 
         try
         {
-            InitialContext initialContext = new InitialContext( env );
+            new InitialContext( env );
         }
         catch( Exception e )
         {

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/BinaryAttributeFilterTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/BinaryAttributeFilterTest.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/BinaryAttributeFilterTest.java
Thu Oct 28 18:47:58 2004
@@ -61,19 +61,20 @@
         value = ou.get();
         assertTrue( value instanceof byte[] );
 
+        // try krb5Key which should be binary automatically - use ou as control
         byte[] keyValue = new byte[] { 0x45, 0x23, 0x7d, 0x7f };
-        // try krb5key which should be binary automatically
         attributes.put( "krb5Key", keyValue );
         sysRoot.createSubcontext( "ou=anothertest", attributes );
         ctx = ( DirContext ) sysRoot.lookup( "ou=anothertest" ) ;
         ou = ctx.getAttributes( "" ).get( "ou" );
         value = ou.get();
         assertTrue( value instanceof byte[] );
-
         Attribute krb5Key = ctx.getAttributes( "" ).get( "krb5Key" );
         value = krb5Key.get();
         assertTrue( value instanceof byte[] );
 
+        // try krb5Key which should be binary automatically but use String to
+        // create so we should still get back a byte[] - use ou as control
         attributes.remove( "krb5Key" );
         attributes.put( "krb5Key", "testing a string" );
         sysRoot.createSubcontext( "ou=yetanothertest", attributes );
@@ -81,7 +82,6 @@
         ou = ctx.getAttributes( "" ).get( "ou" );
         value = ou.get();
         assertTrue( value instanceof byte[] );
-
         krb5Key = ctx.getAttributes( "" ).get( "krb5Key" );
         value = krb5Key.get();
         assertTrue( value instanceof byte[] );

Modified: incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributeServiceTest.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributeServiceTest.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/test/org/apache/eve/jndi/ibs/OperationalAttributeServiceTest.java
Thu Oct 28 18:47:58 2004
@@ -82,4 +82,39 @@
         assertNotNull( result.getAttributes().get( CREATORS_NAME ) );
         assertNotNull( result.getAttributes().get( CREATE_TIMESTAMP ) );
     }
+
+
+    /**
+     * Checks to confirm that the system context root ou=system has the
+     * required operational attributes.  Since this is created automatically
+     * on system database creation properties the create attributes must be
+     * specified.  There are no interceptors in effect when this happens so
+     * we must test explicitly.
+     *
+     *
+     * @see <a href="http://nagoya.apache.org/jira/browse/DIREVE-57">DIREVE-57:
+     * ou=system does not contain operational attributes</a>
+     */
+    public void testSystemContextRoot() throws NamingException
+    {
+        SearchControls controls = new SearchControls();
+        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
+        NamingEnumeration list;
+        list = sysRoot.search( "", "(objectClass=*)", controls );
+        SearchResult result = ( SearchResult ) list.next();
+
+        // test to make sure op attribute do not occur - this is the control
+        Attributes attributes = result.getAttributes();
+        assertNull( attributes.get( "creatorsName" ) );
+        assertNull( attributes.get( "createTimestamp" ) );
+
+        // now we ask for all the op attributes and check to get them
+        String[] ids = new String[] { "creatorsName", "createTimestamp" };
+        controls.setReturningAttributes( ids );
+        list = sysRoot.search( "", "(objectClass=*)", controls );
+        result = ( SearchResult ) list.next();
+        attributes = result.getAttributes();
+        assertNotNull( attributes.get( "creatorsName" ) );
+        assertNotNull( attributes.get( "createTimestamp" ) );
+    }
 }

Mime
View raw message