You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2006/01/13 07:56:51 UTC

svn commit: r368622 - in /directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi: ServerContext.java ServerDirContext.java ServerLdapContext.java

Author: trustin
Date: Thu Jan 12 22:56:47 2006
New Revision: 368622

URL: http://svn.apache.org/viewcvs?rev=368622&view=rev
Log:
Fixed a bug where the context in DirectoryPartitionNexusProxy doesn't match with the actual one.


Modified:
    directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerContext.java
    directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
    directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java

Modified: directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerContext.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerContext.java?rev=368622&r1=368621&r2=368622&view=diff
==============================================================================
--- directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerContext.java (original)
+++ directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerContext.java Thu Jan 12 22:56:47 2006
@@ -69,6 +69,9 @@
     /** property key used for deleting the old RDN on a rename */
     public static final String DELETE_OLD_RDN_PROP = "java.naming.ldap.deleteRDN";
 
+    /** The directory service which owns this context **/
+    private final DirectoryService service;
+    
     /** The interceptor proxy to the backend nexus */
     private final DirectoryPartitionNexus nexusProxy;
 
@@ -105,6 +108,8 @@
      */
     protected ServerContext( DirectoryService service, Hashtable env ) throws NamingException
     {
+        this.service = service;
+        
         // set references to cloned env and the proxy
         this.nexusProxy = new DirectoryPartitionNexusProxy( this, service );
         
@@ -154,12 +159,13 @@
      * @param env the environment properties used by this context
      * @param dn the distinguished name of this context
      */
-    protected ServerContext( LdapPrincipal principal, DirectoryPartitionNexus nexusProxy, Hashtable env, Name dn )
+    protected ServerContext( DirectoryService service, LdapPrincipal principal, Name dn )
     {
+        this.service = service;
         this.dn = ( LdapName ) dn.clone();
-        this.env = ( Hashtable ) env.clone();
+        this.env = ( Hashtable ) service.getConfiguration().getEnvironment();
         this.env.put( PROVIDER_URL, dn.toString() );
-        this.nexusProxy = nexusProxy;
+        this.nexusProxy = new DirectoryPartitionNexusProxy( this, service );;
         this.principal = principal;
     }
 
@@ -168,6 +174,13 @@
     // New Impl Specific Public Methods
     // ------------------------------------------------------------------------
 
+    /**
+     * Returns the {@link DirectoryService} which manages this context.
+     */
+    public DirectoryService getService()
+    {
+        return service;
+    }
 
     /**
      * Gets the principal of the authenticated user which also happens to own
@@ -298,9 +311,19 @@
         attributes.put( rdnAttribute, rdnValue );
         attributes.put( JavaLdapSupport.OBJECTCLASS_ATTR, JavaLdapSupport.JCONTAINER_ATTR );
         attributes.put( JavaLdapSupport.OBJECTCLASS_ATTR, JavaLdapSupport.TOP_ATTR );
-
+        
+        /*
+         * Add the new context to the server which as a side effect adds 
+         * operational attributes to the attributes refering instance which
+         * can them be used to initialize a new ServerLdapContext.  Remember
+         * we need to copy over the controls as well to propagate the complete 
+         * environment besides whats in the hashtable for env.
+         */
         nexusProxy.add( target.toString(), target, attributes );
-        return new ServerLdapContext( principal, nexusProxy, env, target );
+        ServerLdapContext ctx = new ServerLdapContext( service, principal, target );
+        Control [] controls = ( Control [] ) ( ( ServerLdapContext ) this ).getRequestControls().clone();
+        ctx.setRequestControls( controls );
+        return ctx;
     }
 
 
@@ -519,14 +542,14 @@
      */
     public Object lookup( String name ) throws NamingException
     {
-    	if ( StringTools.isEmpty( name ) )
-    	{
-    		return lookup( LdapName.EMPTY_LDAP_NAME );
-    	}
-    	else
-    	{
-    		return lookup( new LdapName( name ) );
-    	}
+        if ( StringTools.isEmpty( name ) )
+        {
+            return lookup( LdapName.EMPTY_LDAP_NAME );
+        }
+        else
+        {
+            return lookup( new LdapName( name ) );
+        }
     }
 
 
@@ -565,7 +588,7 @@
         }
         
         // Initialize and return a context since the entry is not a java object
-        ServerLdapContext ctx = new ServerLdapContext( principal, nexusProxy, env, target );
+        ServerLdapContext ctx = new ServerLdapContext( service, principal, target );
             
         // Need to add controls to propagate extended ldap operational env
         Control [] controls = ( ( ServerLdapContext ) this ).getRequestControls();

Modified: directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java?rev=368622&r1=368621&r2=368622&view=diff
==============================================================================
--- directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java (original)
+++ directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerDirContext.java Thu Jan 12 22:56:47 2006
@@ -35,6 +35,7 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.event.EventDirContext;
 import javax.naming.event.NamingListener;
+import javax.naming.ldap.Control;
 import javax.naming.spi.DirStateFactory;
 import javax.naming.spi.DirectoryManager;
 
@@ -47,7 +48,6 @@
 import org.apache.ldap.common.util.NamespaceTools;
 import org.apache.ldap.server.DirectoryService;
 import org.apache.ldap.server.authn.LdapPrincipal;
-import org.apache.ldap.server.partition.DirectoryPartitionNexus;
 import org.apache.ldap.server.partition.DirectoryPartitionNexusProxy;
 
 
@@ -87,9 +87,9 @@
      * @param env the environment properties used by this context
      * @param dn the distinguished name of this context
      */
-    protected ServerDirContext( LdapPrincipal principal, DirectoryPartitionNexus nexusProxy, Hashtable env, Name dn )
+    protected ServerDirContext( DirectoryService service, LdapPrincipal principal, Name dn )
     {
-        super( principal, nexusProxy, env, dn );
+        super( service, principal, dn );
     }
 
 
@@ -349,9 +349,24 @@
             attributes.put( rdnAttribute, rdnValue );
         }
 
-        // Add the new entry to the server and return the new context
+        // Add the new context to the server which as a side effect adds
         getNexusProxy().add( target.toString(), target, attributes );
-        return new ServerLdapContext( getPrincipal(), getNexusProxy(), getEnvironment(), target );
+
+        // Initialize the new context
+        ServerLdapContext ctx = new ServerLdapContext( getService(), getPrincipal(), target );
+        Control [] controls = ( ( ServerLdapContext ) this ).getRequestControls();
+
+        if ( controls != null )
+        {
+            controls = ( Control[] ) controls.clone();
+        }
+        else
+        {
+            controls = new Control[0];
+        }
+
+        ctx.setRequestControls( controls );
+        return ctx;
     }
 
 
@@ -520,8 +535,8 @@
      */
     public NamingEnumeration search( Name name, ExprNode filter, SearchControls cons ) throws NamingException
     {
-    	/*Name newName = new LdapDN( name.toString() );
-    	newName = LdapDN.oidToName( newName, DnOidContainer.getOids() );
+        /*Name newName = new LdapDN( name.toString() );
+        newName = LdapDN.oidToName( newName, DnOidContainer.getOids() );
         Name target = buildTarget( ((LdapDN)newName).toLdapName() );*/
 
         Name target = buildTarget( name );

Modified: directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java?rev=368622&r1=368621&r2=368622&view=diff
==============================================================================
--- directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java (original)
+++ directory/trunks/apacheds/src/main/java/org/apache/ldap/server/jndi/ServerLdapContext.java Thu Jan 12 22:56:47 2006
@@ -29,7 +29,6 @@
 import org.apache.ldap.common.NotImplementedException;
 import org.apache.ldap.server.DirectoryService;
 import org.apache.ldap.server.authn.LdapPrincipal;
-import org.apache.ldap.server.partition.DirectoryPartitionNexus;
 
 
 /**
@@ -68,9 +67,9 @@
      * @param env the environment properties used by this context
      * @param dn the distinguished name of this context
      */
-    ServerLdapContext( LdapPrincipal principal, DirectoryPartitionNexus nexusProxy, Hashtable env, Name dn )
+    ServerLdapContext( DirectoryService service, LdapPrincipal principal, Name dn )
     {
-        super( principal, nexusProxy, env, dn );
+        super( service, principal, dn );
     }
 
 
@@ -91,8 +90,7 @@
     public LdapContext newInstance( Control[] requestControls )
         throws NamingException
     {
-        ServerLdapContext ctx = new ServerLdapContext( getPrincipal(), getNexusProxy(),
-                getEnvironment(), getDn() );
+        ServerLdapContext ctx = new ServerLdapContext( getService(), getPrincipal(), getDn() );
         ctx.setRequestControls( requestControls );
         return ctx;
     }