You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/06/07 05:35:02 UTC

svn commit: r664268 - in /directory/apacheds/branches/bigbang/core/src: main/java/org/apache/directory/server/core/ main/java/org/apache/directory/server/core/collective/ main/java/org/apache/directory/server/core/exception/ main/java/org/apache/direct...

Author: akarasulu
Date: Fri Jun  6 20:35:02 2008
New Revision: 664268

URL: http://svn.apache.org/viewvc?rev=664268&view=rev
Log:
fixing bugs after JNDI and CoreSession refactoring ...

 o fixed bug in collective attribute interceptor which was causing a nasty
   chain recursion: new bypass was used on lookups that avoids this interceptor
 o fixed bug in referral mode handling where the sessions referral handling
   was not being propertly set by the JNDI Context implementation
 o added some new methods to OperationContext to deal with hasEntry() operations
   which required using a special bypass instruction which is used by the 
   ExceptionInterceptor
 o more javadocs
 o added method to convert Context.REFERRAL to an enumerated type for the 
   referral handling mode : NEED TO MOVE THIS TO SHARED ???
 o exposed setter for setting the ReferralHandlingMode on a CoreSession


Modified:
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/CoreSession.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/ReferralHandlingMode.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/ByPassConstants.java
    directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/CoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/CoreSession.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/CoreSession.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/CoreSession.java Fri Jun  6 20:35:02 2008
@@ -99,6 +99,14 @@
      * @return the referral handling mode for this session
      */
     ReferralHandlingMode getReferralHandlingMode();
+
+    
+    /**
+     * Sets the referral handling mode for this CoreSession.
+     *
+     * @param referralHandlingMode the referral handling mode for this session
+     */
+    void setReferralHandlingMode( ReferralHandlingMode referralHandlingMode );
     
     
     /**

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/ReferralHandlingMode.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/ReferralHandlingMode.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/ReferralHandlingMode.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/ReferralHandlingMode.java Fri Jun  6 20:35:02 2008
@@ -20,6 +20,9 @@
 package org.apache.directory.server.core;
 
 
+import javax.naming.Context;
+
+
 /**
  * Enumeration for referral handling modes.
  *
@@ -30,18 +33,70 @@
 {
     THROW( "throw" ), FOLLOW( "follow" ), IGNORE( "ignore" ), THROW_FINDING_BASE( "throw-finding-base" );
     
-    
+    /** 
+     * The JNDI Context.REFERRAL key's value.
+     * 
+     * @see {@link Context#REFERRAL}
+     */
     private final String jndiValue;
     
     
+    /**
+     * Creates a new instance of ReferralHandlingMode.
+     *
+     * @see {@link Context#REFERRAL}
+     * @param jndiValue the JNDI Context.REFERRAL key's value
+     */
     private ReferralHandlingMode( String jndiValue )
     {
         this.jndiValue = jndiValue;
     }
     
     
+    /**
+     * Gets the equivalent JNDI Context.REFERRAL key's value for this enumeration constant.
+     *
+     * @see {@link Context#REFERRAL}
+     * @return the equivalent JNDI Context.REFERRAL key's value
+     */
     public String getJndiValue()
     {
         return jndiValue;
     }
+    
+    
+    /**
+     * Gets the enumeration constant for the JNDI Context.REFERRAL key's value.
+     *
+     * @see {@link Context#REFERRAL}
+     * @param jndiValue the JNDI Context.REFERRAL key's value
+     * @return the referral handling mode enumeration constant
+     * @throws IllegalArgumentException if the value is not a recognized value
+     */
+    public static final ReferralHandlingMode getModeFromJndi( String jndiValue )
+    {
+        jndiValue = jndiValue.trim().toLowerCase();
+        
+        if ( jndiValue.equals( "throw" ) )
+        {
+            return THROW;
+        }
+        
+        if ( jndiValue.equals( "follow" ) )
+        {
+            return FOLLOW;
+        }
+        
+        if ( jndiValue.equals( "ignore" ) )
+        {
+            return IGNORE;
+        }
+        
+        if ( jndiValue.equals( "throw-finding-base" ) )
+        {
+            return THROW_FINDING_BASE;
+        }
+        
+        throw new IllegalArgumentException( "Unknown JNDI Context.REFERRAL value of " + jndiValue );
+    }
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/collective/CollectiveAttributeInterceptor.java Fri Jun  6 20:35:02 2008
@@ -196,7 +196,15 @@
         {
             String subentryDnStr = ( String ) value.get();
             LdapDN subentryDn = new LdapDN( subentryDnStr );
-            ServerEntry subentry = opContext.lookup( subentryDn, ByPassConstants.LOOKUP_BYPASS );
+            
+            /*
+             * TODO - Instead of hitting disk here can't we leverage the 
+             * SubentryService to get us cached sub-entries so we're not
+             * wasting time with a lookup here? It is ridiculous to waste
+             * time looking up this sub-entry. 
+             */
+            
+            ServerEntry subentry = opContext.lookup( subentryDn, ByPassConstants.LOOKUP_COLLECTIVE_BYPASS );
             
             for ( AttributeType attributeType:subentry.getAttributeTypes() )
             {

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java Fri Jun  6 20:35:02 2008
@@ -558,7 +558,7 @@
             return;
         }
         
-        if ( !nextInterceptor.hasEntry( new EntryOperationContext( opContext.getSession(), dn ) ) )
+        if ( ! opContext.hasEntry( dn, ByPassConstants.HAS_ENTRY_BYPASS ) )
         {
             LdapNameNotFoundException e;
 

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java Fri Jun  6 20:35:02 2008
@@ -266,6 +266,15 @@
     }
     
     
+    public boolean hasEntry( LdapDN dn, Collection<String> byPassed ) throws Exception
+    {
+        EntryOperationContext opContext = new EntryOperationContext( session, dn );
+        setup( opContext );
+        opContext.setByPassed( byPassed );
+        return session.getDirectoryService().getOperationManager().hasEntry( opContext );
+    }
+    
+    
     public void add( ServerEntry entry, Collection<String> byPassed ) throws Exception
     {
         AddOperationContext opContext = new AddOperationContext( session, entry );

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java Fri Jun  6 20:35:02 2008
@@ -445,4 +445,22 @@
     {
         throw new NotImplementedException();
     }
+
+
+    private void setup( AbstractOperationContext opContext )
+    {
+        opContext.setPreviousOperation( this );
+        next = opContext;
+        opContext.setByPassed( opContext.getByPassed() );
+        opContext.setAuthorizedPrincipal( authorizedPrincipal );
+    }
+    
+    
+    public boolean hasEntry( LdapDN dn, Collection<String> byPassed ) throws Exception
+    {
+        EntryOperationContext opContext = new EntryOperationContext( session, dn );
+        setup( opContext );
+        opContext.setByPassed( byPassed );
+        return session.getDirectoryService().getOperationManager().hasEntry( opContext );
+    }
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java Fri Jun  6 20:35:02 2008
@@ -29,6 +29,7 @@
 import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
 import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.name.LdapDN;
 
@@ -261,19 +262,30 @@
     LookupOperationContext newLookupContext( LdapDN dn );
 
     
-    ClonedServerEntry lookup( LdapDN dn, Collection<String> bypass ) throws Exception;
+    ClonedServerEntry lookup( LdapDN dn, Collection<String> byPass ) throws Exception;
     
     
     ClonedServerEntry lookup( LookupOperationContext lookupContext ) throws Exception;
     
     
-    void modify( LdapDN dn, List<Modification> mods, Collection<String> bypass ) throws Exception;
+    void modify( LdapDN dn, List<Modification> mods, Collection<String> byPass ) throws Exception;
     
     
-    void add( ServerEntry entry, Collection<String> bypass ) throws Exception;
+    void add( ServerEntry entry, Collection<String> byPass ) throws Exception;
     
     
-    void delete( LdapDN dn, Collection<String> bypass ) throws Exception;
+    void delete( LdapDN dn, Collection<String> byPass ) throws Exception;
+
+
+    /**
+     * Checks to see if an entry exists.
+     *
+     * @param dn the distinguished name of the entry to check
+     * @param byPass collection of {@link Interceptor}'s to bypass for this check
+     * @return true if the entry exists, false if it does not
+     * @throws Exception on failure to perform this operation
+     */
+    boolean hasEntry( LdapDN dn, Collection<String> byPass ) throws Exception;
     
     
 //    AddOperationContext newAddContext( ServerEntry entry );

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java Fri Jun  6 20:35:02 2008
@@ -23,6 +23,7 @@
 import org.apache.directory.server.core.CoreSession;
 import org.apache.directory.server.core.DefaultCoreSession;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.ReferralHandlingMode;
 import org.apache.directory.server.core.authn.LdapPrincipal;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
@@ -128,6 +129,7 @@
     // Constructors
     // ------------------------------------------------------------------------
 
+    
     /**
      * Must be called by all subclasses to initialize the nexus proxy and the
      * environment settings to be used by this Context implementation.  This
@@ -142,8 +144,7 @@
      * @throws NamingException if the environment parameters are not set 
      * correctly.
      */
-    @SuppressWarnings(value =
-        { "unchecked" })
+    @SuppressWarnings(value = { "unchecked" })
     protected ServerContext( DirectoryService service, Hashtable<String, Object> env ) throws Exception
     {
         this.service = service;
@@ -152,6 +153,7 @@
         this.nexusProxy = new PartitionNexusProxy( service );
 
         this.env = env;
+        
         LdapJndiProperties props = LdapJndiProperties.getLdapJndiProperties( this.env );
         dn = props.getProviderDn();
 
@@ -160,12 +162,33 @@
             .getSaslAuthId() );
 
         session = new DefaultCoreSession( principal, service );
+        setReferralHandlingMode( env );
         
         if ( !nexusProxy.hasEntry( new EntryOperationContext( session, dn ) ) )
         {
             throw new NameNotFoundException( dn + " does not exist" );
         }
     }
+    
+    
+    /**
+     * Sets the referral handling mode on the CoreSession based on the 
+     * presence of a {@link Context#REFERRAL} environment property.
+     *
+     * @param env the environment to check
+     */
+    private void setReferralHandlingMode( Hashtable<String,Object> env )
+    {
+        if ( env.containsKey( Context.REFERRAL ) )
+        {
+            Object value = env.get( Context.REFERRAL );
+            
+            if ( value != null )
+            {
+                session.setReferralHandlingMode( ReferralHandlingMode.getModeFromJndi( ( String ) value ) );
+            }
+        }
+    }
 
 
     /**
@@ -598,6 +621,18 @@
      */
     public Object addToEnvironment( String propName, Object propVal ) throws NamingException
     {
+        if ( propName.equals( Context.REFERRAL ) )
+        {
+            if ( propVal != null )
+            {
+                session.setReferralHandlingMode( ReferralHandlingMode.getModeFromJndi( ( String ) propVal ) );
+            }
+            else
+            {
+                session.setReferralHandlingMode( ReferralHandlingMode.IGNORE );
+            }
+        }
+        
         return env.put( propName, propVal );
     }
 
@@ -607,6 +642,11 @@
      */
     public Object removeFromEnvironment( String propName ) throws NamingException
     {
+        if ( propName.equals( Context.REFERRAL ) )
+        {
+            session.setReferralHandlingMode( ReferralHandlingMode.IGNORE );
+        }
+        
         return env.remove( propName );
     }
 

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/ByPassConstants.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/ByPassConstants.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/ByPassConstants.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/ByPassConstants.java Fri Jun  6 20:35:02 2008
@@ -31,6 +31,7 @@
 import org.apache.directory.server.core.collective.CollectiveAttributeInterceptor;
 import org.apache.directory.server.core.event.EventInterceptor;
 import org.apache.directory.server.core.exception.ExceptionInterceptor;
+import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.normalization.NormalizationInterceptor;
 import org.apache.directory.server.core.operational.OperationalAttributeInterceptor;
 import org.apache.directory.server.core.referral.ReferralInterceptor;
@@ -46,13 +47,24 @@
  */
 public class ByPassConstants
 {
-
     /**
      * safe to use set of bypass instructions to lookup raw entries
      */
     public final static Collection<String> LOOKUP_BYPASS;
 
     /**
+     * safe to use set of bypass instructions to lookup raw entries while
+     * also avoiding hit on collective attributes {@link Interceptor}: used 
+     * by collective attributes interceptor.
+     */
+    public static final Collection<String> LOOKUP_COLLECTIVE_BYPASS;
+
+    /**
+     * bypass instructions used by ExceptionInterceptor
+     */
+    public final static Collection<String> HAS_ENTRY_BYPASS;
+
+    /**
      * safe to use set of bypass instructions to getMatchedDn
      */
     public static final Collection<String> GETMATCHEDDN_BYPASS;
@@ -90,6 +102,32 @@
         LOOKUP_BYPASS = Collections.unmodifiableCollection( c );
 
         c = new HashSet<String>();
+        c.add( NormalizationInterceptor.class.getName() );
+        c.add( AuthenticationInterceptor.class.getName() );
+        c.add( ReferralInterceptor.class.getName() );
+        c.add( AciAuthorizationInterceptor.class.getName() );
+        c.add( DefaultAuthorizationInterceptor.class.getName() );
+        c.add( ExceptionInterceptor.class.getName() );
+        c.add( OperationalAttributeInterceptor.class.getName() );
+        c.add( SchemaInterceptor.class.getName() );
+        c.add( SubentryInterceptor.class.getName() );
+        c.add( EventInterceptor.class.getName() );
+        HAS_ENTRY_BYPASS = Collections.unmodifiableCollection( c );
+
+        c = new HashSet<String>();
+        c.add( NormalizationInterceptor.class.getName() );
+        c.add( AuthenticationInterceptor.class.getName() );
+        c.add( ReferralInterceptor.class.getName() );
+        c.add( AciAuthorizationInterceptor.class.getName() );
+        c.add( DefaultAuthorizationInterceptor.class.getName() );
+        c.add( CollectiveAttributeInterceptor.class.getName() );
+        c.add( OperationalAttributeInterceptor.class.getName() );
+        c.add( SchemaInterceptor.class.getName() );
+        c.add( SubentryInterceptor.class.getName() );
+        c.add( EventInterceptor.class.getName() );
+        LOOKUP_COLLECTIVE_BYPASS = Collections.unmodifiableCollection( c );
+
+        c = new HashSet<String>();
         c.add( AuthenticationInterceptor.class.getName() );
         c.add( ReferralInterceptor.class.getName() );
         c.add( AciAuthorizationInterceptor.class.getName() );

Modified: directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java?rev=664268&r1=664267&r2=664268&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java (original)
+++ directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java Fri Jun  6 20:35:02 2008
@@ -446,6 +446,13 @@
             // TODO Auto-generated method stub
             
         }
+
+
+        public boolean hasEntry( LdapDN dn, Collection<String> byPass ) throws Exception
+        {
+            // TODO Auto-generated method stub
+            return false;
+        }
     }
 
     class MockDirectoryService implements DirectoryService