* - 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 )
{
LdapResult result = req.getResultResponse().getLdapResult();
LOG.debug( "Handling modify dn request while ignoring referrals: {}", 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.setDiagnosticMessage( msg );
session.getIoSession().write( req.getResultResponse() );
return;
}
try
{
SchemaManager schemaManager = session.getCoreSession().getDirectoryService().getSchemaManager();
Dn newRdn = new Dn( schemaManager, req.getNewRdn().getName() );
Dn oldRdn = new Dn( schemaManager, req.getName().getRdn().getName() );
boolean rdnChanged = req.getNewRdn() != null &&
!newRdn.getNormName().equals( oldRdn.getNormName() );
CoreSession coreSession = session.getCoreSession();
if ( rdnChanged )
{
if ( req.getNewSuperior() != null )
{
coreSession.moveAndRename( req );
}
else
{
coreSession.rename( req );
}
}
else if ( req.getNewSuperior() != null )
{
req.setNewRdn( null );
coreSession.move( req );
}
else
{
result.setDiagnosticMessage( "Attempt to move entry onto itself." );
result.setResultCode( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
result.setMatchedDn( req.getName() );
session.getIoSession().write( req.getResultResponse() );
return;
}
result.setResultCode( ResultCodeEnum.SUCCESS );
session.getIoSession().write( req.getResultResponse() );
}
catch ( Exception e )
{
handleException( session, req, e );