You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/11/12 19:24:43 UTC
svn commit: r1201297 [3/9] - in /directory/apacheds/branches/apacheds-txns:
all/ apache-felix/ core-annotations/ core-api/
core-api/src/main/java/org/apache/directory/server/core/api/
core-api/src/main/java/org/apache/directory/server/core/api/intercep...
Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java?rev=1201297&r1=1201296&r2=1201297&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java (original)
+++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/partition/DefaultPartitionNexus.java Sat Nov 12 18:24:38 2011
@@ -46,8 +46,8 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.interceptor.context.BindOperationContext;
import org.apache.directory.server.core.api.interceptor.context.CompareOperationContext;
import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.EntryOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.GetRootDSEOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.GetRootDseOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ListOperationContext;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
@@ -115,7 +115,7 @@ public class DefaultPartitionNexus exten
private static final String ASF = "Apache Software Foundation";
/** the read only rootDSE attributes */
- private final Entry rootDSE;
+ private final Entry rootDse;
/** The DirectoryService instance */
private DirectoryService directoryService;
@@ -151,28 +151,28 @@ public class DefaultPartitionNexus exten
* attributes are added to the rootDSE.
*
* @see <a href="http://www.faqs.org/rfcs/rfc3045.html">Vendor Information</a>
- * @param rootDSE the root entry for the DSA
+ * @param rootDse the root entry for the DSA
* @throws javax.naming.Exception on failure to initialize
*/
- public DefaultPartitionNexus( Entry rootDSE ) throws Exception
+ public DefaultPartitionNexus( Entry rootDse ) throws Exception
{
id = ID;
suffixDn = null;
// setup that root DSE
- this.rootDSE = rootDSE;
+ this.rootDse = rootDse;
// Add the basic informations
- rootDSE.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN );
- rootDSE.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" );
- rootDSE.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES );
- rootDSE.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID );
+ rootDse.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN );
+ rootDse.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" );
+ rootDse.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES );
+ rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID );
// Add the objectClasses
- rootDSE.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );
+ rootDse.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );
// Add the 'vendor' name and version infos
- rootDSE.put( SchemaConstants.VENDOR_NAME_AT, ASF );
+ rootDse.put( SchemaConstants.VENDOR_NAME_AT, ASF );
Properties props = new Properties();
@@ -185,10 +185,10 @@ public class DefaultPartitionNexus exten
LOG.error( I18n.err( I18n.ERR_33 ) );
}
- rootDSE.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) );
+ rootDse.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) );
// The rootDSE uuid has been randomly created
- rootDSE.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" );
+ rootDse.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" );
}
@@ -205,7 +205,7 @@ public class DefaultPartitionNexus exten
while ( ctrlOidItr.hasNext() )
{
- rootDSE.add( SchemaConstants.SUPPORTED_CONTROL_AT, ctrlOidItr.next() );
+ rootDse.add( SchemaConstants.SUPPORTED_CONTROL_AT, ctrlOidItr.next() );
}
schemaManager = directoryService.getSchemaManager();
@@ -216,7 +216,7 @@ public class DefaultPartitionNexus exten
Dn adminDn = directoryService.getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN );
adminDn.apply( schemaManager );
- Value<?> attr = rootDSE.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
+ Value<?> attr = rootDse.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() );
//initializeSystemPartition( directoryService );
@@ -277,7 +277,7 @@ public class DefaultPartitionNexus exten
Dn systemSuffixDn = directoryService.getDnFactory().create( ServerDNConstants.SYSTEM_DN );
CoreSession adminSession = directoryService.getAdminSession();
- if ( !system.hasEntry( new EntryOperationContext( adminSession, systemSuffixDn ) ) )
+ if ( !system.hasEntry( new HasEntryOperationContext( adminSession, systemSuffixDn ) ) )
{
Entry systemEntry = new DefaultEntry( schemaManager, systemSuffixDn );
@@ -308,13 +308,13 @@ public class DefaultPartitionNexus exten
{
partitions.put( key, system );
partitionLookupTree.add( system.getSuffixDn(), system );
- Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
+ Attribute namingContexts = rootDse.get( SchemaConstants.NAMING_CONTEXTS_AT );
if ( namingContexts == null )
{
namingContexts = new DefaultAttribute( schemaManager
.getAttributeType( SchemaConstants.NAMING_CONTEXTS_AT ), system.getSuffixDn().getName() );
- rootDSE.put( namingContexts );
+ rootDse.put( namingContexts );
}
else
{
@@ -443,8 +443,8 @@ public class DefaultPartitionNexus exten
// ------------------------------------------------------------------------
// DirectoryPartition Interface Method Implementations
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#add(org.apache.directory.server.core.interceptor.context.AddOperationContext)
+ /**
+ * {@inheritDoc}
*/
public void add( AddOperationContext addContext ) throws LdapException
{
@@ -456,8 +456,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#bind(org.apache.directory.server.core.interceptor.context.BindOperationContext)
+ /**
+ * {@inheritDoc}
*/
public void bind( BindOperationContext bindContext ) throws LdapException
{
@@ -466,8 +466,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#compare(org.apache.directory.server.core.interceptor.context.CompareOperationContext)
+ /**
+ * {@inheritDoc}
*/
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
@@ -509,8 +509,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#delete(org.apache.directory.server.core.interceptor.context.DeleteOperationContext)
+ /**
+ * {@inheritDoc}
*/
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
@@ -522,7 +522,7 @@ public class DefaultPartitionNexus exten
/**
* {@inheritDoc}
*/
- public boolean hasEntry( EntryOperationContext hasEntryContext ) throws LdapException
+ public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
Dn dn = hasEntryContext.getDn();
@@ -531,7 +531,7 @@ public class DefaultPartitionNexus exten
LOG.debug( "Check if Dn '" + dn + "' exists." );
}
- if ( dn.isRootDSE() )
+ if ( dn.isRootDse() )
{
return true;
}
@@ -562,17 +562,17 @@ public class DefaultPartitionNexus exten
if ( dn.equals( subschemSubentryDn ) )
{
- return new ClonedServerEntry( rootDSE.clone() );
+ return new ClonedServerEntry( rootDse.clone() );
}
// This is for the case we do a lookup on the rootDSE
if ( dn.size() == 0 )
{
- Entry retval = new ClonedServerEntry( rootDSE );
+ Entry retval = new ClonedServerEntry( rootDse );
if ( ( lookupContext.getAttrsId() != null ) && !lookupContext.getAttrsId().isEmpty() )
{
- for ( Attribute attribute : rootDSE.getAttributes() )
+ for ( Attribute attribute : rootDse.getAttributes() )
{
AttributeType attributeType = attribute.getAttributeType();
String oid = attributeType.getOid();
@@ -587,7 +587,7 @@ public class DefaultPartitionNexus exten
}
else
{
- return new ClonedServerEntry( rootDSE );
+ return new ClonedServerEntry( rootDse );
}
}
@@ -665,7 +665,7 @@ public class DefaultPartitionNexus exten
}
- private EntryFilteringCursor searchRootDSE( SearchOperationContext searchContext ) throws LdapException
+ private EntryFilteringCursor searchRootDse( SearchOperationContext searchContext ) throws LdapException
{
SearchControls searchControls = searchContext.getSearchControls();
@@ -677,8 +677,8 @@ public class DefaultPartitionNexus exten
// -----------------------------------------------------------
if ( ( ids == null ) || ( ids.length == 0 ) )
{
- Entry rootDSE = getRootDSE( null );
- return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( rootDSE ), searchContext );
+ Entry rootDse = getRootDse( null );
+ return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( rootDse ), searchContext );
}
// -----------------------------------------------------------
@@ -715,15 +715,15 @@ public class DefaultPartitionNexus exten
// return everything
if ( allUserAttributes && allOperationalAttributes )
{
- Entry rootDSE = getRootDSE( null );
- return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( rootDSE ), searchContext );
+ Entry rootDse = getRootDse( null );
+ return new BaseEntryFilteringCursor( new SingletonCursor<Entry>( rootDse ), searchContext );
}
Entry serverEntry = new DefaultEntry( schemaManager, Dn.ROOT_DSE );
- Entry rootDSE = getRootDSE( new GetRootDSEOperationContext( searchContext.getSession() ) );
+ Entry rootDse = getRootDse( new GetRootDseOperationContext( searchContext.getSession() ) );
- for ( Attribute attribute : rootDSE )
+ for ( Attribute attribute : rootDse )
{
AttributeType type = schemaManager.lookupAttributeTypeRegistry( attribute.getUpId() );
@@ -745,8 +745,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#search(org.apache.directory.server.core.interceptor.context.SearchOperationContext)
+ /**
+ * {@inheritDoc}
*/
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
@@ -783,7 +783,7 @@ public class DefaultPartitionNexus exten
*/
if ( ( filter instanceof PresenceNode ) && isObjectScope && isSearchAll )
{
- return searchRootDSE( searchContext );
+ return searchRootDse( searchContext );
}
else if ( isObjectScope && ( !isSearchAll ) )
{
@@ -796,7 +796,7 @@ public class DefaultPartitionNexus exten
for ( Partition partition : partitions.values() )
{
Dn contextDn = partition.getSuffixDn();
- EntryOperationContext hasEntryContext = new EntryOperationContext( searchContext.getSession(), contextDn );
+ HasEntryOperationContext hasEntryContext = new HasEntryOperationContext( searchContext.getSession(), contextDn );
// search only if the context entry exists
if( partition.hasEntry( hasEntryContext ) )
@@ -845,8 +845,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#unbind(org.apache.directory.server.core.interceptor.context.UnbindOperationContext)
+ /**
+ * {@inheritDoc}
*/
public void unbind( UnbindOperationContext unbindContext ) throws LdapException
{
@@ -855,17 +855,17 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#getRootDSE(org.apache.directory.server.core.interceptor.context.GetRootDSEOperationContext)
+ /**
+ * {@inheritDoc}
*/
- public Entry getRootDSE( GetRootDSEOperationContext getRootDSEContext )
+ public Entry getRootDse( GetRootDseOperationContext getRootDseContext )
{
- return rootDSE.clone();
+ return rootDse.clone();
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#addContextPartition(org.apache.directory.server.core.interceptor.context.AddContextPartitionOperationContext)
+ /**
+ * {@inheritDoc}
*/
public synchronized void addContextPartition( Partition partition ) throws LdapException
{
@@ -894,13 +894,13 @@ public class DefaultPartitionNexus exten
partitions.put( partitionSuffix.getNormName(), partition );
partitionLookupTree.add( partition.getSuffixDn(), partition );
- Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
+ Attribute namingContexts = rootDse.get( SchemaConstants.NAMING_CONTEXTS_AT );
if ( namingContexts == null )
{
namingContexts = new DefaultAttribute( schemaManager
.lookupAttributeTypeRegistry( SchemaConstants.NAMING_CONTEXTS_AT ), partitionSuffix.getName() );
- rootDSE.put( namingContexts );
+ rootDse.put( namingContexts );
}
else
{
@@ -910,8 +910,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#removeContextPartition(Dn partitionDN)
+ /**
+ * {@inheritDoc}
*/
public synchronized void removeContextPartition( Dn partitionDn )
throws LdapException
@@ -933,7 +933,7 @@ public class DefaultPartitionNexus exten
// Retrieve the namingContexts from the RootDSE : the partition
// suffix must be present in those namingContexts
- Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
+ Attribute namingContexts = rootDse.get( SchemaConstants.NAMING_CONTEXTS_AT );
if ( namingContexts != null )
{
@@ -968,8 +968,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#getPartition(org.apache.directory.shared.ldap.model.name.Dn)
+ /**
+ * {@inheritDoc}
*/
public Partition getPartition( Dn dn ) throws LdapException
{
@@ -1010,17 +1010,17 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#registerSupportedExtensions(java.util.Set)
+ /**
+ * {@inheritDoc}
*/
public void registerSupportedExtensions( Set<String> extensionOids ) throws LdapException
{
- Attribute supportedExtension = rootDSE.get( SchemaConstants.SUPPORTED_EXTENSION_AT );
+ Attribute supportedExtension = rootDse.get( SchemaConstants.SUPPORTED_EXTENSION_AT );
if ( supportedExtension == null )
{
- rootDSE.put( SchemaConstants.SUPPORTED_EXTENSION_AT, (String)null );
- supportedExtension = rootDSE.get( SchemaConstants.SUPPORTED_EXTENSION_AT );
+ rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, (String)null );
+ supportedExtension = rootDse.get( SchemaConstants.SUPPORTED_EXTENSION_AT );
}
for ( String extensionOid : extensionOids )
@@ -1030,8 +1030,8 @@ public class DefaultPartitionNexus exten
}
- /* (non-Javadoc)
- * @see org.apache.directory.server.core.partition.PartitionNexus#registerSupportedSaslMechanisms(java.util.Set)
+ /**
+ * {@inheritDoc}
*/
public void registerSupportedSaslMechanisms( Set<String> supportedSaslMechanisms ) throws LdapException
{
@@ -1044,7 +1044,7 @@ public class DefaultPartitionNexus exten
supportedSaslMechanismsAt.add( saslMechanism );
}
- rootDSE.add( supportedSaslMechanismsAt );
+ rootDse.add( supportedSaslMechanismsAt );
}
@@ -1063,7 +1063,7 @@ public class DefaultPartitionNexus exten
*/
private void unregister( Partition partition ) throws Exception
{
- Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
+ Attribute namingContexts = rootDse.get( SchemaConstants.NAMING_CONTEXTS_AT );
if ( namingContexts != null )
{
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=1201297&r1=1201296&r2=1201297&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Sat Nov 12 18:24:38 2011
@@ -51,6 +51,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.DirectoryService;
import org.apache.directory.server.core.api.DnFactory;
import org.apache.directory.server.core.api.InstanceLayout;
+import org.apache.directory.server.core.api.InterceptorEnum;
import org.apache.directory.server.core.api.LdapPrincipal;
import org.apache.directory.server.core.api.OperationEnum;
import org.apache.directory.server.core.api.OperationManager;
@@ -64,12 +65,13 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.changelog.Tag;
import org.apache.directory.server.core.api.changelog.TaggableSearchableChangeLogStore;
import org.apache.directory.server.core.api.event.EventService;
+import org.apache.directory.server.core.api.interceptor.BaseInterceptor;
import org.apache.directory.server.core.api.interceptor.Interceptor;
-import org.apache.directory.server.core.api.interceptor.InterceptorChain;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.BindOperationContext;
-import org.apache.directory.server.core.api.interceptor.context.EntryOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.HasEntryOperationContext;
import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.OperationContext;
import org.apache.directory.server.core.api.journal.Journal;
import org.apache.directory.server.core.api.partition.Partition;
import org.apache.directory.server.core.api.partition.PartitionNexus;
@@ -142,7 +144,7 @@ public class DefaultDirectoryService imp
/** A reference on the SchemaManager */
private SchemaManager schemaManager;
-
+
/** The LDAP Codec Service */
private LdapApiService ldapCodecService = LdapApiServiceFactory.getSingleton();
@@ -152,9 +154,6 @@ public class DefaultDirectoryService imp
/** whether or not server is started for the first time */
private boolean firstStart;
- /** The interceptor (or interceptor chain) for this service */
- private InterceptorChain interceptorChain;
-
/** whether or not this instance has been shutdown */
private boolean started;
@@ -190,7 +189,7 @@ public class DefaultDirectoryService imp
/** remove me after implementation is completed */
private static final String PARTIAL_IMPL_WARNING =
- "WARNING: the changelog is only partially operational and will revert\n" +
+ "WARNING: the changelog is only partially operational and will revert\n" +
"state without consideration of who made the original change. All reverting " +
"changes are made by the admin user.\n Furthermore the used controls are not at " +
"all taken into account";
@@ -243,14 +242,14 @@ public class DefaultDirectoryService imp
/** The list of declared interceptors */
private List<Interceptor> interceptors;
private Map<String, Interceptor> interceptorNames;
-
+
/** A lock to protect the interceptors List */
private ReadWriteLock interceptorsLock = new ReentrantReadWriteLock();
-
+
/** The read and write locks */
private Lock readLock = interceptorsLock.readLock();
private Lock writeLock = interceptorsLock.writeLock();
-
+
/** A map associating a list of interceptor to each operation */
private Map<OperationEnum, List<String>> operationInterceptors;
@@ -294,7 +293,7 @@ public class DefaultDirectoryService imp
/** The Dn factory */
private DnFactory dnFactory;
-
+
/** The Subentry cache */
SubentryCache subentryCache = new SubentryCache();
@@ -477,14 +476,14 @@ public class DefaultDirectoryService imp
public List<Interceptor> getInterceptors()
{
List<Interceptor> cloned = new ArrayList<Interceptor>();
-
+
try
{
readLock.lock();
-
- cloned.addAll( interceptors );
-
- return cloned;
+
+ cloned.addAll( interceptors );
+
+ return cloned;
}
finally
{
@@ -501,13 +500,13 @@ public class DefaultDirectoryService imp
public List<String> getInterceptors( OperationEnum operation )
{
List<String> cloned = new ArrayList<String>();
-
+
try
{
- readLock.lock();
- cloned.addAll( operationInterceptors.get( operation ) );
-
- return cloned;
+ readLock.lock();
+ cloned.addAll( operationInterceptors.get( operation ) );
+
+ return cloned;
}
finally
{
@@ -515,136 +514,177 @@ public class DefaultDirectoryService imp
}
}
-
-
+
+
/**
* Compute the list of to call for each operation
*/
private void initOperationsList()
{
- try
- {
- writeLock.lock();
- operationInterceptors = new ConcurrentHashMap<OperationEnum, List<String>>();
-
- for ( OperationEnum operation : OperationEnum.getOperations() )
- {
- List<String> operationList = new ArrayList<String>();
-
- for ( Interceptor interceptor : interceptors )
- {
- Method[] methods = interceptor.getClass().getDeclaredMethods();
-
- for ( Method method : methods )
- {
- if ( method.getName().equals( operation.getMethodName() ) )
- {
- operationList.add( interceptor.getName() );
- break;
- }
- }
- }
-
- operationInterceptors.put( operation, operationList );
- }
- }
- finally
- {
- writeLock.unlock();
- }
+ try
+ {
+ writeLock.lock();
+ operationInterceptors = new ConcurrentHashMap<OperationEnum, List<String>>();
+
+ for ( OperationEnum operation : OperationEnum.getOperations() )
+ {
+ List<String> operationList = new ArrayList<String>();
+
+ for ( Interceptor interceptor : interceptors )
+ {
+ gatherInterceptors( interceptor, interceptor.getClass(), operation, operationList );
+ }
+
+ operationInterceptors.put( operation, operationList );
+ }
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
+ }
+
+
+ /**
+ * Recursively checks if the given interceptor can be added to the list of interceptors for a given
+ * operation and adds to the list of interceptors if it implements the respective operation
+ *
+ * @param interceptor the instance of the interceptor
+ * @param interceptorClz the class of the interceptor
+ * @param operation type of operation
+ * @param selectedInterceptorList the list of selected interceptors
+ */
+ private void gatherInterceptors( Interceptor interceptor, Class<?> interceptorClz, OperationEnum operation, List<String> selectedInterceptorList )
+ {
+ // We stop recursing when we reach the Base class
+ if( ( interceptorClz == null ) || ( interceptorClz == BaseInterceptor.class ) )
+ {
+ return;
+ }
+
+ Method[] methods = interceptorClz.getDeclaredMethods();
+
+ for ( Method method : methods )
+ {
+ Class<?>[] param = method.getParameterTypes();
+ boolean hasCorrestSig = false;
+
+ // check for the correct signature
+ if( ( param == null ) || ( param.length > 1 ) || ( param.length == 0 ))
+ {
+ continue;
+ }
+
+ if ( OperationContext.class.isAssignableFrom( param[0] ) )
+ {
+ hasCorrestSig = true;
+ }
+ else
+ {
+ continue;
+ }
+
+ if ( hasCorrestSig && method.getName().equals( operation.getMethodName() ) )
+ {
+ selectedInterceptorList.add( interceptor.getName() );
+ break;
+ }
+ }
+
+ gatherInterceptors( interceptor, interceptorClz.getSuperclass(), operation, selectedInterceptorList );
}
-
-
+
+
/**
* Add an interceptor to the list of interceptors to call for each operation
- * @throws LdapException
+ * @throws LdapException
*/
private void addInterceptor( Interceptor interceptor, int position ) throws LdapException
{
- // First, init the interceptor
- interceptor.init( this );
-
- try
- {
- writeLock.lock();
-
- for ( OperationEnum operation : OperationEnum.getOperations() )
- {
- List<String> operationList = operationInterceptors.get( operation );
-
- Method[] methods = interceptor.getClass().getDeclaredMethods();
-
- for ( Method method : methods )
- {
- if ( method.getName().equals( operation.getMethodName() ) )
- {
- if ( position == -1 )
- {
- operationList.add( interceptor.getName() );
- }
- else
- {
- operationList.add( position, interceptor.getName() );
- }
-
- break;
- }
- }
- }
-
- interceptorNames.put( interceptor.getName(), interceptor );
-
- if ( position == -1 )
- {
- interceptors.add( interceptor );
- }
- else
- {
- interceptors.add( position, interceptor );
- }
- }
- finally
- {
- writeLock.unlock();
- }
+ // First, init the interceptor
+ interceptor.init( this );
+
+ try
+ {
+ writeLock.lock();
+
+ for ( OperationEnum operation : OperationEnum.getOperations() )
+ {
+ List<String> operationList = operationInterceptors.get( operation );
+
+ Method[] methods = interceptor.getClass().getDeclaredMethods();
+
+ for ( Method method : methods )
+ {
+ if ( method.getName().equals( operation.getMethodName() ) )
+ {
+ if ( position == -1 )
+ {
+ operationList.add( interceptor.getName() );
+ }
+ else
+ {
+ operationList.add( position, interceptor.getName() );
+ }
+
+ break;
+ }
+ }
+ }
+
+ interceptorNames.put( interceptor.getName(), interceptor );
+
+ if ( position == -1 )
+ {
+ interceptors.add( interceptor );
+ }
+ else
+ {
+ interceptors.add( position, interceptor );
+ }
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
}
-
+
/**
* Remove an interceptor to the list of interceptors to call for each operation
*/
private void removeOperationsList( String interceptorName )
{
- Interceptor interceptor = interceptorNames.get( interceptorName );
-
- try
- {
- writeLock.lock();
-
- for ( OperationEnum operation : OperationEnum.getOperations() )
- {
- List<String> operationList = operationInterceptors.get( operation );
-
- Method[] methods = interceptor.getClass().getDeclaredMethods();
-
- for ( Method method : methods )
- {
- if ( method.getName().equals( operation.getMethodName() ) )
- {
- operationList.remove( interceptor.getName() );
-
- break;
- }
- }
- }
-
- interceptorNames.remove( interceptorName );
- interceptors.remove( interceptor );
- }
- finally
- {
- writeLock.unlock();
- }
+ Interceptor interceptor = interceptorNames.get( interceptorName );
+
+ try
+ {
+ writeLock.lock();
+
+ for ( OperationEnum operation : OperationEnum.getOperations() )
+ {
+ List<String> operationList = operationInterceptors.get( operation );
+
+ Method[] methods = interceptor.getClass().getDeclaredMethods();
+
+ for ( Method method : methods )
+ {
+ if ( method.getName().equals( operation.getMethodName() ) )
+ {
+ operationList.remove( interceptor.getName() );
+
+ break;
+ }
+ }
+ }
+
+ interceptorNames.remove( interceptorName );
+ interceptors.remove( interceptor );
+ }
+ finally
+ {
+ writeLock.unlock();
+ }
}
@@ -665,7 +705,7 @@ public class DefaultDirectoryService imp
LOG.warn( "Encountered duplicate definitions for {} interceptor", interceptor.getName() );
continue;
}
-
+
interceptorNames.put( interceptor.getName(), interceptor );
}
@@ -673,7 +713,19 @@ public class DefaultDirectoryService imp
this.interceptorNames = interceptorNames;
// Now update the Map that connect each operation with the list of interceptors.
- initOperationsList();
+ initOperationsList();
+ }
+
+
+ /**
+ * Initialize the interceptors
+ */
+ private void initInterceptors() throws LdapException
+ {
+ for ( Interceptor interceptor : interceptors )
+ {
+ interceptor.init( this );
+ }
}
@@ -687,7 +739,7 @@ public class DefaultDirectoryService imp
{
List<LdifEntry> cloned = new ArrayList<LdifEntry>();
cloned.addAll( testEntries );
-
+
return cloned;
}
@@ -722,7 +774,7 @@ public class DefaultDirectoryService imp
public void setInstanceLayout( InstanceLayout instanceLayout ) throws IOException
{
this.instanceLayout = instanceLayout;
-
+
// Create the directories if they are missing
if ( !instanceLayout.getInstanceDirectory().exists() )
{
@@ -739,7 +791,7 @@ public class DefaultDirectoryService imp
throw new IOException(I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, instanceLayout.getLogDirectory() ) );
}
}
-
+
if ( !instanceLayout.getRunDirectory().exists() )
{
if ( !instanceLayout.getRunDirectory().mkdirs() )
@@ -747,7 +799,7 @@ public class DefaultDirectoryService imp
throw new IOException(I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, instanceLayout.getRunDirectory() ) );
}
}
-
+
if ( !instanceLayout.getPartitionsDirectory().exists() )
{
if ( !instanceLayout.getPartitionsDirectory().mkdirs() )
@@ -755,7 +807,7 @@ public class DefaultDirectoryService imp
throw new IOException(I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, instanceLayout.getPartitionsDirectory() ) );
}
}
-
+
if ( !instanceLayout.getConfDirectory().exists() )
{
if ( !instanceLayout.getConfDirectory().mkdirs() )
@@ -874,7 +926,7 @@ public class DefaultDirectoryService imp
// We've got an exception, we cannot add the partition to the partitions
throw le;
}
-
+
// Now, add the partition to the set of managed partitions
partitions.add( partition );
}
@@ -896,7 +948,7 @@ public class DefaultDirectoryService imp
// Bad ! We can't go any further
throw le;
}
-
+
// And update the set of managed partitions
partitions.remove( partition );
}
@@ -961,7 +1013,7 @@ public class DefaultDirectoryService imp
bindContext.setCredentials( credentials );
bindContext.setDn( principalDn );
bindContext.setInterceptors( getInterceptors( OperationEnum.BIND ) );
-
+
operationManager.bind( bindContext );
return bindContext.getSession();
@@ -970,7 +1022,7 @@ public class DefaultDirectoryService imp
public CoreSession getSession( Dn principalDn, byte[] credentials, String saslMechanism, String saslAuthId )
throws Exception
- {
+ {
if ( ! started )
{
throw new IllegalStateException( "Service has not started." );
@@ -985,7 +1037,7 @@ public class DefaultDirectoryService imp
operationManager.bind( bindContext );
return bindContext.getSession();
- }
+ }
public long revert() throws LdapException
@@ -1213,13 +1265,13 @@ public class DefaultDirectoryService imp
// load the last stored valid CSN value
LookupOperationContext loc = new LookupOperationContext( getAdminSession() );
loc.setDn( systemPartition.getSuffixDn() );
-
+
// get back all the attributes
loc.setAttrsId( SchemaConstants.ALL_ATTRIBUTES_ARRAY );
Entry entry = systemPartition.lookup( loc );
Attribute cntextCsnAt = entry.get( SchemaConstants.CONTEXT_CSN_AT );
-
+
if ( cntextCsnAt != null )
{
// this is a multivalued attribute but current syncrepl provider implementation stores only ONE value at ou=system
@@ -1298,9 +1350,8 @@ public class DefaultDirectoryService imp
// --------------------------------------------------------------------
// And shutdown the server
// --------------------------------------------------------------------
- interceptorChain.destroy();
cacheService.destroy();
-
+
if ( lockFile != null )
{
try
@@ -1356,7 +1407,7 @@ public class DefaultDirectoryService imp
this.schemaManager = schemaManager;
}
-
+
public LdapApiService getLdapCodecService()
{
return ldapCodecService;
@@ -1387,12 +1438,6 @@ public class DefaultDirectoryService imp
}
- public InterceptorChain getInterceptorChain()
- {
- return interceptorChain;
- }
-
-
public boolean isFirstStart()
{
return firstStart;
@@ -1430,17 +1475,17 @@ public class DefaultDirectoryService imp
/*
* If the admin entry is there, then the database was already created
*/
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, adminDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, adminDn ) ) )
{
firstStart = true;
Entry serverEntry = new DefaultEntry( schemaManager, adminDn );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.PERSON_OC,
- SchemaConstants.ORGANIZATIONAL_PERSON_OC,
- SchemaConstants.INET_ORG_PERSON_OC );
+ SchemaConstants.TOP_OC,
+ SchemaConstants.PERSON_OC,
+ SchemaConstants.ORGANIZATIONAL_PERSON_OC,
+ SchemaConstants.INET_ORG_PERSON_OC );
serverEntry.put( SchemaConstants.UID_AT, PartitionNexus.ADMIN_UID );
serverEntry.put( SchemaConstants.USER_PASSWORD_AT, PartitionNexus.ADMIN_PASSWORD_BYTES );
@@ -1463,15 +1508,15 @@ public class DefaultDirectoryService imp
Dn userDn = getDnFactory().create( ServerDNConstants.USERS_SYSTEM_DN );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, userDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, userDn ) ) )
{
firstStart = true;
Entry serverEntry = new DefaultEntry( schemaManager, userDn );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+ SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
serverEntry.put( SchemaConstants.OU_AT, "users" );
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
@@ -1488,15 +1533,15 @@ public class DefaultDirectoryService imp
Dn groupDn = getDnFactory().create( ServerDNConstants.GROUPS_SYSTEM_DN );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, groupDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, groupDn ) ) )
{
firstStart = true;
Entry serverEntry = new DefaultEntry( schemaManager, groupDn );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.ORGANIZATIONAL_UNIT_OC );
+ SchemaConstants.TOP_OC,
+ SchemaConstants.ORGANIZATIONAL_UNIT_OC );
serverEntry.put( SchemaConstants.OU_AT, "groups" );
serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
@@ -1513,15 +1558,15 @@ public class DefaultDirectoryService imp
Dn name = getDnFactory().create( ServerDNConstants.ADMINISTRATORS_GROUP_DN );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, name ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, name ) ) )
{
firstStart = true;
Entry serverEntry = new DefaultEntry( schemaManager, name );
serverEntry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
+ SchemaConstants.TOP_OC,
+ SchemaConstants.GROUP_OF_UNIQUE_NAMES_OC );
serverEntry.put( SchemaConstants.CN_AT, "Administrators" );
serverEntry.put( SchemaConstants.UNIQUE_MEMBER_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
@@ -1539,7 +1584,7 @@ public class DefaultDirectoryService imp
Dn configurationDn = getDnFactory().create( "ou=configuration,ou=system" );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, configurationDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, configurationDn ) ) )
{
firstStart = true;
@@ -1561,7 +1606,7 @@ public class DefaultDirectoryService imp
Dn partitionsDn = getDnFactory().create( "ou=partitions,ou=configuration,ou=system" );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, partitionsDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, partitionsDn ) ) )
{
firstStart = true;
@@ -1582,7 +1627,7 @@ public class DefaultDirectoryService imp
Dn servicesDn = getDnFactory().create( "ou=services,ou=configuration,ou=system" );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, servicesDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, servicesDn ) ) )
{
firstStart = true;
@@ -1604,7 +1649,7 @@ public class DefaultDirectoryService imp
Dn interceptorsDn = getDnFactory().create( "ou=interceptors,ou=configuration,ou=system" );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, interceptorsDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, interceptorsDn ) ) )
{
firstStart = true;
@@ -1626,7 +1671,7 @@ public class DefaultDirectoryService imp
Dn sysPrefRootDn = getDnFactory().create( ServerDNConstants.SYSPREFROOT_SYSTEM_DN );
- if ( !partitionNexus.hasEntry( new EntryOperationContext( adminSession, sysPrefRootDn ) ) )
+ if ( !partitionNexus.hasEntry( new HasEntryOperationContext( adminSession, sysPrefRootDn ) ) )
{
firstStart = true;
@@ -1704,24 +1749,24 @@ public class DefaultDirectoryService imp
}
}
}
-
-
+
+
private void initializeSystemPartition() throws Exception
{
Partition system = getSystemPartition();
-
+
// Add root context entry for system partition
Dn systemSuffixDn = getDnFactory().create( ServerDNConstants.SYSTEM_DN );
CoreSession adminSession = getAdminSession();
- if ( !system.hasEntry( new EntryOperationContext( adminSession, systemSuffixDn ) ) )
+ if ( !system.hasEntry( new HasEntryOperationContext( adminSession, systemSuffixDn ) ) )
{
Entry systemEntry = new DefaultEntry( schemaManager, systemSuffixDn );
-
+
// Add the ObjectClasses
systemEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC,
SchemaConstants.ORGANIZATIONAL_UNIT_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );
-
+
// Add some operational attributes
systemEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN );
systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
@@ -1729,7 +1774,7 @@ public class DefaultDirectoryService imp
systemEntry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
systemEntry.put( DnUtils.getRdnAttributeType( ServerDNConstants.SYSTEM_DN ), DnUtils
.getRdnValue( ServerDNConstants.SYSTEM_DN ) );
-
+
AddOperationContext addOperationContext = new AddOperationContext( adminSession, systemEntry );
system.add( addOperationContext );
}
@@ -1747,7 +1792,7 @@ public class DefaultDirectoryService imp
{
LOG.debug( "---> Initializing the DefaultDirectoryService " );
}
-
+
cacheService = new CacheService();
cacheService.initialize( this );
@@ -1758,7 +1803,7 @@ public class DefaultDirectoryService imp
triggerExecutionAPCache = new DnNode<TriggerExecutionAdministrativePoint>();
dnFactory = new DefaultDnFactory( schemaManager, cacheService.getCache( "dnCache" ) );
-
+
// triggers partition to load schema fully from schema partition
schemaPartition.initialize();
partitions.add( schemaPartition );
@@ -1773,15 +1818,15 @@ public class DefaultDirectoryService imp
partitionNexus.initialize( );
initializeSystemPartition();
-
+
// --------------------------------------------------------------------
// Create all the bootstrap entries before initializing chain
// --------------------------------------------------------------------
firstStart = createBootstrapEntries();
-
- interceptorChain = new InterceptorChain();
- interceptorChain.init( this );
+
+ // Initialize the interceptors
+ initInterceptors();
// --------------------------------------------------------------------
// Initialize the changeLog if it's enabled
@@ -1794,7 +1839,7 @@ public class DefaultDirectoryService imp
if( changeLog.isExposed() && changeLog.isTagSearchSupported() )
{
String clSuffix = ( ( TaggableSearchableChangeLogStore ) changeLog.getChangeLogStore() ).getPartition().getSuffixDn().getName();
- partitionNexus.getRootDSE( null ).add( SchemaConstants.CHANGELOG_CONTEXT_AT, clSuffix );
+ partitionNexus.getRootDse( null ).add( SchemaConstants.CHANGELOG_CONTEXT_AT, clSuffix );
}
}
@@ -1970,19 +2015,19 @@ public class DefaultDirectoryService imp
*/
public Interceptor getInterceptor( String interceptorName )
{
- try
- {
- readLock.lock();
-
- for ( Interceptor interceptor:interceptors )
- {
- if ( interceptor.getName().equalsIgnoreCase( interceptorName ) )
- {
- return interceptor;
- }
- }
-
- return null;
+ try
+ {
+ readLock.lock();
+
+ for ( Interceptor interceptor:interceptors )
+ {
+ if ( interceptor.getName().equalsIgnoreCase( interceptorName ) )
+ {
+ return interceptor;
+ }
+ }
+
+ return null;
}
finally
{
@@ -1993,39 +2038,39 @@ public class DefaultDirectoryService imp
/**
* {@inheritDoc}
- * @throws LdapException
+ * @throws LdapException
*/
- public void addFirst( Interceptor interceptor ) throws LdapException
- {
- addInterceptor( interceptor, 0 );
- }
+ public void addFirst( Interceptor interceptor ) throws LdapException
+ {
+ addInterceptor( interceptor, 0 );
+ }
/**
* {@inheritDoc}
- * @throws LdapException
+ * @throws LdapException
*/
- public void addLast( Interceptor interceptor ) throws LdapException
- {
- addInterceptor( interceptor, -1 );
- }
+ public void addLast( Interceptor interceptor ) throws LdapException
+ {
+ addInterceptor( interceptor, -1 );
+ }
/**
* {@inheritDoc}
*/
- public void addAfter( String interceptorName, Interceptor interceptor )
- {
- }
+ public void addAfter( String interceptorName, Interceptor interceptor )
+ {
+ }
/**
* {@inheritDoc}
*/
- public void remove( String interceptorName )
- {
- removeOperationsList( interceptorName );
- }
+ public void remove( String interceptorName )
+ {
+ removeOperationsList( interceptorName );
+ }
/**
@@ -2183,24 +2228,24 @@ public class DefaultDirectoryService imp
{
return triggerExecutionAPCache;
}
-
-
+
+
/**
* {@inheritDoc}
*/
public boolean isPwdPolicyEnabled()
{
- AuthenticationInterceptor authenticationInterceptor = (AuthenticationInterceptor)getInterceptor( AuthenticationInterceptor.class.getSimpleName() );
-
+ AuthenticationInterceptor authenticationInterceptor = (AuthenticationInterceptor)getInterceptor( InterceptorEnum.AUTHENTICATION_INTERCEPTOR.getName() );
+
if ( authenticationInterceptor == null )
{
return false;
}
PpolicyConfigContainer pwdPolicyContainer = authenticationInterceptor.getPwdPolicyContainer();
-
- return ( ( pwdPolicyContainer != null )
- && ( ( pwdPolicyContainer.getDefaultPolicy() != null )
+
+ return ( ( pwdPolicyContainer != null )
+ && ( ( pwdPolicyContainer.getDefaultPolicy() != null )
|| ( pwdPolicyContainer.hasCustomConfigs() ) ) );
}
@@ -2221,8 +2266,8 @@ public class DefaultDirectoryService imp
{
return subentryCache;
}
-
-
+
+
/**
* {@inheritDoc}
*/