directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r109649 - in incubator/directory/eve/trunk: eve/src/java/org/apache/eve protocol/src/java/org/apache/eve/protocol
Date Fri, 03 Dec 2004 08:16:52 GMT
Author: akarasulu
Date: Fri Dec  3 00:16:51 2004
New Revision: 109649

URL: http://svn.apache.org/viewcvs?view=rev&rev=109649
Log:
Changes ...

 o cleaned up exception handling in request handlers by
   -> first trying to check if an exception is an LdapException with ResultCode
   -> next taking an educated guess
 o we renamed the get/put methods to be getInitialLdapContext et. cetera
 o now we create a new initial context for anonymous operations as anonymous 
   binds 
 o fixed the bind code to actually use passwords now 
 o cleaned up the EveMain 
 
These changes fix the following issues ...

 -> http://nagoya.apache.org/jira/browse/DIREVE-95
 -> http://nagoya.apache.org/jira/browse/DIREVE-96



Modified:
   incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.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/CompareHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
   incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java

Modified: incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java&r1=109648&p2=incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java	(original)
+++ incubator/directory/eve/trunk/eve/src/java/org/apache/eve/EveMain.java	Fri Dec  3 00:16:51
2004
@@ -79,11 +79,9 @@
         env.setProperty( Context.PROVIDER_URL, "ou=system" );
         env.setProperty( Context.INITIAL_CONTEXT_FACTORY, "org.apache.eve.jndi.EveContextFactory"
);
 
-        InitialDirContext ctx;
-
         try
         {
-            ctx = new InitialDirContext( env );
+            new InitialDirContext( env );
         }
         catch ( NamingException e )
         {
@@ -104,7 +102,7 @@
                 try
                 {
                     env.setProperty( EveContextFactory.SYNC_OP_ENV, "true" );
-                    ctx = new InitialDirContext( env );
+                    new InitialDirContext( env );
                 }
                 catch ( NamingException e )
                 {

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/AddHandler.java
Fri Dec  3 00:16:51 2004
@@ -17,15 +17,16 @@
 package org.apache.eve.protocol;
 
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
-import javax.naming.directory.DirContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.LdapContext;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
 import org.apache.ldap.common.message.*;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -41,11 +42,12 @@
         AddRequest req = ( AddRequest ) request;
         AddResponse resp = new AddResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
 
         try
         {
-            DirContext ctx = ( DirContext ) ictx.lookup( "" );
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
+            LdapContext ctx = ( LdapContext ) ictx.lookup( "" );
             ctx.createSubcontext( req.getName(), req.getEntry() );
         }
         catch ( NamingException e )
@@ -53,7 +55,16 @@
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
-            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/BindHandler.java&r2=109649
==============================================================================
--- 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
Fri Dec  3 00:16:51 2004
@@ -19,14 +19,16 @@
 
 import java.util.Hashtable;
 
-import javax.naming.InitialContext;
+import javax.naming.Context;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
 import org.apache.ldap.common.message.*;
 import org.apache.ldap.common.util.ExceptionUtils;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -37,45 +39,64 @@
  */
 public class BindHandler extends AbstractSingleReplyHandler
 {
+    private static final Control[] EMPTY = new Control[0];
+
+
     /**
      * @see org.apache.seda.protocol.SingleReplyHandler#handle(ClientKey,Object)
      */
     public Object handle( ClientKey key, Object request )
     {
+        InitialLdapContext ictx;
         BindRequest req = ( BindRequest ) request;
         BindResponse resp = new BindResponseImpl( req.getMessageId() );
+        LdapResult result = new LdapResultImpl( resp );
+        resp.setLdapResult( result );
+        Hashtable env = SessionRegistry.getSingleton().getEnvironment();
 
+        // if the bind request is not simple then we freak: no strong auth yet
         if ( ! req.isSimple() )
         {
-            resp.setLdapResult( new LdapResultImpl( resp ) );
-            resp.getLdapResult().setResultCode( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
-            resp.getLdapResult().setErrorMessage( "Only simple binds currently supported"
);
+            result.setResultCode( ResultCodeEnum.AUTHMETHODNOTSUPPORTED );
+            result.setErrorMessage( "Only simple binds currently supported" );
             return resp;
         }
 
+        // clone the environment first then add the required security settings
         String dn = req.getName();
         byte[] creds = req.getCredentials();
-        Hashtable env = SessionRegistry.getSingleton().getEnvironment();
-        InitialContext ictx;
 
+        env = ( Hashtable ) env.clone();
+        env.put( Context.SECURITY_PRINCIPAL, dn );
+        env.put( Context.SECURITY_CREDENTIALS, creds );
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" );
+
+        Control[] connCtls = ( Control[] ) req.getControls().toArray( EMPTY );
         try
         {
-            ictx = new InitialContext( env );
+            ictx = new InitialLdapContext( env, connCtls );
         }
         catch( NamingException e )
         {
-            resp.setLdapResult( new LdapResultImpl( resp ) );
-            resp.getLdapResult().setResultCode( ResultCodeEnum.OTHER );
+            if ( e instanceof LdapException )
+            {
+                result.setResultCode( ( ( LdapException ) e ).getResultCode() );
+            }
+            else
+            {
+                result.setResultCode( ResultCodeEnum.getBestEstimate( e,
+                        req.getType() ) );
+            }
+
             String msg = "Bind failure:\n" + ExceptionUtils.getStackTrace( e );
             msg += "\n\nBindRequest = \n" + req.toString();
-            resp.getLdapResult().setErrorMessage( msg );
+            result.setErrorMessage( msg );
             return resp;
         }
 
-        SessionRegistry.getSingleton().put( key, ictx );
-        resp.setLdapResult( new LdapResultImpl( resp ) );
-        resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-        resp.getLdapResult().setMatchedDn( req.getName() );
+        SessionRegistry.getSingleton().setInitialLdapContext( key, ictx );
+        result.setResultCode( ResultCodeEnum.SUCCESS );
+        result.setMatchedDn( req.getName() );
         return resp;
     }
 }

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/CompareHandler.java
Fri Dec  3 00:16:51 2004
@@ -17,8 +17,8 @@
 package org.apache.eve.protocol;
 
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.Attribute;
 
@@ -27,6 +27,7 @@
 
 import org.apache.ldap.common.util.ExceptionUtils;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -45,10 +46,11 @@
         CompareRequest req = ( CompareRequest ) request;
         CompareResponse resp = new CompareResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
 
         try
         {
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             Attribute attr = ctx.getAttributes( req.getName() ).get( req.getAttributeId()
);
 
@@ -70,7 +72,16 @@
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
-            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/DeleteHandler.java
Fri Dec  3 00:16:51 2004
@@ -17,16 +17,16 @@
 package org.apache.eve.protocol;
 
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 import javax.naming.directory.DirContext;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
-import org.apache.ldap.common.NotImplementedException;
 import org.apache.ldap.common.util.ExceptionUtils;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -45,10 +45,11 @@
         DeleteRequest req = ( DeleteRequest ) request;
         DeleteResponse resp = new DeleteResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
 
         try
         {
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             ctx.destroySubcontext( req.getName() );
         }
@@ -57,7 +58,16 @@
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
-            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Fri Dec  3 00:16:51 2004
@@ -17,8 +17,8 @@
 package org.apache.eve.protocol;
 
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 import javax.naming.directory.DirContext;
 
 import org.apache.seda.listener.ClientKey;
@@ -27,6 +27,7 @@
 import org.apache.ldap.common.name.LdapName;
 import org.apache.ldap.common.util.ExceptionUtils;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -45,10 +46,11 @@
         ModifyDnRequest req = ( ModifyDnRequest ) request;
         ModifyDnResponse resp = new ModifyDnResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
 
         try
         {
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
             ctx.addToEnvironment( "java.naming.ldap.deleteRDN", deleteRDN );
@@ -82,7 +84,16 @@
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
-            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/ModifyHandler.java
Fri Dec  3 00:16:51 2004
@@ -17,17 +17,17 @@
 package org.apache.eve.protocol;
 
 
-import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractSingleReplyHandler;
 
-import org.apache.ldap.common.NotImplementedException;
 import org.apache.ldap.common.util.ExceptionUtils;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -47,10 +47,11 @@
         ModifyRequest req = ( ModifyRequest ) request;
         ModifyResponse resp = new ModifyResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
 
         try
         {
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
             DirContext ctx = ( DirContext ) ictx.lookup( "" );
             Object[] mods = req.getModificationItems().toArray( EMPTY );
             ctx.modifyAttributes( req.getName(), ( ModificationItem[] ) mods );
@@ -60,7 +61,16 @@
             String msg = "failed to add entry " + req.getName() + ":\n";
             msg += ExceptionUtils.getStackTrace( e );
             ResultCodeEnum code;
-            code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
 

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SearchHandler.java
Fri Dec  3 00:16:51 2004
@@ -19,11 +19,10 @@
 
 import java.util.*;
 
-import javax.naming.InitialContext;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.Name;
 import javax.naming.ldap.LdapContext;
+import javax.naming.ldap.InitialLdapContext;
 import javax.naming.directory.SearchResult;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.Attribute;
@@ -34,7 +33,7 @@
 import org.apache.ldap.common.util.ExceptionUtils;
 import org.apache.ldap.common.util.ArrayUtils;
 import org.apache.ldap.common.message.*;
-import org.apache.ldap.common.name.LdapName;
+import org.apache.ldap.common.exception.LdapException;
 
 
 /**
@@ -58,7 +57,6 @@
     {
         LdapContext ctx;
         SearchRequest req = ( SearchRequest ) request;
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
         NamingEnumeration list = null;
 
         // check the attributes to see if a referral's ref attribute is included
@@ -86,6 +84,8 @@
 
         try
         {
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, true );
             ctx = ( LdapContext ) ictx.lookup( "" );
             ctx.addToEnvironment( DEREFALIASES_KEY, req.getDerefAliases().getName() );
             list = ctx.search( req.getBase(), req.getFilter().toString(), controls );
@@ -108,7 +108,17 @@
             String msg = "failed on search operation:\n" + req + "\n";
             msg += ExceptionUtils.getStackTrace( e );
             SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );
-            ResultCodeEnum rc = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            ResultCodeEnum rc = null;
+
+            if ( e instanceof LdapException )
+            {
+                rc = ( ( LdapException ) e ).getResultCode() ;
+            }
+            else
+            {
+                rc = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
             resp.setLdapResult( new LdapResultImpl( resp ) );
             resp.getLdapResult().setResultCode( rc );
             resp.getLdapResult().setErrorMessage( msg );
@@ -133,7 +143,17 @@
         String msg = "failed on search operation:\n" + req + "\n";
         msg += ExceptionUtils.getStackTrace( e );
         SearchResponseDone resp = new SearchResponseDoneImpl( req.getMessageId() );
-        ResultCodeEnum rc = ResultCodeEnum.getBestEstimate( e, req.getType() );
+        ResultCodeEnum rc = null;
+
+        if ( e instanceof LdapException )
+        {
+            rc = ( ( LdapException ) e ).getResultCode() ;
+        }
+        else
+        {
+            rc = ResultCodeEnum.getBestEstimate( e, req.getType() );
+        }
+
         resp.setLdapResult( new LdapResultImpl( resp ) );
         resp.getLdapResult().setResultCode( rc );
         resp.getLdapResult().setErrorMessage( msg );

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java&r2=109649
==============================================================================
--- incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
(original)
+++ incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/SessionRegistry.java
Fri Dec  3 00:16:51 2004
@@ -18,8 +18,11 @@
 
 
 import java.util.*;
-import javax.naming.InitialContext;
 import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.ldap.Control;
+import javax.naming.directory.InitialDirContext;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.event.EventRouter;
@@ -109,18 +112,36 @@
 
     /**
      * Gets the InitialContext to the root of the system that was gotten for
-     * client.
+     * client.  If the context is not present then there was no bind operation
+     * that set it.  Hence this operation requesting the IC is anonymous.
      *
      * @param key the client's key
+     * @param connCtls connection controls if any to use if creating anon context
+     * @param allowAnonymous true if anonymous requests will create anonymous
+     * InitialContext if one is not present for the operation
      * @return the InitialContext or null
      */
-    public InitialContext get( ClientKey key )
+    public InitialLdapContext getInitialLdapContext( ClientKey key,
+                                                     Control[] connCtls,
+                                                     boolean allowAnonymous )
+            throws NamingException
     {
+        InitialLdapContext ictx = null;
+
         key.addObserver( keyObserver );
+
         synchronized( contexts )
         {
-            return ( InitialContext ) contexts.get( key );
+            ictx = ( InitialLdapContext ) contexts.get( key );
+        }
+
+        if ( ictx == null && allowAnonymous )
+        {
+            ictx = new InitialLdapContext( env, connCtls );
+            // @todo log something with a monitor here eventually!
         }
+
+        return ictx;
     }
 
 
@@ -130,7 +151,7 @@
      * @param key the client's key
      * @param ictx the initial context gotten
      */
-    public void put( ClientKey key, InitialContext ictx )
+    public void setInitialLdapContext( ClientKey key, InitialDirContext ictx )
     {
         key.deleteObserver( keyObserver );  // remove first just in case
         key.addObserver( keyObserver );

Modified: incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java?view=diff&rev=109649&p1=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java&r1=109648&p2=incubator/directory/eve/trunk/protocol/src/java/org/apache/eve/protocol/UnbindHandler.java&r2=109649
==============================================================================
--- 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
Fri Dec  3 00:16:51 2004
@@ -19,6 +19,7 @@
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
 
 import org.apache.seda.listener.ClientKey;
 import org.apache.seda.protocol.AbstractNoReplyHandler;
@@ -35,12 +36,16 @@
 {
     public void handle( ClientKey key, Object request )
     {
-        InitialContext ictx = SessionRegistry.getSingleton().get( key );
         SessionRegistry registry = SessionRegistry.getSingleton();
 
         try
         {
-            ictx.close();
+            InitialLdapContext ictx = SessionRegistry.getSingleton()
+                    .getInitialLdapContext( key, null, false );
+            if ( ictx != null )
+            {
+                ictx.close();
+            }
             registry.terminateSession( key );
             registry.remove( key );
         }

Mime
View raw message