directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 56477 - incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol
Date Wed, 03 Nov 2004 05:45:53 GMT
Author: akarasulu
Date: Tue Nov  2 21:45:52 2004
New Revision: 56477

Added:
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProviderMonitor.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
Modified:
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AbandonHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProtocolProvider.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java
Log:
its coming along

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AbandonHandler.java
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AbandonHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AbandonHandler.java
Tue Nov  2 21:45:52 2004
@@ -20,6 +20,7 @@
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractNoReplyHandler;
 
+import org.apache.ldap.common.message.AbandonRequest;
 import org.apache.ldap.common.NotImplementedException;
 
 
@@ -33,6 +34,8 @@
 {
     public void handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.AbandonHandler
not implemented!" );
+        AbandonRequest req = ( AbandonRequest ) request;
+        int abandonedId = req.getAbandoned();
+        throw new NotImplementedException( "don't know how to do this just yet" );
     }
 }

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java
Tue Nov  2 21:45:52 2004
@@ -17,10 +17,16 @@
 package org.apache.eve.protocol;
 
 
+import java.util.Hashtable;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
-import org.apache.ldap.common.NotImplementedException;
+import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.util.ExceptionUtils;
 
 
 /**
@@ -36,6 +42,37 @@
      */
     public Object handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.BindHandler
not implemented!" );
+        BindRequest req = ( BindRequest ) request;
+        BindResponse resp = new BindResponseImpl( req.getMessageId() );
+
+        if ( ! req.isSimple() )
+        {
+            resp.setLdapResult( new LdapResultImpl( resp ) );
+            resp.getLdapResult().setResultCode( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
+            resp.getLdapResult().setErrorMessage( "Only simple binds currently supported"
);
+            return resp;
+        }
+
+        String dn = req.getName();
+        byte[] creds = req.getCredentials();
+        Hashtable env = SessionRegistry.getSingleton( null ).getEnvironment();
+        InitialContext ictx;
+
+        try
+        {
+            ictx = new InitialContext( env );
+        }
+        catch( NamingException e )
+        {
+            resp.setLdapResult( new LdapResultImpl( resp ) );
+            resp.getLdapResult().setResultCode( ResultCodeEnum.OTHER );
+            String msg = "Bind failure:\n" + ExceptionUtils.getStackTrace( e );
+            msg += "\n\nBindRequest = \n" + req.toString();
+            resp.getLdapResult().setErrorMessage( msg );
+            return resp;
+        }
+
+        SessionRegistry.getSingleton( null ).put( key, ictx );
+        return resp;
     }
 }

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProtocolProvider.java
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProtocolProvider.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProtocolProvider.java
Tue Nov  2 21:45:52 2004
@@ -115,6 +115,7 @@
     public LdapProtocolProvider( Properties env ) throws LdapNamingException
     {
         this.handlers = new HashMap();
+        SessionRegistry.getSingleton( env );
 
         Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();
         while ( requestTypes.hasNext() )
@@ -172,6 +173,7 @@
     public LdapProtocolProvider() throws LdapNamingException
     {
         this.handlers = new HashMap();
+        SessionRegistry.getSingleton( null );
 
         Iterator requestTypes = DEFAULT_HANDLERS.keySet().iterator();
         while ( requestTypes.hasNext() )

Added: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProviderMonitor.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/LdapProviderMonitor.java
Tue Nov  2 21:45:52 2004
@@ -0,0 +1,28 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.eve.protocol;
+
+
+/**
+ * Document this class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface LdapProviderMonitor
+{
+}

Added: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
Tue Nov  2 21:45:52 2004
@@ -0,0 +1,162 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.eve.protocol;
+
+
+import java.util.*;
+import javax.naming.InitialContext;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * A client session state based on JNDI contexts.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SessionRegistry
+{
+    private static SessionRegistry s_singleton;
+    /** the set of client contexts */
+    private final Map contexts = new HashMap();
+    /** the observer to listen for key expiration */
+    private final Observer keyObserver = new KeyExpirationObserver();
+    /** the properties associated with this SessionRegistry */
+    private Hashtable env;
+
+
+    /**
+     * Gets the singleton instance for this SessionRegistry.  If the singleton
+     * does not exist one is created.
+     *
+     * @param env the properties associated with the SessionRegistry if created
+     * @return the singleton SessionRegistry instance
+     */
+    public static SessionRegistry getSingleton( Hashtable env )
+    {
+        if ( s_singleton == null )
+        {
+            s_singleton = new SessionRegistry( env );
+        }
+
+        return s_singleton;
+    }
+
+
+    /**
+     * Creates a singleton session state object for the system.
+     *
+     * @param env the properties associated with this SessionRegistry
+     */
+    private SessionRegistry( Hashtable env )
+    {
+        if ( env == null )
+        {
+            this.env = new Hashtable();
+        }
+        else
+        {
+            this.env = env;
+        }
+    }
+
+
+    /**
+     * Gets a cloned copy of the environment associated with this registry.
+     *
+     * @return the registry environment
+     */
+    public Hashtable getEnvironment()
+    {
+        return ( Hashtable ) env.clone();
+    }
+
+
+    /**
+     * Gets the InitialContext to the root of the system that was gotten for
+     * client.
+     *
+     * @param key the client's key
+     * @return the InitialContext or null
+     */
+    public InitialContext get( ClientKey key )
+    {
+        key.addObserver( keyObserver );
+        synchronized( contexts )
+        {
+            return ( InitialContext ) contexts.get( key );
+        }
+    }
+
+
+    /**
+     * Sets the initial context associated with a newly authenticated client.
+     *
+     * @param key the client's key
+     * @param ictx the initial context gotten
+     */
+    public void put( ClientKey key, InitialContext ictx )
+    {
+        key.deleteObserver( keyObserver );  // remove first just in case
+        key.addObserver( keyObserver );
+        synchronized( contexts )
+        {
+            contexts.put( key, ictx );
+        }
+    }
+
+
+    /**
+     * Removes the state mapping a JNDI initial context for the client's key.
+     *
+     * @param key the client's key
+     */
+    public void remove( ClientKey key )
+    {
+        key.deleteObserver( keyObserver );
+        synchronized( contexts )
+        {
+            contexts.remove( key );
+        }
+    }
+
+
+    /**
+     * A key expiration observer.
+     */
+    class KeyExpirationObserver implements Observer
+    {
+        /**
+         * This is called whenever the client's key expires. We react by removing
+         * the entry if any of the client's in our InitialContext registry.
+         *
+         * @param o the ClientKey that has expired
+         * @param arg will be null
+         */
+        public void update( Observable o, Object arg )
+        {
+            // cast just to make sure
+            ClientKey key = ( ClientKey ) o;
+            key.deleteObserver( keyObserver );
+            synchronized( contexts )
+            {
+                contexts.remove( key );
+            }
+        }
+    }
+}

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java
Tue Nov  2 21:45:52 2004
@@ -20,8 +20,6 @@
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractNoReplyHandler;
 
-import org.apache.ldap.common.NotImplementedException;
-
 
 /**
  * A no reply protocol handler implementation for LDAP {@link
@@ -34,6 +32,6 @@
 {
     public void handle( ClientKey key, Object request )
     {
-        throw new NotImplementedException( "handle in org.apache.eve.protocol.UnbindHandler
not implemented!" );
+        SessionRegistry.getSingleton( null ).remove( key );
     }
 }

Mime
View raw message