You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/06/08 07:41:31 UTC

svn commit: r664450 - in /directory/apacheds/branches/bigbang: core/src/main/java/org/apache/directory/server/core/ core/src/main/java/org/apache/directory/server/core/interceptor/context/ protocol-newldap/src/main/java/org/apache/directory/server/newl...

Author: akarasulu
Date: Sat Jun  7 22:41:30 2008
New Revision: 664450

URL: http://svn.apache.org/viewvc?rev=664450&view=rev
Log:
adding new ModifyDnRequest handler and integrating it into the LdapServer

Added:
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java   (with props)
Modified:
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
    directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java
    directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapServer.java

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java?rev=664450&r1=664449&r2=664450&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java Sat Jun  7 22:41:30 2008
@@ -371,20 +371,25 @@
 
     public void move( ModifyDnRequest modifyDnRequest ) throws Exception
     {
-        directoryService.getOperationManager().move( new MoveOperationContext( this, modifyDnRequest ) );
+        MoveOperationContext opContext = new MoveOperationContext( this, modifyDnRequest );
+        directoryService.getOperationManager().move( opContext );
+        modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
     }
 
 
     public void moveAndRename( ModifyDnRequest modifyDnRequest ) throws Exception
     {
-        directoryService.getOperationManager().moveAndRename( 
-            new MoveAndRenameOperationContext( this, modifyDnRequest ) );
+        MoveAndRenameOperationContext opContext = new MoveAndRenameOperationContext( this, modifyDnRequest );
+        directoryService.getOperationManager().moveAndRename( opContext );
+        modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
     }
 
 
     public void rename( ModifyDnRequest modifyDnRequest ) throws Exception
     {
-        directoryService.getOperationManager().rename( new RenameOperationContext( this, modifyDnRequest ) );
+        RenameOperationContext opContext = new RenameOperationContext( this, modifyDnRequest );
+        directoryService.getOperationManager().rename( opContext );
+        modifyDnRequest.getResultResponse().addAll( opContext.getResponseControls() );
     }
 
 

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java?rev=664450&r1=664449&r2=664450&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java Sat Jun  7 22:41:30 2008
@@ -73,6 +73,8 @@
         {
             throw new IllegalArgumentException( modifyDnRequest + " represents a move and rename operation." );
         }
+        
+        super.setReferralHandlingMode( modifyDnRequest );
     }
 
 

Modified: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapServer.java?rev=664450&r1=664449&r2=664450&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapServer.java (original)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/LdapServer.java Sat Jun  7 22:41:30 2008
@@ -51,6 +51,7 @@
 import org.apache.directory.server.newldap.handlers.NewBindHandler;
 import org.apache.directory.server.newldap.handlers.NewCompareHandler;
 import org.apache.directory.server.newldap.handlers.NewDeleteHandler;
+import org.apache.directory.server.newldap.handlers.NewModifyDnHandler;
 import org.apache.directory.server.newldap.handlers.SearchHandler;
 import org.apache.directory.server.newldap.handlers.UnbindHandler;
 import org.apache.directory.server.newldap.handlers.bind.*;
@@ -192,7 +193,7 @@
     private LdapRequestHandler<DeleteRequest> deleteHandler;
     private ExtendedHandler extendedHandler;
     private ModifyHandler modifyHandler;
-    private ModifyDnHandler modifyDnHandler;
+    private LdapRequestHandler<ModifyDnRequest> modifyDnHandler;
     private SearchHandler searchHandler;
     private UnbindHandler unbindHandler;
 
@@ -279,7 +280,7 @@
         
         if ( getModifyDnHandler() == null )
         {
-            setModifyDnHandler( new DefaultModifyDnHandler() );
+            setModifyDnHandler( new NewModifyDnHandler() );
         }
         
         if ( getSearchHandler() == null )
@@ -971,12 +972,11 @@
     }
 
 
-    public void setModifyDnHandler( ModifyDnHandler modifyDnHandler )
+    public void setModifyDnHandler( LdapRequestHandler<ModifyDnRequest> modifyDnHandler )
     {
         this.handler.removeMessageHandler( ModifyDnRequest.class );
         this.modifyDnHandler = modifyDnHandler;
-        this.modifyDnHandler.setProtocolProvider( this );
-        //noinspection unchecked
+        this.modifyDnHandler.setLdapServer( this );
         this.handler.addMessageHandler( ModifyDnRequest.class, this.modifyDnHandler );
     }
 

Added: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java?rev=664450&view=auto
==============================================================================
--- directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java (added)
+++ directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java Sat Jun  7 22:41:30 2008
@@ -0,0 +1,158 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.directory.server.newldap.handlers;
+
+ 
+import javax.naming.NamingException;
+import javax.naming.ReferralException;
+
+import org.apache.directory.server.newldap.LdapSession;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.LdapResult;
+import org.apache.directory.shared.ldap.message.ModifyDnRequest;
+import org.apache.directory.shared.ldap.message.ReferralImpl;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.ExceptionUtils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A single reply handler for {@link ModifyDnRequest}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 664302 $
+ */
+public class NewModifyDnHandler extends LdapRequestHandler<ModifyDnRequest>
+{
+    private static final Logger LOG = LoggerFactory.getLogger( NewModifyDnHandler.class );
+
+    /** Speedup for logs */
+    private static final boolean IS_DEBUG = LOG.isDebugEnabled();
+
+    
+    /**
+     * Deal with a ModifyDN request received from a client.
+     *
+     * A ModifyDN operation has more than one semantic, depending on its parameters.
+     *
+     * In any case, the first argument is the DN entry to be changed. We then
+     * have the new relative DN for this entry.
+     *
+     * Two other arguments can be provided :
+     * - deleteOldRdn : if the old RDN attributes should be removed from the
+     * new entry or not (for instance, if the old RDN was cn=acme, and the new
+     * one is sn=acme, then we may have to remove the cn: acme from the attributes
+     * list)
+     * - newSuperior : this is a move operation. The entry is removed from its
+     * current location, and created in the new one.
+     */
+    public void handle( LdapSession session, ModifyDnRequest req ) throws Exception
+    {
+        LdapResult result = req.getResultResponse().getLdapResult();
+
+        if ( IS_DEBUG )
+        {
+            LOG.debug( "Received: ", req );
+        }
+
+        if ( req.getName().isEmpty() )
+        {
+            // it is not allowed to modify the name of the Root DSE
+            String msg = "Modify DN is not allowed on Root DSE.";
+            result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
+            result.setErrorMessage( msg );
+            session.getIoSession().write( req.getResultResponse() );
+            return;
+        }
+        
+        try
+        {
+            if ( req.getNewRdn() != null )
+            {
+                if ( req.getNewSuperior() != null )
+                {
+                    session.getCoreSession().moveAndRename( req );
+                }
+                else
+                {
+                    session.getCoreSession().rename( req );
+                }
+            }
+            else
+            {
+                session.getCoreSession().move( req );
+            }
+
+            result.setResultCode( ResultCodeEnum.SUCCESS );
+            session.getIoSession().write( req.getResultResponse() );
+        }
+        catch ( ReferralException e )
+        {
+            ReferralImpl refs = new ReferralImpl();
+            result.setReferral( refs );
+            result.setResultCode( ResultCodeEnum.REFERRAL );
+            result.setErrorMessage( "Encountered referral attempting to handle modifyDn request." );
+            result.setMatchedDn( ( LdapDN ) e.getResolvedName() );
+
+            do
+            {
+                refs.addLdapUrl( ( String ) e.getReferralInfo() );
+            }
+            while ( e.skipReferral() );
+
+            session.getIoSession().write( req.getResultResponse() );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to modify DN of entry " + req.getName() + ": " + e.getMessage();
+
+            if ( IS_DEBUG )
+            {
+                msg += ":\n" + ExceptionUtils.getStackTrace( e );
+            }
+
+            ResultCodeEnum code;
+
+            if ( e instanceof LdapException )
+            {
+                code = ( ( LdapException ) e ).getResultCode();
+            }
+            else
+            {
+                code = ResultCodeEnum.getBestEstimate( e, req.getType() );
+            }
+
+            result.setResultCode( code );
+            result.setErrorMessage( msg );
+
+            if ( ( e.getResolvedName() != null )
+                && ( ( code == ResultCodeEnum.NO_SUCH_OBJECT ) || ( code == ResultCodeEnum.ALIAS_PROBLEM )
+                    || ( code == ResultCodeEnum.INVALID_DN_SYNTAX ) || ( code == ResultCodeEnum.ALIAS_DEREFERENCING_PROBLEM ) ) )
+            {
+                result.setMatchedDn( (LdapDN)e.getResolvedName() );
+            }
+
+            session.getIoSession().write( req.getResultResponse() );
+        }
+    }
+}
\ No newline at end of file

Propchange: directory/apacheds/branches/bigbang/protocol-newldap/src/main/java/org/apache/directory/server/newldap/handlers/NewModifyDnHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native