directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r159311 - in directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol: BindHandler.java SessionRegistry.java
Date Mon, 28 Mar 2005 21:13:22 GMT
Author: akarasulu
Date: Mon Mar 28 13:13:21 2005
New Revision: 159311

URL: http://svn.apache.org/viewcvs?view=rev&rev=159311
Log:
adding support for reusing an existing handle to an ICF within the protocol provider for LDAP

Modified:
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
    directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java

Modified: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/BindHandler.java?view=diff&r1=159310&r2=159311
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
(original)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/BindHandler.java
Mon Mar 28 13:13:21 2005
@@ -21,7 +21,9 @@
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
 import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
 
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.BindRequest;
@@ -37,6 +39,7 @@
 import org.apache.mina.protocol.DemuxingProtocolHandler.MessageHandler;
 
 
+
 /**
  * A single reply handler for {@link org.apache.ldap.common.message.BindRequest}s.
  *
@@ -50,7 +53,7 @@
 
     public void messageReceived( ProtocolSession session, Object request )
     {
-        InitialLdapContext ictx;
+        LdapContext ctx;
 
         BindRequest req = ( BindRequest ) request;
 
@@ -104,19 +107,33 @@
 
         byte[] creds = req.getCredentials();
 
-        env = ( Hashtable ) env.clone();
+        Hashtable cloned = ( Hashtable ) env.clone();
 
-        env.put( Context.SECURITY_PRINCIPAL, dn );
+        cloned.put( Context.SECURITY_PRINCIPAL, dn );
 
-        env.put( Context.SECURITY_CREDENTIALS, creds );
+        cloned.put( Context.SECURITY_CREDENTIALS, creds );
 
-        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+        cloned.put( Context.SECURITY_AUTHENTICATION, "simple" );
 
         Control[] connCtls = ( Control[] ) req.getControls().toArray( EMPTY );
 
         try
         {
-            ictx = new InitialLdapContext( env, connCtls );
+            if ( cloned.containsKey( "server.use.factory.instance" ) )
+            {
+                InitialContextFactory factory = ( InitialContextFactory ) cloned.get( "server.use.factory.instance"
);
+
+                if ( factory == null )
+                {
+                    throw new NullPointerException( "server.use.factory.instance was set
in env but was null" );
+                }
+
+                ctx = ( LdapContext ) factory.getInitialContext( cloned );
+            }
+            else
+            {
+                ctx = new InitialLdapContext( cloned, connCtls );
+            }
         }
         catch( NamingException e )
         {
@@ -141,7 +158,7 @@
             return;
         }
 
-        SessionRegistry.getSingleton().setInitialLdapContext( session, ictx );
+        SessionRegistry.getSingleton().setLdapContext( session, ctx );
 
         result.setResultCode( ResultCodeEnum.SUCCESS );
 

Modified: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java?view=diff&r1=159310&r2=159311
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java
(original)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/SessionRegistry.java
Mon Mar 28 13:13:21 2005
@@ -23,9 +23,11 @@
 
 import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
 import javax.naming.directory.InitialDirContext;
 import javax.naming.ldap.Control;
 import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
 
 import org.apache.ldap.common.exception.LdapNoPermissionException;
 import org.apache.mina.protocol.ProtocolSession;
@@ -39,9 +41,12 @@
  */
 public class SessionRegistry
 {
+    /** the singleton for this registry */
     private static SessionRegistry s_singleton;
+
     /** the set of client contexts */
     private final Map contexts = new HashMap();
+
     /** the properties associated with this SessionRegistry */
     private Hashtable env;
 
@@ -84,12 +89,15 @@
         if ( env == null )
         {
             this.env = new Hashtable();
+
             this.env.put( Context.PROVIDER_URL, "" );
+
             this.env.put( Context.INITIAL_CONTEXT_FACTORY, "org.apache.ldap.server.jndi.ServerContextFactory"
);
         }
         else
         {
             this.env = env;
+
             this.env.put( Context.PROVIDER_URL, "" );
         }
     }
@@ -117,19 +125,17 @@
      * InitialContext if one is not present for the operation
      * @return the InitialContext or null
      */
-    public InitialLdapContext getInitialLdapContext( ProtocolSession session,
-                                                     Control[] connCtls,
-                                                     boolean allowAnonymous )
+    public LdapContext getInitialLdapContext( ProtocolSession session, Control[] connCtls,
boolean allowAnonymous )
             throws NamingException
     {
-        InitialLdapContext ictx = null;
+        LdapContext ctx = null;
 
         synchronized( contexts )
         {
-            ictx = ( InitialLdapContext ) contexts.get( session );
+            ctx = ( InitialLdapContext ) contexts.get( session );
         }
 
-        if ( ictx == null && allowAnonymous )
+        if ( ctx == null && allowAnonymous )
         {
             if ( env.containsKey( "server.disable.anonymous" ) )
             {
@@ -137,10 +143,25 @@
             }
 
             Hashtable cloned = ( Hashtable ) env.clone();
-            ictx = new InitialLdapContext( cloned, connCtls );
+
+            if ( env.containsKey( "server.use.factory.instance" ) )
+            {
+                InitialContextFactory factory = ( InitialContextFactory ) env.get( "server.use.factory.instance"
);
+
+                if ( factory == null )
+                {
+                    throw new NullPointerException( "server.use.factory.instance was set
in env but was null" );
+                }
+
+                ctx = ( LdapContext ) factory.getInitialContext( env );
+            }
+            else
+            {
+                ctx = new InitialLdapContext( cloned, connCtls );
+            }
         }
 
-        return ictx;
+        return ctx;
     }
 
 
@@ -150,7 +171,7 @@
      * @param session the client session
      * @param ictx the initial context gotten
      */
-    public void setInitialLdapContext( ProtocolSession session, InitialDirContext ictx )
+    public void setLdapContext( ProtocolSession session, LdapContext ictx )
     {
         synchronized( contexts )
         {



Mime
View raw message