directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szoer...@apache.org
Subject svn commit: r354207 - /directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/support/ModifyDnHandler.java
Date Mon, 05 Dec 2005 22:20:56 GMT
Author: szoerner
Date: Mon Dec  5 14:20:52 2005
New Revision: 354207

URL: http://svn.apache.org/viewcvs?rev=354207&view=rev
Log:
Add a test for empty names in order to prevent clients to rename Root DSE. This is due to
DIREVE-307. 

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

Modified: directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/support/ModifyDnHandler.java
URL: http://svn.apache.org/viewcvs/directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/support/ModifyDnHandler.java?rev=354207&r1=354206&r2=354207&view=diff
==============================================================================
--- directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/support/ModifyDnHandler.java
(original)
+++ directory/protocol-providers/ldap/trunk/src/main/java/org/apache/ldap/server/protocol/support/ModifyDnHandler.java
Mon Dec  5 14:20:52 2005
@@ -16,11 +16,11 @@
  */
 package org.apache.ldap.server.protocol.support;
 
-
 import javax.naming.NamingException;
 import javax.naming.ldap.LdapContext;
 
 import org.apache.ldap.common.exception.LdapException;
+import org.apache.ldap.common.message.LdapResult;
 import org.apache.ldap.common.message.LdapResultImpl;
 import org.apache.ldap.common.message.ModifyDnRequest;
 import org.apache.ldap.common.message.ModifyDnResponse;
@@ -34,10 +34,10 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
- * A single reply handler for {@link org.apache.ldap.common.message.ModifyDnRequest}s.
- *
+ * A single reply handler for
+ * {@link org.apache.ldap.common.message.ModifyDnRequest}s.
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
@@ -45,79 +45,92 @@
 {
     private static final Logger LOG = LoggerFactory.getLogger( ModifyDnHandler.class );
 
-    public void messageReceived( IoSession session, Object request )
+    public void messageReceived(IoSession session, Object request)
     {
-        ModifyDnRequest req = ( ModifyDnRequest ) request;
+        ModifyDnRequest req = (ModifyDnRequest) request;
         ModifyDnResponse resp = new ModifyDnResponseImpl( req.getMessageId() );
         resp.setLdapResult( new LdapResultImpl( resp ) );
 
-        try
+        System.out.println("req.getName() == [" + req.getName() +"]");
+        if (req.getName() == null || req.getName().length() == 0)
         {
-            LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session, null,
true );
-            String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
-            ctx.addToEnvironment( "java.naming.ldap.deleteRDN", deleteRDN );
+            // it is not allowed to modify the name of the Root DSE
+            
+            String msg = "Modify DN is not allowed on Root DSE.";
 
-            if ( req.isMove() )
+            LdapResult result = resp.getLdapResult();
+            result.setResultCode( ResultCodeEnum.PROTOCOLERROR );
+            result.setErrorMessage( msg );
+            session.write( resp );
+        }
+        else
+        {
+            try
             {
-                LdapName oldDn = new LdapName( req.getName() );
-                LdapName newDn = new LdapName( req.getNewSuperior() );
+                LdapContext ctx = SessionRegistry.getSingleton().getLdapContext( session,
null, true );
+                String deleteRDN = String.valueOf( req.getDeleteOldRdn() );
+                ctx.addToEnvironment( "java.naming.ldap.deleteRDN", deleteRDN );
 
-                if ( req.getNewRdn() != null )
+                if (req.isMove())
                 {
-                    newDn.add( req.getNewRdn() );
+                    LdapName oldDn = new LdapName( req.getName() );
+                    LdapName newDn = new LdapName( req.getNewSuperior() );
+
+                    if (req.getNewRdn() != null)
+                    {
+                        newDn.add( req.getNewRdn() );
+                    }
+                    else
+                    {
+                        newDn.add( oldDn.getRdn() );
+                    }
+
+                    ctx.rename( new LdapName( req.getName() ), newDn );
                 }
                 else
                 {
-                    newDn.add( oldDn.getRdn() );
+                    LdapName newDn = new LdapName( req.getName() );
+                    newDn.remove( newDn.size() - 1 );
+                    newDn.add( req.getNewRdn() );
+                    ctx.rename( new LdapName( req.getName() ), newDn );
                 }
-
-                ctx.rename( new LdapName( req.getName() ), newDn );
             }
-            else
+            catch ( NamingException e )
             {
-                LdapName newDn = new LdapName( req.getName() );
-                newDn.remove( newDn.size() - 1 );
-                newDn.add( req.getNewRdn() );
-                ctx.rename( new LdapName( req.getName() ), newDn );
-            }
-        }
-        catch ( NamingException e )
-        {
-            String msg = "failed to modify DN of entry " + req.getName();
+                String msg = "failed to modify DN of entry " + req.getName();
 
-            if ( LOG.isDebugEnabled() )
-            {
-                msg += ":\n" + ExceptionUtils.getStackTrace( e );
-            }
+                if (LOG.isDebugEnabled())
+                {
+                    msg += ":\n" + ExceptionUtils.getStackTrace( e );
+                }
 
-            ResultCodeEnum code;
-            
-            if ( e instanceof LdapException )
-            {
-                code = ( ( LdapException ) e ).getResultCode() ;
-            }
-            else
-            {
-                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
-            }
+                ResultCodeEnum code;
 
-            resp.getLdapResult().setResultCode( code );
-            resp.getLdapResult().setErrorMessage( msg );
+                if (e instanceof LdapException)
+                {
+                    code = ((LdapException) e).getResultCode();
+                }
+                else
+                {
+                    code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+                }
 
-            if ( ( e.getResolvedName() != null ) &&
-                    ( ( code == ResultCodeEnum.NOSUCHOBJECT ) ||
-                      ( code == ResultCodeEnum.ALIASPROBLEM ) ||
-                      ( code == ResultCodeEnum.INVALIDDNSYNTAX ) ||
-                      ( code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM ) ) )
-            {
-                resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+                resp.getLdapResult().setResultCode( code );
+                resp.getLdapResult().setErrorMessage( msg );
+
+                if ((e.getResolvedName() != null)
+                        && ((code == ResultCodeEnum.NOSUCHOBJECT) || (code == ResultCodeEnum.ALIASPROBLEM)
+                                || (code == ResultCodeEnum.INVALIDDNSYNTAX) || (code == ResultCodeEnum.ALIASDEREFERENCINGPROBLEM)))
+                {
+                    resp.getLdapResult().setMatchedDn( e.getResolvedName().toString() );
+                }
+
+                session.write( resp );
+                return;
             }
 
+            resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
             session.write( resp );
-            return;
         }
-
-        resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
-        session.write( resp );
     }
 }



Mime
View raw message