Modified: directory/apacheds/branches/apacheds-osgi/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=1201362&r1=1201361&r2=1201362&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-osgi/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original) +++ directory/apacheds/branches/apacheds-osgi/interceptors/subtree/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Sat Nov 12 23:58:40 2011 @@ -31,12 +31,12 @@ import org.apache.directory.server.const import org.apache.directory.server.constants.ServerDNConstants; import org.apache.directory.server.core.api.CoreSession; import org.apache.directory.server.core.api.DirectoryService; +import org.apache.directory.server.core.api.InterceptorEnum; import org.apache.directory.server.core.api.LdapPrincipal; import org.apache.directory.server.core.api.entry.ClonedServerEntry; import org.apache.directory.server.core.api.filtering.EntryFilter; import org.apache.directory.server.core.api.filtering.EntryFilteringCursor; import org.apache.directory.server.core.api.interceptor.BaseInterceptor; -import org.apache.directory.server.core.api.interceptor.NextInterceptor; import org.apache.directory.server.core.api.interceptor.context.AddOperationContext; import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext; import org.apache.directory.server.core.api.interceptor.context.ListOperationContext; @@ -111,7 +111,7 @@ public class SubentryInterceptor extends /** A reference to the nexus for direct backend operations */ private PartitionNexus nexus; - + /** An enum used for the entries update */ private enum OperationEnum { @@ -119,7 +119,15 @@ public class SubentryInterceptor extends REMOVE, REPLACE } - + + /** + * Creates a new instance of SubentryInterceptor + */ + public SubentryInterceptor() + { + super( InterceptorEnum.SUBENTRY_INTERCEPTOR ); + } + //------------------------------------------------------------------------------------------- // Search filter methods @@ -179,10 +187,10 @@ public class SubentryInterceptor extends SUBENTRY_OPATTRS = new AttributeType[] { - ACCESS_CONTROL_SUBENTRIES_AT, - SUBSCHEMA_SUBENTRY_AT, - COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT, - TRIGGER_EXECUTION_SUBENTRIES_AT + ACCESS_CONTROL_SUBENTRIES_AT, + SUBSCHEMA_SUBENTRY_AT, + COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT, + TRIGGER_EXECUTION_SUBENTRIES_AT }; ssParser = new SubtreeSpecificationParser( schemaManager ); @@ -321,7 +329,7 @@ public class SubentryInterceptor extends if ( opContext.hasRequestControl( SUBENTRY_CONTROL ) ) { SubentriesDecorator subentriesDecorator = ( SubentriesDecorator ) opContext.getRequestControl( SUBENTRY_CONTROL ); - return ( ( Subentries ) subentriesDecorator.getDecorated() ).isVisible(); + return subentriesDecorator.getDecorated().isVisible(); } return false; @@ -369,7 +377,7 @@ public class SubentryInterceptor extends case REPLACE : modifications = getOperationalModsForReplace( subentryDn, candidate ); break; - */ + */ } LOG.debug( "The entry {} has been evaluated to true for subentry {}", candidate.getDn(), subentryDn ); @@ -415,7 +423,7 @@ public class SubentryInterceptor extends CoreSession session = opContext.getSession(); LookupOperationContext lookupContext = new LookupOperationContext( session, apDn ); lookupContext.setAttrsId( SchemaConstants.ALL_ATTRIBUTES_ARRAY ); - + Entry administrationPoint = directoryService.getPartitionNexus().lookup( lookupContext ); // The administrativeRole AT must exist and not be null @@ -520,7 +528,7 @@ public class SubentryInterceptor extends */ SubentryCache subentryCache = directoryService.getSubentryCache(); SubtreeEvaluator evaluator = directoryService.getEvaluator(); - + for ( Dn subentryDn : subentryCache ) { Dn apDn = subentryDn.getParent(); @@ -583,7 +591,7 @@ public class SubentryInterceptor extends for ( Modification mod : mods ) { if ( mod.getAttribute().getId().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) || - mod.getAttribute().getId().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) ) + mod.getAttribute().getId().equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) ) { switch ( mod.getOperation() ) { @@ -620,8 +628,7 @@ public class SubentryInterceptor extends * Update the list of modifications with a modification associated with a specific * role, if it's requested. */ - private void getOperationalModForReplace( boolean hasRole, AttributeType attributeType, Entry entry, Dn oldDn, Dn newDn, List modifications ) - throws LdapInvalidAttributeValueException + private void getOperationalModForReplace( boolean hasRole, AttributeType attributeType, Entry entry, Dn oldDn, Dn newDn, List modifications ) throws LdapInvalidAttributeValueException { String oldDnStr = oldDn.getNormName(); String newDnStr = newDn.getNormName(); @@ -649,8 +656,7 @@ public class SubentryInterceptor extends * Get the list of modifications to be applied on an entry to inject the operational attributes * associated with the administrative roles. */ - private List getOperationalModsForReplace( Dn oldDn, Dn newDn, Subentry subentry, Entry entry ) - throws Exception + private List getOperationalModsForReplace( Dn oldDn, Dn newDn, Subentry subentry, Entry entry ) throws Exception { List modifications = new ArrayList(); @@ -851,7 +857,7 @@ public class SubentryInterceptor extends /** * {@inheritDoc} */ - public void add( NextInterceptor next, AddOperationContext addContext ) throws LdapException + public void add( AddOperationContext addContext ) throws LdapException { Dn dn = addContext.getDn(); Entry entry = addContext.getEntry(); @@ -862,7 +868,7 @@ public class SubentryInterceptor extends // get the name of the administrative point and its administrativeRole attributes // The AP must be the parent Dn, but we also have to check that the given Dn // is not the rootDSE or a NamingContext - if ( dn.isRootDSE() || isNamingContext( dn ) ) + if ( dn.isRootDse() || isNamingContext( dn ) ) { // Not allowed : we can't get a parent in those cases throw new LdapOtherException( "Cannot find an AdministrativePoint for " + dn ); @@ -896,7 +902,7 @@ public class SubentryInterceptor extends directoryService.getSubentryCache().addSubentry( dn, subentry ); // Now inject the subentry into the backend - next.add( addContext ); + next( addContext ); /* ---------------------------------------------------------------- * Find the baseDn for the subentry and use that to search the tree @@ -966,7 +972,7 @@ public class SubentryInterceptor extends addContext.setEntry( entry ); // Propagate the addition down to the backend. - next.add( addContext ); + next( addContext ); } } @@ -974,7 +980,7 @@ public class SubentryInterceptor extends /** * {@inheritDoc} */ - public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException + public void delete( DeleteOperationContext deleteContext ) throws LdapException { Dn dn = deleteContext.getDn(); Entry entry = deleteContext.getEntry(); @@ -1004,12 +1010,12 @@ public class SubentryInterceptor extends directoryService.getSubentryCache().removeSubentry( dn ); // Now delete the subentry itself - next.delete( deleteContext ); + next( deleteContext ); } else { // TODO : deal with AP removal. - next.delete( deleteContext ); + next( deleteContext ); } } @@ -1017,10 +1023,9 @@ public class SubentryInterceptor extends /** * {@inheritDoc} */ - public EntryFilteringCursor list( NextInterceptor nextInterceptor, ListOperationContext listContext ) - throws LdapException + public EntryFilteringCursor list( ListOperationContext listContext ) throws LdapException { - EntryFilteringCursor cursor = nextInterceptor.list( listContext ); + EntryFilteringCursor cursor = next( listContext ); if ( !isSubentryVisible( listContext ) ) { @@ -1034,7 +1039,7 @@ public class SubentryInterceptor extends /** * {@inheritDoc} */ - public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws LdapException + public void modify( ModifyOperationContext modifyContext ) throws LdapException { Dn dn = modifyContext.getDn(); List modifications = modifyContext.getModItems(); @@ -1086,7 +1091,7 @@ public class SubentryInterceptor extends subentry.setAdministrativeRoles( getSubentryTypes( entry, modifications ) ); directoryService.getSubentryCache().addSubentry( dn, subentry ); - next.modify( modifyContext ); + next( modifyContext ); // search for all entries selected by the old SS and remove references to subentry Dn apName = dn.getParent(); @@ -1118,7 +1123,7 @@ public class SubentryInterceptor extends getOperationalModsForRemove( dn, candidate ) ) ); } } - + subentries.close(); } catch ( Exception e ) @@ -1181,7 +1186,7 @@ public class SubentryInterceptor extends } else { - next.modify( modifyContext ); + next( modifyContext ); if ( !containsSubentryOC ) { @@ -1226,7 +1231,7 @@ public class SubentryInterceptor extends * @param moveContext The context containing all the needed informations to proceed * @throws LdapException If the move failed */ - public void move( NextInterceptor next, MoveOperationContext moveContext ) throws LdapException + public void move( MoveOperationContext moveContext ) throws LdapException { Dn oldDn = moveContext.getDn(); Dn newSuperiorDn = moveContext.getNewSuperior(); @@ -1255,7 +1260,7 @@ public class SubentryInterceptor extends directoryService.getSubentryCache().addSubentry( newName, subentry ); - next.move( moveContext ); + next( moveContext ); subentry = directoryService.getSubentryCache().getSubentry( newName ); @@ -1319,7 +1324,7 @@ public class SubentryInterceptor extends } // Move the entry - next.move( moveContext ); + next( moveContext ); // calculate the new Dn now for use below to modify subentry operational // attributes contained within this regular entry with name changes @@ -1335,7 +1340,10 @@ public class SubentryInterceptor extends } - public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { Dn oldDn = moveAndRenameContext.getDn(); Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn(); @@ -1356,7 +1364,7 @@ public class SubentryInterceptor extends directoryService.getSubentryCache().addSubentry( newName, subentry ); - next.moveAndRename( moveAndRenameContext ); + next( moveAndRenameContext ); subentry = directoryService.getSubentryCache().getSubentry( newName ); @@ -1412,7 +1420,7 @@ public class SubentryInterceptor extends throw new LdapSchemaViolationException( ResultCodeEnum.NOT_ALLOWED_ON_RDN, msg ); } - next.moveAndRename( moveAndRenameContext ); + next( moveAndRenameContext ); // calculate the new Dn now for use below to modify subentry operational // attributes contained within this regular entry with name changes @@ -1427,7 +1435,10 @@ public class SubentryInterceptor extends } - public void rename( NextInterceptor next, RenameOperationContext renameContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void rename( RenameOperationContext renameContext ) throws LdapException { Dn oldDn = renameContext.getDn(); @@ -1447,7 +1458,7 @@ public class SubentryInterceptor extends newName.apply( schemaManager ); directoryService.getSubentryCache().addSubentry( newName, subentry ); - next.rename( renameContext ); + next( renameContext ); subentry = directoryService.getSubentryCache().getSubentry( newName ); ExprNode filter = new PresenceNode( OBJECT_CLASS_AT ); @@ -1502,7 +1513,7 @@ public class SubentryInterceptor extends throw new LdapSchemaViolationException( ResultCodeEnum.NOT_ALLOWED_ON_RDN, msg ); } - next.rename( renameContext ); + next( renameContext ); // calculate the new Dn now for use below to modify subentry operational // attributes contained within this regular entry with name changes @@ -1521,10 +1532,9 @@ public class SubentryInterceptor extends /** * {@inheritDoc} */ - public EntryFilteringCursor search( NextInterceptor nextInterceptor, SearchOperationContext searchContext ) - throws LdapException + public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { - EntryFilteringCursor cursor = nextInterceptor.search( searchContext ); + EntryFilteringCursor cursor = next( searchContext ); // object scope searches by default return subentries if ( searchContext.getScope() == SearchScope.OBJECT ) Propchange: directory/apacheds/branches/apacheds-osgi/interceptors/trigger/ ------------------------------------------------------------------------------ --- svn:mergeinfo (added) +++ svn:mergeinfo Sat Nov 12 23:58:40 2011 @@ -0,0 +1,10 @@ +/directory/apacheds/branches/apacheds-codec-merge/interceptors/trigger:982369-987590 +/directory/apacheds/branches/apacheds-config/interceptors/trigger:1023442-1029077 +/directory/apacheds/branches/apacheds-kerberos-codec-2.0/interceptors/trigger:1040956-1043765 +/directory/apacheds/branches/apacheds-replication/interceptors/trigger:749790-764110 +/directory/apacheds/branches/apacheds-schema/interceptors/trigger:806623-896441 +/directory/apacheds/branches/apacheds-subtree/interceptors/trigger:965203-965686 +/directory/apacheds/branches/milestones/interceptors/trigger:1072812-1075328 +/directory/apacheds/branches/xdbm-refactoring/interceptors/trigger:945827-946347 +/directory/apacheds/trunk/interceptors/trigger:1066126-1067785,1068026-1072718,1072800-1075329,1185681-1201347 +/directory/studio/trunk/interceptors/trigger:1067786-1067997 Modified: directory/apacheds/branches/apacheds-osgi/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-osgi/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java?rev=1201362&r1=1201361&r2=1201362&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-osgi/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java (original) +++ directory/apacheds/branches/apacheds-osgi/interceptors/trigger/src/main/java/org/apache/directory/server/core/trigger/TriggerInterceptor.java Sat Nov 12 23:58:40 2011 @@ -6,16 +6,16 @@ * 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. - * + * under the License. + * */ package org.apache.directory.server.core.trigger; @@ -29,9 +29,9 @@ import java.util.Map; import org.apache.directory.server.core.api.CoreSession; import org.apache.directory.server.core.api.DirectoryService; +import org.apache.directory.server.core.api.InterceptorEnum; import org.apache.directory.server.core.api.entry.ClonedServerEntry; import org.apache.directory.server.core.api.interceptor.BaseInterceptor; -import org.apache.directory.server.core.api.interceptor.NextInterceptor; import org.apache.directory.server.core.api.interceptor.context.AddOperationContext; import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext; import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext; @@ -92,11 +92,20 @@ public class TriggerInterceptor extends private TriggerExecutionAuthorizer triggerExecutionAuthorizer = new SimpleTriggerExecutionAuthorizer(); private StoredProcExecutionManager manager; - + /** The SubentryUtils instance */ private static SubentryUtils subentryUtils; /** + * Creates a new instance of a TriggerInterceptor. + */ + public TriggerInterceptor() + { + super( InterceptorEnum.TRIGGER_INTERCEPTOR ); + } + + + /** * Adds prescriptiveTrigger TriggerSpecificaitons to a collection of * TriggerSpeficaitions by accessing the triggerSpecCache. The trigger * specification cache is accessed for each trigger subentry associated @@ -109,7 +118,7 @@ public class TriggerInterceptor extends * @param dn the normalized distinguished name of the entry * @param entry the target entry that is considered as the trigger source * @throws Exception if there are problems accessing attribute values - * @param proxy the partition nexus proxy + * @param proxy the partition nexus proxy */ private void addPrescriptiveTriggerSpecs( OperationContext opContext, List triggerSpecs, Dn dn, Entry entry ) throws LdapException @@ -131,7 +140,7 @@ public class TriggerInterceptor extends CoreSession session = opContext.getSession(); LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn ); lookupContext.setAttrsId( SchemaConstants.ALL_ATTRIBUTES_ARRAY ); - + entry = directoryService.getPartitionNexus().lookup( lookupContext ); } @@ -196,7 +205,7 @@ public class TriggerInterceptor extends * * @param triggerSpecs the trigger specifications * @param ldapOperation the ldap operation being performed - * @return the set of trigger specs for a trigger action + * @return the set of trigger specs for a trigger action */ public Map> getActionTimeMappedTriggerSpecsForOperation( List triggerSpecs, LdapOperation ldapOperation ) @@ -252,13 +261,16 @@ public class TriggerInterceptor extends manager = new StoredProcExecutionManager( spContainer, spEngineConfigs ); this.enabled = true; // TODO: Get this from the configuration if needed. - + // Init the SubentryUtils instance subentryUtils = new SubentryUtils( directoryService ); } - public void add( NextInterceptor next, AddOperationContext addContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void add( AddOperationContext addContext ) throws LdapException { Dn name = addContext.getDn(); Entry entry = addContext.getEntry(); @@ -266,7 +278,7 @@ public class TriggerInterceptor extends // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.add( addContext ); + next( addContext ); return; } @@ -284,7 +296,7 @@ public class TriggerInterceptor extends Map> triggerMap = getActionTimeMappedTriggerSpecsForOperation( triggerSpecs, LdapOperation.ADD ); - next.add( addContext ); + next( addContext ); triggerSpecCache.subentryAdded( name, entry ); // Fire AFTER Triggers. @@ -293,14 +305,17 @@ public class TriggerInterceptor extends } - public void delete( NextInterceptor next, DeleteOperationContext deleteContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void delete( DeleteOperationContext deleteContext ) throws LdapException { Dn name = deleteContext.getDn(); // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.delete( deleteContext ); + next( deleteContext ); return; } @@ -317,7 +332,7 @@ public class TriggerInterceptor extends Map> triggerMap = getActionTimeMappedTriggerSpecsForOperation( triggerSpecs, LdapOperation.DELETE ); - next.delete( deleteContext ); + next( deleteContext ); triggerSpecCache.subentryDeleted( name, deletedEntry ); @@ -327,12 +342,15 @@ public class TriggerInterceptor extends } - public void modify( NextInterceptor next, ModifyOperationContext modifyContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void modify( ModifyOperationContext modifyContext ) throws LdapException { // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.modify( modifyContext ); + next( modifyContext ); return; } @@ -351,7 +369,7 @@ public class TriggerInterceptor extends Map> triggerMap = getActionTimeMappedTriggerSpecsForOperation( triggerSpecs, LdapOperation.MODIFY ); - next.modify( modifyContext ); + next( modifyContext ); triggerSpecCache.subentryModified( modifyContext, originalEntry ); @@ -361,51 +379,85 @@ public class TriggerInterceptor extends } - public void rename( NextInterceptor next, RenameOperationContext renameContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void move( MoveOperationContext moveContext ) throws LdapException { - Dn name = renameContext.getDn(); - Rdn newRdn = renameContext.getNewRdn(); - boolean deleteOldRn = renameContext.getDeleteOldRdn(); - // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.rename( renameContext ); + next( moveContext ); return; } - // Gather supplementary data. - Entry renamedEntry = ((ClonedServerEntry)renameContext.getEntry()).getClonedEntry(); + Rdn rdn = moveContext.getRdn(); + Dn dn = moveContext.getDn(); + Dn newDn = moveContext.getNewDn(); + Dn oldSuperior = moveContext.getOldSuperior(); + Dn newSuperior = moveContext.getNewSuperior(); - // @TODO : To be completely reviewed !!! - Rdn oldRdn = name.getRdn(); - Dn oldSuperiorDn = name.getParent(); - Dn newSuperiorDn = oldSuperiorDn; - Dn oldDn = name; - Dn newDn = name; - newDn = newDn.add( newRdn ); + // Gather supplementary data. + Entry movedEntry = moveContext.getOriginalEntry(); - StoredProcedureParameterInjector injector = new ModifyDNStoredProcedureParameterInjector( renameContext, - deleteOldRn, oldRdn, newRdn, oldSuperiorDn, newSuperiorDn, oldDn, newDn); + //Rdn newRDN = dn.getRdn(); - // Gather Trigger Specifications which apply to the entry being renamed. - List triggerSpecs = new ArrayList(); - addPrescriptiveTriggerSpecs( renameContext, triggerSpecs, name, renamedEntry ); - addEntryTriggerSpecs( triggerSpecs, renamedEntry ); + StoredProcedureParameterInjector injector = new ModifyDNStoredProcedureParameterInjector( moveContext, false, + rdn, rdn, oldSuperior, newSuperior, dn, newDn ); - Map> triggerMap = getActionTimeMappedTriggerSpecsForOperation( - triggerSpecs, LdapOperation.MODIFYDN_RENAME ); + // Gather Trigger Specifications which apply to the entry being exported. + List exportTriggerSpecs = new ArrayList(); + addPrescriptiveTriggerSpecs( moveContext, exportTriggerSpecs, dn, movedEntry ); + addEntryTriggerSpecs( exportTriggerSpecs, movedEntry ); - next.rename( renameContext ); - triggerSpecCache.subentryRenamed( name, newDn); + // Get the entry again without operational attributes + // because access control subentry operational attributes + // will not be valid at the new location. + // This will certainly be fixed by the SubentryInterceptor, + // but after this service. + CoreSession session = moveContext.getSession(); + LookupOperationContext lookupContext = new LookupOperationContext( session, dn, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY ); + + Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext ); + + // As the target entry does not exist yet and so + // its subentry operational attributes are not there, + // we need to construct an entry to represent it + // at least with minimal requirements which are object class + // and access control subentry operational attributes. + Entry fakeImportedEntry = subentryUtils.getSubentryAttributes( newDn, importedEntry ); + + for ( Attribute attribute : importedEntry ) + { + fakeImportedEntry.put( attribute ); + } + + // Gather Trigger Specifications which apply to the entry being imported. + // Note: Entry Trigger Specifications are not valid for Import. + List importTriggerSpecs = new ArrayList(); + addPrescriptiveTriggerSpecs( moveContext, importTriggerSpecs, newDn, fakeImportedEntry ); + + Map> exportTriggerMap = getActionTimeMappedTriggerSpecsForOperation( + exportTriggerSpecs, LdapOperation.MODIFYDN_EXPORT ); + + Map> importTriggerMap = getActionTimeMappedTriggerSpecsForOperation( + importTriggerSpecs, LdapOperation.MODIFYDN_IMPORT ); + + next( moveContext ); + triggerSpecCache.subentryRenamed( dn, newDn ); // Fire AFTER Triggers. - List afterTriggerSpecs = triggerMap.get( ActionTime.AFTER ); - executeTriggers( renameContext, afterTriggerSpecs, injector ); + List afterExportTriggerSpecs = exportTriggerMap.get( ActionTime.AFTER ); + List afterImportTriggerSpecs = importTriggerMap.get( ActionTime.AFTER ); + executeTriggers( moveContext, afterExportTriggerSpecs, injector ); + executeTriggers( moveContext, afterImportTriggerSpecs, injector ); } - public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException + /** + * {@inheritDoc} + */ + public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { Dn oldDn = moveAndRenameContext.getDn(); Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn(); @@ -415,11 +467,11 @@ public class TriggerInterceptor extends // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.moveAndRename( moveAndRenameContext ); + next( moveAndRenameContext ); return; } - // Gather supplementary data. + // Gather supplementary data. Entry movedEntry = moveAndRenameContext.getOriginalEntry(); Rdn oldRdn = oldDn.getRdn(); @@ -468,7 +520,7 @@ public class TriggerInterceptor extends Map> importTriggerMap = getActionTimeMappedTriggerSpecsForOperation( importTriggerSpecs, LdapOperation.MODIFYDN_IMPORT ); - next.moveAndRename( moveAndRenameContext ); + next( moveAndRenameContext ); triggerSpecCache.subentryRenamed( oldDN, newDn); // Fire AFTER Triggers. @@ -482,75 +534,47 @@ public class TriggerInterceptor extends /** * {@inheritDoc} */ - public void move( NextInterceptor next, MoveOperationContext moveContext ) throws LdapException + public void rename( RenameOperationContext renameContext ) throws LdapException { + Dn name = renameContext.getDn(); + Rdn newRdn = renameContext.getNewRdn(); + boolean deleteOldRn = renameContext.getDeleteOldRdn(); + // Bypass trigger handling if the service is disabled. if ( !enabled ) { - next.move( moveContext ); + next( renameContext ); return; } - Rdn rdn = moveContext.getRdn(); - Dn dn = moveContext.getDn(); - Dn newDn = moveContext.getNewDn(); - Dn oldSuperior = moveContext.getOldSuperior(); - Dn newSuperior = moveContext.getNewSuperior(); - - // Gather supplementary data. - Entry movedEntry = moveContext.getOriginalEntry(); - - //Rdn newRDN = dn.getRdn(); - - StoredProcedureParameterInjector injector = new ModifyDNStoredProcedureParameterInjector( moveContext, false, - rdn, rdn, oldSuperior, newSuperior, dn, newDn ); - - // Gather Trigger Specifications which apply to the entry being exported. - List exportTriggerSpecs = new ArrayList(); - addPrescriptiveTriggerSpecs( moveContext, exportTriggerSpecs, dn, movedEntry ); - addEntryTriggerSpecs( exportTriggerSpecs, movedEntry ); - - // Get the entry again without operational attributes - // because access control subentry operational attributes - // will not be valid at the new location. - // This will certainly be fixed by the SubentryInterceptor, - // but after this service. - CoreSession session = moveContext.getSession(); - LookupOperationContext lookupContext = new LookupOperationContext( session, dn, SchemaConstants.ALL_USER_ATTRIBUTES_ARRAY ); - - Entry importedEntry = directoryService.getPartitionNexus().lookup( lookupContext ); - - // As the target entry does not exist yet and so - // its subentry operational attributes are not there, - // we need to construct an entry to represent it - // at least with minimal requirements which are object class - // and access control subentry operational attributes. - Entry fakeImportedEntry = subentryUtils.getSubentryAttributes( newDn, importedEntry ); + // Gather supplementary data. + Entry renamedEntry = ((ClonedServerEntry)renameContext.getEntry()).getClonedEntry(); - for ( Attribute attribute : importedEntry ) - { - fakeImportedEntry.put( attribute ); - } + // @TODO : To be completely reviewed !!! + Rdn oldRdn = name.getRdn(); + Dn oldSuperiorDn = name.getParent(); + Dn newSuperiorDn = oldSuperiorDn; + Dn oldDn = name; + Dn newDn = name; + newDn = newDn.add( newRdn ); - // Gather Trigger Specifications which apply to the entry being imported. - // Note: Entry Trigger Specifications are not valid for Import. - List importTriggerSpecs = new ArrayList(); - addPrescriptiveTriggerSpecs( moveContext, importTriggerSpecs, newDn, fakeImportedEntry ); + StoredProcedureParameterInjector injector = new ModifyDNStoredProcedureParameterInjector( renameContext, + deleteOldRn, oldRdn, newRdn, oldSuperiorDn, newSuperiorDn, oldDn, newDn); - Map> exportTriggerMap = getActionTimeMappedTriggerSpecsForOperation( - exportTriggerSpecs, LdapOperation.MODIFYDN_EXPORT ); + // Gather Trigger Specifications which apply to the entry being renamed. + List triggerSpecs = new ArrayList(); + addPrescriptiveTriggerSpecs( renameContext, triggerSpecs, name, renamedEntry ); + addEntryTriggerSpecs( triggerSpecs, renamedEntry ); - Map> importTriggerMap = getActionTimeMappedTriggerSpecsForOperation( - importTriggerSpecs, LdapOperation.MODIFYDN_IMPORT ); + Map> triggerMap = getActionTimeMappedTriggerSpecsForOperation( + triggerSpecs, LdapOperation.MODIFYDN_RENAME ); - next.move( moveContext ); - triggerSpecCache.subentryRenamed( dn, newDn ); + next( renameContext ); + triggerSpecCache.subentryRenamed( name, newDn); // Fire AFTER Triggers. - List afterExportTriggerSpecs = exportTriggerMap.get( ActionTime.AFTER ); - List afterImportTriggerSpecs = importTriggerMap.get( ActionTime.AFTER ); - executeTriggers( moveContext, afterExportTriggerSpecs, injector ); - executeTriggers( moveContext, afterImportTriggerSpecs, injector ); + List afterTriggerSpecs = triggerMap.get( ActionTime.AFTER ); + executeTriggers( renameContext, afterTriggerSpecs, injector ); } @@ -589,7 +613,7 @@ public class TriggerInterceptor extends { List returnValues = new ArrayList(); List spSpecs = tsec.getSPSpecs(); - + for ( SPSpec spSpec : spSpecs ) { List arguments = new ArrayList(); @@ -609,7 +633,7 @@ public class TriggerInterceptor extends { Entry spUnit = manager.findStoredProcUnit( opContext.getSession(), procedure ); StoredProcEngine engine = manager.getStoredProcEngineInstance( spUnit ); - + return engine.invokeProcedure( opContext.getSession(), procedure, values ); } catch ( Exception e )