directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r328303 - in /directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support: AddHandler.java BindHandler.java
Date Tue, 25 Oct 2005 07:50:06 GMT
Author: elecharny
Date: Tue Oct 25 00:50:01 2005
New Revision: 328303

URL: http://svn.apache.org/viewcvs?rev=328303&view=rev
Log:
Updated the resultMessage

Modified:
    directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/AddHandler.java
    directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/BindHandler.java

Modified: directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/AddHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/AddHandler.java?rev=328303&r1=328302&r2=328303&view=diff
==============================================================================
--- directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/AddHandler.java
(original)
+++ directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/AddHandler.java
Tue Oct 25 00:50:01 2005
@@ -41,31 +41,37 @@
  */
 public class AddHandler implements MessageHandler
 {
-    private static final Logger LOG = LoggerFactory.getLogger( AddHandler.class );
+    private static final Logger log = LoggerFactory.getLogger( AddHandler.class );
 
     public void messageReceived( ProtocolSession session, Object request )
     {
         AddRequest req = ( AddRequest ) request;
+        
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Received a Add message : " + req.toString() );
+        }
+
         AddResponse resp = new AddResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
 
         try
         {
             LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session, null,
true );
-            ctx.createSubcontext( req.getName(), req.getEntry() );
+            ctx.createSubcontext( req.getEntry(), req.getAttributes() );
         }
         catch( NamingException e )
         {
-            String msg = "failed to add entry " + req.getName();
+            String msg = "failed to add entry " + req.getEntry();
 
-            if ( LOG.isDebugEnabled() )
+            if ( log.isDebugEnabled() )
             {
                 msg += ":\n" + ExceptionUtils.getStackTrace( e );
             }
 
             ResultCodeEnum code;
 
-            if( e instanceof LdapException )
+            if ( e instanceof LdapException )
             {
                 code = ( ( LdapException ) e ).getResultCode();
             }
@@ -76,7 +82,12 @@
 
             resp.getLdapResult().setResultCode( code );
             resp.getLdapResult().setErrorMessage( msg );
-            if( e.getResolvedName() != null )
+            
+            if ( ( e.getResolvedName() != null ) &&
+                 ( ( code == ResultCodeEnum.NOSUCHOBJECT ) ||
+                   ( code == ResultCodeEnum.ALIASPROBLEM ) ||
+                   ( code == ResultCodeEnum.INVALIDDNSYNTAX ) ||
+                   ( code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM ) ) )
             {
                 resp.getLdapResult().setMatchedDn(
                         e.getResolvedName().toString() );
@@ -87,7 +98,6 @@
         }
 
         resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-        resp.getLdapResult().setMatchedDn( req.getName() );
         session.write( resp );
     }
 }

Modified: directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/BindHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/BindHandler.java?rev=328303&r1=328302&r2=328303&view=diff
==============================================================================
--- directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/BindHandler.java
(original)
+++ directory/protocol-providers/ldap/branches/protocol-ldap-utf8/src/main/java/org/apache/ldap/server/protocol/support/BindHandler.java
Tue Oct 25 00:50:01 2005
@@ -25,6 +25,8 @@
 import javax.naming.ldap.LdapContext;
 import javax.naming.spi.InitialContextFactory;
 
+import org.apache.asn1new.util.StringUtils;
+import org.apache.asn1new.util.StringUtilsTest;
 import org.apache.ldap.common.exception.LdapException;
 import org.apache.ldap.common.message.BindRequest;
 import org.apache.ldap.common.message.BindResponse;
@@ -52,7 +54,7 @@
  */
 public class BindHandler implements MessageHandler
 {
-    private static final Logger LOG = LoggerFactory.getLogger( BindHandler.class );
+    private static final Logger log = LoggerFactory.getLogger( BindHandler.class );
     private static final Control[] EMPTY = new Control[0];
 
 
@@ -66,6 +68,7 @@
 
         Hashtable env = SessionRegistry.getSingleton().getEnvironment();
         StartupConfiguration cfg = ( StartupConfiguration ) Configuration.toConfiguration(
env );
+        
         // if the bind request is not simple then we freak: no strong auth yet
         if ( ! req.isSimple() )
         {
@@ -77,7 +80,7 @@
 
         boolean allowAnonymousBinds = cfg.isAllowAnonymousAccess();
         boolean emptyCredentials = req.getCredentials() == null || req.getCredentials().length
== 0;
-        boolean emptyDn = req.getName() == null || req.getName().length() == 0;
+        boolean emptyDn = StringUtils.isEmpty( req.getName() );
 
         if ( emptyCredentials && emptyDn && ! allowAnonymousBinds )
         {
@@ -89,8 +92,7 @@
         }
 
         // clone the environment first then add the required security settings
-
-        String dn = req.getName();
+        String dn = ( emptyDn ? "" : req.getName() );
 
         byte[] creds = req.getCredentials();
 
@@ -121,25 +123,36 @@
         }
         catch( NamingException e )
         {
+            ResultCodeEnum code;
+            
             if ( e instanceof LdapException )
             {
-                result.setResultCode( ( ( LdapException ) e ).getResultCode() );
+                code = ( ( LdapException ) e ).getResultCode();
+                result.setResultCode( code );
             }
             else
             {
-                result.setResultCode( ResultCodeEnum.getBestEstimate( e,
-                        req.getType() ) );
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+                result.setResultCode( code );
             }
 
             String msg = "Bind failed";
 
-            if ( LOG.isDebugEnabled() )
+            if ( log.isDebugEnabled() )
             {
                 msg += ":\n" + ExceptionUtils.getStackTrace( e );
                 msg += "\n\nBindRequest = \n" + req.toString();
             }
 
-
+            if ( ( e.getResolvedName() != null ) &&
+                    ( ( code == ResultCodeEnum.NOSUCHOBJECT ) ||
+                      ( code == ResultCodeEnum.ALIASPROBLEM ) ||
+                      ( code == ResultCodeEnum.INVALIDDNSYNTAX ) ||
+                      ( code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM ) ) )
+            {
+                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+            }
+            
             result.setErrorMessage( msg );
             session.write( resp );
             return;
@@ -147,7 +160,6 @@
 
         SessionRegistry.getSingleton().setLdapContext( session, ctx );
         result.setResultCode( ResultCodeEnum.SUCCESS );
-        result.setMatchedDn( req.getName() );
         session.write( resp );
     }
 }



Mime
View raw message