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 2010/10/30 16:30:34 UTC
svn commit: r1029081 [2/4] - in /directory/apacheds/trunk/server-config: ./
src/main/java/org/apache/directory/server/config/
src/main/java/org/apache/directory/server/config/beans/ src/main/resources/
src/main/resources/config/ src/main/resources/conf...
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java?rev=1029081&r1=1029080&r2=1029081&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigPartitionReader.java Sat Oct 30 14:30:31 2010
@@ -21,38 +21,19 @@
package org.apache.directory.server.config;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_ALLOW_USER_CHANGE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_ATTRIBUTE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_CHECK_QUALITY_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_EXPIRE_WARNING_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_FAILURE_COUNT_INTERVAL_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_GRACE_AUTHN_LIMIT_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_GRACE_EXPIRE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_IN_HISTORY_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_LOCKOUT_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_LOCKOUT_DURATION_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MAX_AGE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MAX_DELAY_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MAX_FAILURE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MAX_IDLE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MAX_LENGTH_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MIN_AGE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MIN_DELAY_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MIN_LENGTH_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_MUST_CHANGE_AT;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_POLICY_OC;
-import static org.apache.directory.shared.ldap.constants.PasswordPolicySchemaConstants.PWD_SAFE_MODIFY_AT;
-
import java.io.File;
-import java.io.FilenameFilter;
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
-import java.util.TreeSet;
import javax.naming.directory.SearchControls;
@@ -85,46 +66,23 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
import org.apache.directory.server.core.partition.ldif.AbstractLdifPartition;
-import org.apache.directory.server.dhcp.service.DhcpService;
-import org.apache.directory.server.dhcp.service.StoreBasedDhcpService;
-import org.apache.directory.server.dhcp.store.DhcpStore;
-import org.apache.directory.server.dhcp.store.SimpleDhcpStore;
-import org.apache.directory.server.dns.DnsServer;
import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.integration.http.HttpServer;
-import org.apache.directory.server.integration.http.WebApp;
-import org.apache.directory.server.kerberos.kdc.KdcServer;
-import org.apache.directory.server.kerberos.shared.crypto.encryption.EncryptionType;
-import org.apache.directory.server.ldap.ExtendedOperationHandler;
-import org.apache.directory.server.ldap.LdapServer;
-import org.apache.directory.server.ldap.handlers.bind.MechanismHandler;
-import org.apache.directory.server.ldap.handlers.bind.ntlm.NtlmMechanismHandler;
-import org.apache.directory.server.ldap.replication.ReplicationProvider;
-import org.apache.directory.server.ldap.replication.ReplicationTrustManager;
-import org.apache.directory.server.ldap.replication.SyncReplProvider;
-import org.apache.directory.server.ldap.replication.SyncreplConfiguration;
-import org.apache.directory.server.ntp.NtpServer;
-import org.apache.directory.server.protocol.shared.transport.TcpTransport;
-import org.apache.directory.server.protocol.shared.transport.Transport;
-import org.apache.directory.server.protocol.shared.transport.UdpTransport;
import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexCursor;
import org.apache.directory.server.xdbm.search.SearchEngine;
-import org.apache.directory.shared.ldap.NotImplementedException;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.StringValue;
import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.exception.LdapInvalidDnException;
import org.apache.directory.shared.ldap.filter.EqualityNode;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
import org.apache.directory.shared.ldap.filter.SearchScope;
-import org.apache.directory.shared.ldap.ldif.LdifEntry;
-import org.apache.directory.shared.ldap.ldif.LdifReader;
import org.apache.directory.shared.ldap.message.AliasDerefMode;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.ObjectClass;
import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -138,6 +96,7 @@ import org.slf4j.LoggerFactory;
*/
public class ConfigPartitionReader
{
+ /** The logger for this class */
private static final Logger LOG = LoggerFactory.getLogger( ConfigPartitionReader.class );
/** the partition which holds the configuration data */
@@ -149,25 +108,15 @@ public class ConfigPartitionReader
/** the schema manager set in the config partition */
private SchemaManager schemaManager;
- /** A reference to the ObjectClass AT */
- private static AttributeType OBJECT_CLASS_AT;
-
- /** the parent directory of the config partition's working directory */
- private File workDir;
+ /** The prefix for all the configuration ObjectClass names */
+ private static final String ADS_PREFIX = "ads-";
- /** LDIF file filter */
- private FilenameFilter ldifFilter = new FilenameFilter()
- {
- public boolean accept( File file, String name )
- {
- if ( file.isDirectory() )
- {
- return true;
- }
+ /** The suffix for the bean */
+ private static final String ADS_SUFFIX = "Bean";
- return file.getName().toLowerCase().endsWith( ".ldif" );
- }
- };
+ /** Those two flags are used to tell the reader if an element of configuration is mandatory or not */
+ private static final boolean MANDATORY = true;
+ private static final boolean OPTIONNAL = false;
/**
@@ -192,2109 +141,763 @@ public class ConfigPartitionReader
this.configPartition = configPartition;
se = configPartition.getSearchEngine();
this.schemaManager = configPartition.getSchemaManager();
- this.workDir = partitionsDir;
-
- // setup ObjectClass attribute type value
- OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
}
/**
- * reads the LDAP server configuration and instantiates without setting a DirectoryService
- *
- * @return the LdapServer instance without a DirectoryService
- * @throws Exception
+ * Fnd the upper objectclass in a hierarchy. All the inherited ObjectClasses
+ * will be removed.
*/
- public LdapServer createLdapServer() throws Exception
+ private ObjectClass findObjectClass( EntryAttribute objectClass ) throws Exception
{
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_LDAP_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- LOG.warn( "No LDAP server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- Entry ldapServerEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "LDAP Server Entry {}", ldapServerEntry );
-
- if ( !isEnabled( ldapServerEntry ) )
- {
- return null;
- }
-
- LdapServer server = new LdapServer();
- server.setServiceId( getString( ConfigSchemaConstants.ADS_SERVER_ID, ldapServerEntry ) );
-
- Transport[] transports = createTransports( ldapServerEntry.getDn() );
- server.setTransports( transports );
-
- EntryAttribute replEnableProvAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_REPL_ENABLE_PROVIDER );
+ Set<ObjectClass> candidates = new HashSet<ObjectClass>();
- if( replEnableProvAttr != null )
+ try
{
- if( Boolean.parseBoolean( replEnableProvAttr.getString() ) )
+ // Create the set of candidates
+ for ( Value<?> ocValue : objectClass )
{
- EntryAttribute replProvImplAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_REPL_PROVIDER_IMPL );
-
- String fqcn = null;
+ String ocName = ocValue.getString();
+ String ocOid = schemaManager.getObjectClassRegistry().getOidByName( ocName );
+ ObjectClass oc = (ObjectClass)schemaManager.getObjectClassRegistry().get( ocOid );
- if ( replProvImplAttr != null )
- {
- fqcn = replProvImplAttr.getString();
- }
- else
- {
- // default replication provider
- fqcn = SyncReplProvider.class.getName();
- }
-
- try
- {
- Class<?> replProvImplClz = Class.forName( fqcn );
- ReplicationProvider rp = ( ReplicationProvider ) replProvImplClz.newInstance();
- server.setReplicationProvider( rp );
- }
- catch( ClassNotFoundException e )
+ if ( oc.isStructural() )
{
- LOG.error( "Failed to load and instantiate ReplicationProvider implementation", e );
- throw e;
+ candidates.add( oc );
}
}
}
-
- server.setReplProviderConfigs( createReplProviderConfigs() );
-
- EntryAttribute searchBaseAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_SEARCH_BASE );
- if( searchBaseAttr != null )
- {
- server.setSearchBaseDn( searchBaseAttr.getString() );
- }
-
- // read the SASL mechanism handlers' configuration
- filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_LDAP_SERVER_SASL_MECH_HANDLER_OC ) );
- cursor = se.cursor( ldapServerEntry.getDn(), AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- while( cursor.next() )
- {
- ForwardIndexEntry<Long, Entry, Long> forwardSaslMechEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor.get();
- Entry saslMechHandlerEntry = configPartition.lookup( forwardSaslMechEntry.getId() );
- if( isEnabled( saslMechHandlerEntry ) )
- {
- String mechanism = getString( ConfigSchemaConstants.ADS_LDAP_SERVER_SASL_MECH_NAME, saslMechHandlerEntry );
- server.addSaslMechanismHandler( mechanism, createSaslMechHandler( saslMechHandlerEntry ) );
- }
- }
-
- cursor.close();
-
- // read the extended operation handlers' config
- filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_LDAP_SERVER_EXT_OP_HANDLER_OC ) );
- cursor = se.cursor( ldapServerEntry.getDn(), AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- while( cursor.next() )
+ catch ( Exception e )
{
- ForwardIndexEntry<Long, Entry, Long> forwardExtOpEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor.get();
- Entry extOpHandlerEntry = configPartition.lookup( forwardExtOpEntry.getId() );
-
- if( !isEnabled( extOpHandlerEntry ) )
- {
- continue;
- }
-
- Class<?> extendedOpClass = Class.forName( extOpHandlerEntry.get( ConfigSchemaConstants.ADS_LDAP_SERVER_EXT_OP_HANDLER_FQCN ).getString() );
- ExtendedOperationHandler extOpHandler = ( ExtendedOperationHandler ) extendedOpClass.newInstance();
- server.addExtendedOperationHandler( extOpHandler );
+ e.printStackTrace();
+ throw e;
}
- cursor.close();
-
- EntryAttribute keyStoreAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_LDAP_SERVER_KEYSTORE_FILE );
- if( keyStoreAttr != null )
+ // Now find the parent OC
+ for ( Value<?> ocValue : objectClass )
{
- server.setKeystoreFile( keyStoreAttr.getString() );
+ String ocName = ocValue.getString();
+ String ocOid = schemaManager.getObjectClassRegistry().getOidByName( ocName );
+ ObjectClass oc = (ObjectClass)schemaManager.getObjectClassRegistry().get( ocOid );
- EntryAttribute certPwdAttr = ldapServerEntry.get( ConfigSchemaConstants.ADS_LDAP_SERVER_CERT_PASSWORD );
- if( certPwdAttr != null )
+ for ( ObjectClass superior : oc.getSuperiors() )
{
- server.setCertificatePassword( certPwdAttr.getString() );
+ if ( oc.isStructural() )
+ {
+ if ( candidates.contains( superior ) )
+ {
+ candidates.remove( superior );
+ }
+ }
}
}
+ // The remaining OC in the candidates set is the one we are looking for
+ ObjectClass result = candidates.toArray( new ObjectClass[]{} )[0];
- return server;
+ LOG.debug( "The top level object class is {}", result.getName() );
+ return result;
}
-
-
- /**
- * Read the KdcServer configuration from the DIT
+
+
+ /**
+ * Create the base Bean from the ObjectClass name.
+ * The bean name is constructed using the OjectClass name, by
+ * removing the ADS prefix, upper casing the first letter and adding "Bean" at the end.
*
- * @return A bean containing the KdcServer configuration
- * @throws Exception If the configuration cannot be read
+ * For instance, ads-directoryService wil become DirectoryServiceBean
*/
- public KdcServerBean readKdcServer() throws Exception
+ private AdsBaseBean createBean( ObjectClass objectClass ) throws ConfigurationException
{
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_KERBEROS_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
+ // The remaining OC in the candidates set is the one we are looking for
+ String objectClassName = objectClass.getName();
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
+ // Now, let's instanciate the associated bean. Get rid of the 'ads-' in front of the name,
+ // and uppercase the first letter. Finally add "Bean" at the end and add the package.
+ //String beanName = this.getClass().getPackage().getName() + "org.apache.directory.server.config.beans." + Character.toUpperCase( objectClassName.charAt( 4 ) ) + objectClassName.substring( 5 ) + "Bean";
+ String beanName = this.getClass().getPackage().getName() + ".beans." +
+ Character.toUpperCase( objectClassName.charAt( ADS_PREFIX.length() ) ) +
+ objectClassName.substring( ADS_PREFIX.length() + 1 ) + ADS_SUFFIX;
+
+ try
{
- LOG.warn( "No kerberos server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- Entry kdcEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "kerberos server entry {}", kdcEntry );
-
- if ( !isEnabled( kdcEntry ) )
+ Class<?> clazz = Class.forName( beanName );
+ Constructor<?> constructor = clazz.getConstructor();
+ AdsBaseBean bean = (AdsBaseBean)constructor.newInstance();
+
+ LOG.debug( "Bean {} created for ObjectClass {}", beanName, objectClassName );
+
+ return bean;
+ }
+ catch ( ClassNotFoundException cnfe )
{
- return null;
+ String message = "Cannot find a Bean class for the ObjectClass name " + objectClassName;
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- KdcServerBean kdcServerBean = new KdcServerBean();
-
- // The serviceID
- kdcServerBean.setServerId( getString( ConfigSchemaConstants.ADS_SERVER_ID, kdcEntry ) );
-
- TransportBean[] transports = readTransports( kdcEntry.getDn() );
- kdcServerBean.setTransports( transports );
-
- // MAY attributes
- EntryAttribute clockSkewAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_ALLOWABLE_CLOCKSKEW );
-
- if ( clockSkewAttr != null )
+ catch ( SecurityException se )
{
- kdcServerBean.setKrbAllowableClockSkew( Long.parseLong( clockSkewAttr.getString() ) );
- }
-
- EntryAttribute encryptionTypeAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_ENCRYPTION_TYPES );
-
- if ( encryptionTypeAttr != null )
+ String message = "Cannot access to the class " + beanName;
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( NoSuchMethodException nsme )
{
- EncryptionType[] encryptionTypes = new EncryptionType[encryptionTypeAttr.size()];
- int count = 0;
-
- for ( Value<?> value : encryptionTypeAttr )
- {
- encryptionTypes[count++] = EncryptionType.getByName( value.getString() );
- }
-
- kdcServerBean.setKrbEncryptionTypes( encryptionTypes );
+ String message = "Cannot find a constructor for the class " + beanName;
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- EntryAttribute emptyAddrAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_EMPTY_ADDRESSES_ALLOWED );
-
- if ( emptyAddrAttr != null )
+ catch ( InvocationTargetException ite )
{
- kdcServerBean.setKrbEmptyAddressesAllowed( Boolean.parseBoolean( emptyAddrAttr.getString() ) );
+ String message = "Cannot invoke the class " + beanName + ", " + ite.getMessage();
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- EntryAttribute fwdAllowedAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_FORWARDABLE_ALLOWED );
-
- if ( fwdAllowedAttr != null )
+ catch ( IllegalAccessException iae )
{
- kdcServerBean.setKrbForwardableAllowed( Boolean.parseBoolean( fwdAllowedAttr.getString() ) );
+ String message = "Cannot access to the constructor for class " + beanName;
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- EntryAttribute paEncTmstpAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_PAENC_TIMESTAMP_REQUIRED );
-
- if ( paEncTmstpAttr != null )
+ catch ( InstantiationException ie )
{
- kdcServerBean.setKrbPaEncTimestampRequired( Boolean.parseBoolean( paEncTmstpAttr.getString() ) );
+ String message = "Cannot instanciate the class " + beanName + ", " + ie.getMessage();
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
+ }
+
- EntryAttribute posdtAllowedAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_POSTDATED_ALLOWED );
-
- if ( posdtAllowedAttr != null )
+ /**
+ * Retrieve the Field associated with an AttributeType name, if any.
+ */
+ private static Field getField( Class<?> clazz, String attributeName, Class<?> originalClazz ) throws ConfigurationException
+ {
+ // We will check all the fields, as the AT name is case insentitive
+ // when the field is case sensitive
+ Field[] fields = clazz.getDeclaredFields();
+
+ for ( Field field : fields )
{
- kdcServerBean.setKrbPostdatedAllowed( Boolean.parseBoolean( posdtAllowedAttr.getString() ) );
+ String fieldName = field.getName();
+
+ if ( fieldName.equalsIgnoreCase( attributeName ) )
+ {
+ return field;
+ }
}
-
- EntryAttribute prxyAllowedAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_PROXIABLE_ALLOWED );
-
- if ( prxyAllowedAttr != null )
+
+ // May be in the paren'ts class ?
+ if ( clazz.getSuperclass() != null )
{
- kdcServerBean.setKrbProxiableAllowed( Boolean.parseBoolean( prxyAllowedAttr.getString() ) );
+ return getField( clazz.getSuperclass(), attributeName, originalClazz );
}
-
- EntryAttribute rnwAllowedAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_RENEWABLE_ALLOWED );
-
- if ( rnwAllowedAttr != null )
+
+ String message = "Cannot find a field named " + attributeName + " in class " + originalClazz.getName();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+
+
+ /**
+ * Read the single entry value for an AttributeType, and feed the Bean field with this value
+ */
+ private void readSingleValueField( AdsBaseBean bean, Field beanField, EntryAttribute fieldAttr, boolean mandatory ) throws ConfigurationException
+ {
+ if ( fieldAttr == null )
{
- kdcServerBean.setKrbRenewableAllowed( Boolean.parseBoolean( rnwAllowedAttr.getString() ) );
+ return;
}
-
- EntryAttribute kdcPrncplAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_KDC_PRINCIPAL );
-
- if ( kdcPrncplAttr != null )
+
+ Value<?> value = fieldAttr.get();
+ String valueStr = value.getString();
+ Class<?> type = beanField.getType();
+
+ // Process the value accordingly to its type.
+ try
{
- kdcServerBean.setKrbKdcPrincipal( kdcPrncplAttr.getString() );
+ if ( type == String.class )
+ {
+ beanField.set( bean, value.getString() );
+ }
+ else if ( type == int.class )
+ {
+ beanField.setInt( bean, Integer.parseInt( valueStr ) );
+ }
+ else if ( type == long.class )
+ {
+ beanField.setLong( bean, Long.parseLong( valueStr ) );
+ }
+ else if ( type == boolean.class )
+ {
+ beanField.setBoolean( bean, Boolean.parseBoolean( valueStr ) );
+ }
+ else if ( type == DN.class )
+ {
+ try
+ {
+ DN dn = new DN( valueStr );
+ beanField.set( bean, dn );
+ }
+ catch ( LdapInvalidDnException lide )
+ {
+ String message = "The DN '" + valueStr + "' for attribute " + fieldAttr.getId() + " is not a valid DN";
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ }
}
-
- EntryAttribute maxRnwLfTimeAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_MAXIMUM_RENEWABLE_LIFETIME );
-
- if ( maxRnwLfTimeAttr != null )
+ catch ( IllegalArgumentException iae )
{
- kdcServerBean.setKrbMaximumRenewableLifetime( Long.parseLong( maxRnwLfTimeAttr.getString() ) );
+ String message = "Cannot store '" + valueStr + "' into attribute " + fieldAttr.getId(); ;
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- EntryAttribute maxTcktLfTimeAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_MAXIMUM_TICKET_LIFETIME );
-
- if ( maxTcktLfTimeAttr != null )
+ catch ( IllegalAccessException e )
{
- kdcServerBean.setKrbMaximumTicketLifetime( Long.parseLong( maxTcktLfTimeAttr.getString() ) );
+ String message = "Cannot store '" + valueStr + "' into attribute " + fieldAttr.getId(); ;
+ LOG.error( message );
+ throw new ConfigurationException( message );
}
-
- EntryAttribute prmRealmAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_PRIMARY_REALM );
-
- if ( prmRealmAttr != null )
+ }
+
+
+ /**
+ * Read the multiple entry value for an AttributeType, and feed the Bean field with this value
+ */
+ private void readMultiValuedField( AdsBaseBean bean, Field beanField, EntryAttribute fieldAttr, boolean mandatory ) throws ConfigurationException
+ {
+ if ( fieldAttr == null )
{
- kdcServerBean.setKrbPrimaryRealm( prmRealmAttr.getString() );
+ return;
}
- EntryAttribute bdyCkhsmVerifyAttr = kdcEntry.get( ConfigSchemaConstants.ADS_KRB_BODY_CHECKSUM_VERIFIED );
+ Class<?> type = beanField.getType();
+
+ String fieldName = beanField.getName();
+ String addMethodName = "add" + Character.toUpperCase( fieldName.charAt( 0 ) ) + fieldName.substring( 1 );
- if ( bdyCkhsmVerifyAttr != null )
+ // loop on the values and inject them in the bean
+ for ( Value<?> value : fieldAttr )
{
- kdcServerBean.setKrbBodyChecksumVerified( Boolean.parseBoolean( bdyCkhsmVerifyAttr.getString() ) );
+ String valueStr = value.getString();
+
+ try
+ {
+ if ( type == String.class )
+ {
+ beanField.set( bean, value.getString() );
+ }
+ else if ( type == int.class )
+ {
+ beanField.setInt( bean, Integer.parseInt( valueStr ) );
+ }
+ else if ( type == long.class )
+ {
+ beanField.setLong( bean, Long.parseLong( valueStr ) );
+ }
+ else if ( type == boolean.class )
+ {
+ beanField.setBoolean( bean, Boolean.parseBoolean( valueStr ) );
+ }
+ else if ( type == DN.class )
+ {
+ try
+ {
+ DN dn = new DN( valueStr );
+ beanField.set( bean, dn );
+ }
+ catch ( LdapInvalidDnException lide )
+ {
+ String message = "The DN '" + valueStr + "' for attribute " + fieldAttr.getId() + " is not a valid DN";
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ }
+ else if ( type == Set.class )
+ {
+ Type genericFieldType = beanField.getGenericType();
+ Class<?> fieldArgClass = null;
+
+ if ( genericFieldType instanceof ParameterizedType )
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) genericFieldType;
+ Type[] fieldArgTypes = parameterizedType.getActualTypeArguments();
+
+ for ( Type fieldArgType : fieldArgTypes )
+ {
+ fieldArgClass = (Class<?>) fieldArgType;
+ }
+ }
+
+ Method method = bean.getClass().getMethod( addMethodName, Array.newInstance( fieldArgClass, 0 ).getClass() );
+
+ method.invoke( bean, new Object[]{ new String[]{valueStr} } );
+ }
+ else if ( type == List.class )
+ {
+ Type genericFieldType = beanField.getGenericType();
+ Class<?> fieldArgClass = null;
+
+ if ( genericFieldType instanceof ParameterizedType )
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) genericFieldType;
+ Type[] fieldArgTypes = parameterizedType.getActualTypeArguments();
+
+ for ( Type fieldArgType : fieldArgTypes )
+ {
+ fieldArgClass = (Class<?>) fieldArgType;
+ }
+ }
+
+ Method method = bean.getClass().getMethod( addMethodName, Array.newInstance( fieldArgClass, 0 ).getClass() );
+
+ method.invoke( bean, new Object[]{ new String[]{valueStr} } );
+ }
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ String message = "Cannot store '" + valueStr + "' into attribute " + fieldAttr.getId(); ;
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( IllegalAccessException e )
+ {
+ String message = "Cannot store '" + valueStr + "' into attribute " + fieldAttr.getId(); ;
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( SecurityException se )
+ {
+ String message = "Cannot access to the class " + bean.getClass().getName();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( NoSuchMethodException nsme )
+ {
+ String message = "Cannot find a method " + addMethodName + " in the class " + bean.getClass().getName();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( InvocationTargetException ite )
+ {
+ String message = "Cannot invoke the class " + bean.getClass().getName() + ", " + ite.getMessage();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ catch ( NegativeArraySizeException nase )
+ {
+ // No way that can happen...
+ }
}
+ }
- EntryAttribute searchBaseAttr = kdcEntry.get( ConfigSchemaConstants.ADS_SEARCH_BASE );
-
- if( searchBaseAttr != null )
+
+ /**
+ * Read all the required fields (AttributeTypes) for a given Entry.
+ */
+ private void readFields( AdsBaseBean bean, Entry entry, Set<AttributeType> attributeTypes, boolean mandatory ) throws NoSuchFieldException, IllegalAccessException, Exception
+ {
+ for ( AttributeType attributeType : attributeTypes )
{
- kdcServerBean.setSearchBaseDN( searchBaseAttr.getString() );
+ String fieldName = attributeType.getName();
+ String beanFieldName = fieldName;
+
+ // Remove the "ads-" from the beginning of the field name
+ if ( fieldName.startsWith( ADS_PREFIX ) )
+ {
+ beanFieldName = fieldName.substring( ADS_PREFIX.length() );
+ }
+
+ // Get the field
+ Field beanField = getField( bean.getClass(), beanFieldName, bean.getClass() );
+
+ // The field is private, we need to modify it to be able to access it.
+ beanField.setAccessible( true );
+
+ // Get the entry attribute for this field
+ EntryAttribute fieldAttr = entry.get( fieldName );
+
+ if ( ( fieldAttr == null ) && ( mandatory ) )
+ {
+ String message = "Attribute " + fieldName + " is mandatory and is not present for the Entry " + entry.getDn();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+
+ // Get the associated AttributeType
+ AttributeType beanAT = schemaManager.getAttributeType( fieldName );
+
+ // Check if this AT has the ads-compositeElement as a superior
+ AttributeType superior = beanAT.getSuperior();
+
+ if ( ( superior != null ) && superior.getOid().equals( ConfigSchemaConstants.ADS_COMPOSITE_ELEMENT_AT.getOid() ) )
+ {
+ // This is a composite element, we have to go one level down to read it.
+ // First, check if it's a SingleValued element
+ if ( beanAT.isSingleValued() )
+ {
+ // Yes : get the first element
+ List<AdsBaseBean> beans = read( entry.getDn(), fieldName, SearchScope.ONELEVEL, mandatory );
+
+ // We may not have found an element, but if the attribute is mandatory,
+ // this is an error
+ if ( ( beans == null ) || ( beans.size() == 0 ) )
+ {
+ if ( mandatory )
+ {
+ // This is an error !
+ String message = "The composite " + beanAT.getName() + " is mandatory, and was not found under the "
+ + "configuration entry " + entry.getDn();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ }
+ else
+ {
+ // We must take the first element
+ AdsBaseBean readBean = beans.get( 0 );
+
+ if ( beans.size() > 1 )
+ {
+ // Not allowed as the AT is singled-valued
+ String message = "We have more than one entry for " + beanAT.getName() + " under " + entry.getDn();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+
+ beanField.set( bean, readBean );
+ }
+ }
+ else
+ {
+ // No : we have to loop recursively on all the elements which are
+ // under the ou=<element-name> branch
+ DN newBase = entry.getDn().add( "ou=" + beanFieldName );
+
+ // We have to remove the 's' at the end of the field name
+ String attributeName = fieldName.substring( 0, fieldName.length() - 1 );
+
+ // Sometime, the plural of a noun takes 'es'
+ if ( !schemaManager.getObjectClassRegistry().contains( attributeName ) )
+ {
+ // Try by removing 'es'
+ attributeName = fieldName.substring( 0, fieldName.length() - 2 );
+
+ if ( !schemaManager.getObjectClassRegistry().contains( attributeName ) )
+ {
+ String message = "Cannot find the ObjectClass named " + attributeName + " in the schema";
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ }
+
+ // This is a multi-valued element, it can be a Set or a List
+ Collection<AdsBaseBean> beans = read( newBase, attributeName, SearchScope.ONELEVEL, mandatory );
+
+ if ( ( beans == null ) || ( beans.size() == 0 ) )
+ {
+ // If the element is mandatory, this is an error
+ if ( mandatory )
+ {
+ String message = "The composite " + beanAT.getName() + " is mandatory, and was not found under the "
+ + "configuration entry " + entry.getDn();
+ LOG.error( message );
+ throw new ConfigurationException( message );
+ }
+ }
+ else
+ {
+ // Update the field
+ beanField.set( bean, beans );
+ }
+ }
+ }
+ else // A standard AttributeType (ie, boolean, long, int or String)
+ {
+ // Process the field accordingly to its cardinality
+ if ( beanAT.isSingleValued() )
+ {
+ readSingleValueField( bean, beanField, fieldAttr, mandatory );
+ }
+ else
+ {
+ readMultiValuedField( bean, beanField, fieldAttr, mandatory );
+ }
+ }
}
-
- return kdcServerBean;
}
/**
- * Create an instance of KdcServer reading its configuration in the DIT
- *
- * @return An instance of a KdcServer
- * @throws Exception If the instance cannot be created
+ * Get the list of MUST AttributeTypes for an objectClass
*/
- public KdcServer createKdcServer() throws Exception
+ private Set<AttributeType> getAllMusts( ObjectClass objectClass )
{
- KdcServerBean kdcServerBean = readKdcServer();
+ Set<AttributeType> musts = new HashSet<AttributeType>();
- if ( kdcServerBean == null )
- {
- return null;
- }
+ // First, gets the direct MUST
+ musts.addAll( objectClass.getMustAttributeTypes() );
- KdcServer kdcServer = new KdcServer();
+ // then add all the superiors MUST (recursively)
+ List<ObjectClass> superiors = objectClass.getSuperiors();
- for ( TransportBean transportBean : kdcServerBean.getTransports() )
+ if ( superiors != null )
{
- Transport transport = createTransport( transportBean );
-
- kdcServer.addTransports( transport );
+ for ( ObjectClass superior : superiors )
+ {
+ musts.addAll( getAllMusts( superior) );
+ }
}
- kdcServer.setServiceId( kdcServerBean.getServerId() );
- kdcServer.setAllowableClockSkew( kdcServerBean.getKrbAllowableClockSkew() );
- kdcServer.setEncryptionTypes( kdcServerBean.getKrbEncryptionTypes() );
- kdcServer.setEmptyAddressesAllowed( kdcServerBean.isKrbEmptyAddressesAllowed() );
- kdcServer.setForwardableAllowed( kdcServerBean.isKrbForwardableAllowed() );
- kdcServer.setPaEncTimestampRequired( kdcServerBean.isKrbPaEncTimestampRequired() );
- kdcServer.setPostdatedAllowed( kdcServerBean.isKrbPostdatedAllowed() );
- kdcServer.setProxiableAllowed( kdcServerBean.isKrbProxiableAllowed() );
- kdcServer.setRenewableAllowed( kdcServerBean.isKrbRenewableAllowed() );
- kdcServer.setKdcPrincipal( kdcServerBean.getKrbKdcPrincipal().getName() );
- kdcServer.setMaximumRenewableLifetime( kdcServerBean.getKrbMaximumRenewableLifetime() );
- kdcServer.setMaximumTicketLifetime( kdcServerBean.getKrbMaximumTicketLifetime() );
- kdcServer.setPrimaryRealm( kdcServerBean.getKrbPrimaryRealm() );
- kdcServer.setBodyChecksumVerified( kdcServerBean.isKrbBodyChecksumVerified() );
- kdcServer.setSearchBaseDn( kdcServerBean.getSearchBaseDN() );
-
- return kdcServer;
+ return musts;
}
-
-
+
+
/**
- * Read the DnsServer configuration from the DIT
- *
- * @return A bean containing the DnsServer configuration
- * @throws Exception If the configuration cannot be read
+ * Get the list of MAY AttributeTypes for an objectClass
*/
- public DnsServerBean readDnsServer() throws Exception
+ private Set<AttributeType> getAllMays( ObjectClass objectClass )
{
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_DNS_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- LOG.warn( "No DNS server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- ClonedServerEntry dnsEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "DNS server entry {}", dnsEntry );
-
- if ( !isEnabled( dnsEntry ) )
+ Set<AttributeType> mays = new HashSet<AttributeType>();
+
+ // First, gets the direct MAY
+ mays.addAll( objectClass.getMayAttributeTypes() );
+
+ // then add all the superiors MAY (recursively)
+ List<ObjectClass> superiors = objectClass.getSuperiors();
+
+ if ( superiors != null )
{
- return null;
+ for ( ObjectClass superior : superiors )
+ {
+ mays.addAll( getAllMays( superior) );
+ }
}
-
- DnsServerBean dnsServerBean = new DnsServerBean();
-
- dnsServerBean.setServerId( getString( ConfigSchemaConstants.ADS_SERVER_ID, dnsEntry ) );
-
- TransportBean[] transports = readTransports( dnsEntry.getDn() );
- dnsServerBean.setTransports( transports );
-
- return dnsServerBean;
+
+ return mays;
}
-
+
/**
- * Create an instance of DnsServer reading its configuration in the DIT
- *
- * @return An instance of a DnsServer
- * @throws Exception If the instance cannot be created
+ * Helper method to print a list of AT's names.
*/
- public DnsServer createDnsServer() throws Exception
+ private String dumpATs( Set<AttributeType> attributeTypes )
{
- DnsServerBean dnsServerBean = readDnsServer();
-
- if ( dnsServerBean == null )
+ if ( ( attributeTypes == null ) || ( attributeTypes.size() == 0 ) )
{
- return null;
+ return "";
}
- DnsServer dnsServer = new DnsServer();
+ StringBuilder sb = new StringBuilder();
+ boolean isFirst = true;
+ sb.append( '{' );
- for ( TransportBean transportBean : dnsServerBean.getTransports() )
+ for ( AttributeType attributeType : attributeTypes )
{
- Transport transport = createTransport( transportBean );
+ if ( isFirst )
+ {
+ isFirst = false;
+ }
+ else
+ {
+ sb.append( ", " );
+ }
- dnsServer.addTransports( transport );
+ sb.append( attributeType.getName() );
}
-
- dnsServer.setServiceId( dnsServerBean.getServerId() );
+ sb.append( '}' );
- return dnsServer;
+
+ return sb.toString();
}
+
- //TODO making this method invisible cause there is no DhcpServer exists as of now
- private DhcpService readDhcpServer() throws Exception
+ /**
+ * Read some configuration element from the DIT using its name
+ */
+ private List<AdsBaseBean> read( DN baseDn, String name, SearchScope scope, boolean mandatory ) throws ConfigurationException
{
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_DHCP_SERVER_OC ) );
+ LOG.debug( "Reading from '{}', entry {}", baseDn, name );
+
+ // Search for the element starting at some point in the DIT
+ // Prepare the search request
+ AttributeType adsdAt = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT );
+ EqualityNode<?> filter = new EqualityNode( adsdAt, new StringValue( name ) );
SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
+ controls.setSearchScope( scope.ordinal() );
+ IndexCursor<Long, Entry, Long> cursor = null;
+
+ // Create a container for all the read beans
+ List<AdsBaseBean> beans = new ArrayList<AdsBaseBean>();
- if ( !cursor.next() )
+ try
{
- LOG.warn( "No DHCP server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- ClonedServerEntry dhcpEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "DHCP server entry {}", dhcpEntry );
-
- if ( !isEnabled( dhcpEntry ) )
- {
- return null;
- }
-
- return null;
- }
-
-
- //TODO making this method invisible cause there is no DhcpServer exists as of now
- private DhcpService createDhcpServer() throws Exception
- {
- DhcpStore dhcpStore = new SimpleDhcpStore();
- DhcpService dhcpService = new StoreBasedDhcpService( dhcpStore );
-
- return dhcpService;
- }
-
- /**
- * Read the NtpServer configuration from the DIT
- *
- * @return A bean containing the NtpServer configuration
- * @throws Exception If the configuration cannot be read
- */
- public NtpServerBean readNtpServer() throws Exception
- {
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_NTP_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- LOG.warn( "No NTP server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- ClonedServerEntry ntpEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "NTP server entry {}", ntpEntry );
-
- if ( !isEnabled( ntpEntry ) )
- {
- return null;
- }
-
- NtpServerBean ntpServerBean = new NtpServerBean();
-
- ntpServerBean.setServerId( getString( ConfigSchemaConstants.ADS_SERVER_ID, ntpEntry ) );
-
- TransportBean[] transports = readTransports( ntpEntry.getDn() );
- ntpServerBean.setTransports( transports );
-
- return ntpServerBean;
- }
-
-
- /**
- * Create the NtpServer instance from configuration in the DIT
- *
- * @return An instance of NtpServer
- * @throws Exception If the configuration cannot be read
- */
- public NtpServer createNtpServer() throws Exception
- {
- NtpServerBean ntpServerBean = readNtpServer();
-
- if ( ntpServerBean == null )
- {
- return null;
- }
-
- NtpServer ntpServer = new NtpServer();
-
- for ( TransportBean transportBean : ntpServerBean.getTransports() )
- {
- Transport transport = createTransport( transportBean );
-
- ntpServer.addTransports( transport );
- }
-
- ntpServer.setServiceId( ntpServerBean.getServerId() );
-
- return ntpServer;
- }
-
-
- public ChangePasswordServer createChangePwdServer() throws Exception
- {
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_CHANGEPWD_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- LOG.warn( "No ChangePassword server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor.get();
- cursor.close();
-
- ClonedServerEntry chgPwdEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "Changepassword server entry {}", chgPwdEntry );
-
- if ( !isEnabled( chgPwdEntry ) )
- {
- return null;
- }
-
- ChangePasswordServer chgPwdServer = new ChangePasswordServer();
-
- chgPwdServer.setServiceId( getString( ConfigSchemaConstants.ADS_SERVER_ID, chgPwdEntry ) );
-
- Transport[] transports = createTransports( chgPwdEntry.getDn() );
- chgPwdServer.setTransports( transports );
-
- // MAY attributes
- EntryAttribute clockSkewAttr = chgPwdEntry.get( ConfigSchemaConstants.ADS_KRB_ALLOWABLE_CLOCKSKEW );
-
- if ( clockSkewAttr != null )
- {
- chgPwdServer.setAllowableClockSkew( Long.parseLong( clockSkewAttr.getString() ) );
- }
-
- EntryAttribute encryptionTypeAttr = chgPwdEntry.get( ConfigSchemaConstants.ADS_KRB_ENCRYPTION_TYPES );
-
- if ( encryptionTypeAttr != null )
- {
- EncryptionType[] encryptionTypes = new EncryptionType[encryptionTypeAttr.size()];
- Iterator<Value<?>> itr = encryptionTypeAttr.getAll();
- int count = 0;
-
- while ( itr.hasNext() )
- {
- Value<?> val = itr.next();
- encryptionTypes[count++] = EncryptionType.getByName( val.getString() );
- }
-
- chgPwdServer.setEncryptionTypes( encryptionTypes );
- }
-
- EntryAttribute emptyAddrAttr = chgPwdEntry.get( ConfigSchemaConstants.ADS_KRB_EMPTY_ADDRESSES_ALLOWED );
-
- if ( emptyAddrAttr != null )
- {
- chgPwdServer.setEmptyAddressesAllowed( Boolean.parseBoolean( emptyAddrAttr.getString() ) );
- }
-
- EntryAttribute prmRealmAttr = chgPwdEntry.get( ConfigSchemaConstants.ADS_KRB_PRIMARY_REALM );
-
- if ( prmRealmAttr != null )
- {
- chgPwdServer.setPrimaryRealm( prmRealmAttr.getString() );
- }
-
- EntryAttribute policyCatCount = chgPwdEntry.get( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_CATEGORY_COUNT );
- if( policyCatCount != null )
- {
- chgPwdServer.setPolicyCategoryCount( getInt( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_CATEGORY_COUNT, chgPwdEntry ) );
- }
-
- EntryAttribute policyPwdLen = chgPwdEntry.get( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_PASSWORD_LENGTH );
-
- if( policyPwdLen != null )
- {
- chgPwdServer.setPolicyPasswordLength( getInt( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_PASSWORD_LENGTH, chgPwdEntry ) );
- }
-
- EntryAttribute policyTokenSize = chgPwdEntry.get( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_TOKEN_SIZE );
-
- if( policyTokenSize != null )
- {
- chgPwdServer.setPolicyTokenSize( getInt( ConfigSchemaConstants.ADS_CHANGEPWD_POLICY_TOKEN_SIZE, chgPwdEntry ) );
- }
-
- EntryAttribute servicePrincipal = chgPwdEntry.get( ConfigSchemaConstants.ADS_CHANGEPWD_SERVICE_PRINCIPAL );
-
- if( servicePrincipal != null )
- {
- chgPwdServer.setServicePrincipal( servicePrincipal.getString() );
- }
-
- EntryAttribute searchBaseAttr = chgPwdEntry.get( ConfigSchemaConstants.ADS_SEARCH_BASE );
-
- if ( searchBaseAttr != null )
- {
- chgPwdServer.setSearchBaseDn( searchBaseAttr.getString() );
- }
-
- return chgPwdServer;
- }
-
-
- public HttpServer createHttpServer() throws Exception
- {
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_HTTP_SERVER_OC ) );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- LOG.warn( "No HTTP server was configured under the DN {}", configPartition.getSuffix() );
- return null;
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- Entry httpEntry = configPartition.lookup( forwardEntry.getId() );
- LOG.debug( "HTTP server entry {}", httpEntry );
-
- if ( !isEnabled( httpEntry ) )
- {
- return null;
- }
-
- HttpServer httpServer = new HttpServer();
-
- EntryAttribute portAttr = httpEntry.get( ConfigSchemaConstants.ADS_SYSTEM_PORT );
-
- if ( portAttr != null )
- {
- httpServer.setPort( Integer.parseInt( portAttr.getString() ) );
- }
-
- EntryAttribute confFileAttr = httpEntry.get( ConfigSchemaConstants.ADS_HTTP_CONFFILE );
-
- if ( confFileAttr != null )
- {
- httpServer.setConfFile( confFileAttr.getString() );
- }
-
- DN webAppsDN = new DN( httpEntry.getDn().getName(), schemaManager );
-
- Set<WebApp> webApps = createWebApps( webAppsDN );
- httpServer.setWebApps( webApps );
-
- return httpServer;
- }
-
-
- /**
- * instantiates a DirectoryService based on the configuration present in the partition
- *
- * @throws Exception
- *
- public DirectoryServiceBean readDirectoryService() throws Exception
- {
- AttributeType adsDirectoryServiceidAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_DIRECTORYSERVICE_ID );
- PresenceNode filter = new PresenceNode( adsDirectoryServiceidAt );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- // the DirectoryService is mandatory so throwing exception
- throw new Exception( "No directoryService instance was configured under the DN "
- + configPartition.getSuffix() );
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- Entry dsEntry = configPartition.lookup( forwardEntry.getId() );
-
- LOG.debug( "directory service entry {}", dsEntry );
-
- DirectoryServiceBean dirServicebean = new DirectoryServiceBean();
-
- // MUST attributes
- dirServicebean.setInstanceId( getString( ConfigSchemaConstants.ADS_DIRECTORYSERVICE_ID, dsEntry ) );
- dirServicebean.setReplicaId( getInt( ConfigSchemaConstants.ADS_DS_REPLICA_ID, dsEntry ) );
-
- Set<InterceptorBean> interceptors = readInterceptors( dsEntry.getDn() );
- dirServicebean.setInterceptors( interceptors );
-
- AuthenticationInterceptor authnInterceptor = ( AuthenticationInterceptor ) dirServicebean.getInterceptor( AuthenticationInterceptor.class.getName() );
- authnInterceptor.setPwdPolicyConfig( createPwdPolicyConfig( dsEntry.getDn() ) );
-
- Map<String, Partition> partitions = createPartitions( dsEntry.getDn() );
-
- Partition systemPartition = partitions.remove( "system" );
-
- if ( systemPartition == null )
- {
- throw new Exception( I18n.err( I18n.ERR_505 ) );
- }
-
- dirServicebean.setSystemPartition( systemPartition );
- dirServicebean.setPartitions( new HashSet<Partition>( partitions.values() ) );
-
- // MAY attributes
- EntryAttribute acEnabledAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_ACCESSCONTROL_ENABLED );
-
- if ( acEnabledAttr != null )
- {
- dirServicebean.setAccessControlEnabled( Boolean.parseBoolean( acEnabledAttr.getString() ) );
- }
-
- EntryAttribute anonAccessAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_ALLOW_ANONYMOUS_ACCESS );
-
- if ( anonAccessAttr != null )
- {
- dirServicebean.setAllowAnonymousAccess( Boolean.parseBoolean( anonAccessAttr.getString() ) );
- }
-
- EntryAttribute changeLogAttr = dsEntry.get( ConfigSchemaConstants.ADS_DSCHANGELOG );
-
- if ( changeLogAttr != null )
- {
- DN clDN = new DN( changeLogAttr.getString(), schemaManager );
- ChangeLog cl = createChangeLog( clDN );
- dirServicebean.setChangeLog( cl );
- }
-
- EntryAttribute denormAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_DENORMALIZE_OPATTRS_ENABLED );
-
- if ( denormAttr != null )
- {
- dirServicebean.setDenormalizeOpAttrsEnabled( Boolean.parseBoolean( denormAttr.getString() ) );
- }
-
- EntryAttribute journalAttr = dsEntry.get( ConfigSchemaConstants.ADS_DSJOURNAL );
-
- if ( journalAttr != null )
- {
- DN journalDN = new DN( journalAttr.getString(), schemaManager );
- dirServicebean.setJournal( createJournal( journalDN ) );
- }
-
- EntryAttribute maxPduAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_MAXPDU_SIZE );
-
- if ( maxPduAttr != null )
- {
- dirServicebean.setMaxPDUSize( Integer.parseInt( maxPduAttr.getString() ) );
- }
-
- EntryAttribute passwordHidAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_PASSWORD_HIDDEN );
-
- if ( passwordHidAttr != null )
- {
- dirServicebean.setPasswordHidden( Boolean.parseBoolean( passwordHidAttr.getString() ) );
- }
-
- EntryAttribute replAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_REPLICATION );
-
- if ( replAttr != null )
- {
- // configure replication
- }
-
- EntryAttribute syncPeriodAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_SYNCPERIOD_MILLIS );
-
- if ( syncPeriodAttr != null )
- {
- dirServicebean.setSyncPeriodMillis( Long.parseLong( syncPeriodAttr.getString() ) );
- }
-
- EntryAttribute testEntryAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_TEST_ENTRIES );
-
- if ( testEntryAttr != null )
- {
- String entryFilePath = testEntryAttr.getString();
- dirServicebean.setTestEntries( readTestEntries( entryFilePath ) );
- }
-
- if ( !isEnabled( dsEntry ) )
- {
- // will only be useful if we ever allow more than one DS to be configured and
- // switch between them
- // decide which one to use based on this flag
- }
-
- return dirServicebean;
- }
-
-
- /**
- * instantiates a DirectoryService based on the configuration present in the partition
- *
- * @throws Exception
- */
- public DirectoryService createDirectoryService() throws Exception
- {
- AttributeType adsDirectoryServiceidAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_DIRECTORYSERVICE_ID );
- PresenceNode filter = new PresenceNode( adsDirectoryServiceidAt );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- if ( !cursor.next() )
- {
- // the DirectoryService is mandatory so throwing exception
- throw new Exception( "No directoryService instance was configured under the DN "
- + configPartition.getSuffix() );
- }
-
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- cursor.close();
-
- ClonedServerEntry dsEntry = configPartition.lookup( forwardEntry.getId() );
-
- LOG.debug( "directory service entry {}", dsEntry );
-
- DirectoryService dirService = new DefaultDirectoryService();
- // MUST attributes
- dirService.setInstanceId( getString( ConfigSchemaConstants.ADS_DIRECTORYSERVICE_ID, dsEntry ) );
- dirService.setReplicaId( getInt( ConfigSchemaConstants.ADS_DS_REPLICA_ID, dsEntry ) );
-
- List<Interceptor> interceptors = createInterceptors( dsEntry.getDn() );
- dirService.setInterceptors( interceptors );
-
- AuthenticationInterceptor authnInterceptor = ( AuthenticationInterceptor ) dirService.getInterceptor( AuthenticationInterceptor.class.getName() );
- authnInterceptor.setPwdPolicyConfig( createPwdPolicyConfig( dsEntry.getDn() ) );
-
- Map<String, Partition> partitions = createPartitions( dsEntry.getDn() );
-
- Partition systemPartition = partitions.remove( "system" );
-
- if ( systemPartition == null )
- {
- throw new Exception( I18n.err( I18n.ERR_505 ) );
- }
-
- dirService.setSystemPartition( systemPartition );
- dirService.setPartitions( new HashSet<Partition>( partitions.values() ) );
-
- // MAY attributes
- EntryAttribute acEnabledAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_ACCESSCONTROL_ENABLED );
-
- if ( acEnabledAttr != null )
- {
- dirService.setAccessControlEnabled( Boolean.parseBoolean( acEnabledAttr.getString() ) );
- }
-
- EntryAttribute anonAccessAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_ALLOW_ANONYMOUS_ACCESS );
-
- if ( anonAccessAttr != null )
- {
- dirService.setAllowAnonymousAccess( Boolean.parseBoolean( anonAccessAttr.getString() ) );
- }
-
- EntryAttribute changeLogAttr = dsEntry.get( ConfigSchemaConstants.ADS_DSCHANGELOG );
-
- if ( changeLogAttr != null )
- {
- DN clDN = new DN( changeLogAttr.getString(), schemaManager );
- ChangeLog cl = createChangeLog( clDN );
- dirService.setChangeLog( cl );
- }
-
- EntryAttribute denormAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_DENORMALIZE_OPATTRS_ENABLED );
-
- if ( denormAttr != null )
- {
- dirService.setDenormalizeOpAttrsEnabled( Boolean.parseBoolean( denormAttr.getString() ) );
- }
-
- EntryAttribute journalAttr = dsEntry.get( ConfigSchemaConstants.ADS_DSJOURNAL );
-
- if ( journalAttr != null )
- {
- DN journalDN = new DN( journalAttr.getString(), schemaManager );
- dirService.setJournal( createJournal( journalDN ) );
- }
-
- EntryAttribute maxPduAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_MAXPDU_SIZE );
-
- if ( maxPduAttr != null )
- {
- dirService.setMaxPDUSize( Integer.parseInt( maxPduAttr.getString() ) );
- }
-
- EntryAttribute passwordHidAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_PASSWORD_HIDDEN );
-
- if ( passwordHidAttr != null )
- {
- dirService.setPasswordHidden( Boolean.parseBoolean( passwordHidAttr.getString() ) );
- }
-
- EntryAttribute replAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_REPLICATION );
-
- if ( replAttr != null )
- {
- // configure replication
- }
-
- EntryAttribute syncPeriodAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_SYNCPERIOD_MILLIS );
-
- if ( syncPeriodAttr != null )
- {
- dirService.setSyncPeriodMillis( Long.parseLong( syncPeriodAttr.getString() ) );
- }
-
- EntryAttribute testEntryAttr = dsEntry.get( ConfigSchemaConstants.ADS_DS_TEST_ENTRIES );
-
- if ( testEntryAttr != null )
- {
- String entryFilePath = testEntryAttr.getString();
- dirService.setTestEntries( readTestEntries( entryFilePath ) );
- }
-
- if ( !isEnabled( dsEntry ) )
- {
- // will only be useful if we ever allow more than one DS to be configured and
- // switch between them
- // decide which one to use based on this flag
- }
-
- return dirService;
- }
-
-
- private List<SyncreplConfiguration> createReplProviderConfigs() throws Exception
- {
- EqualityNode<String> filter = new EqualityNode<String>( OBJECT_CLASS_AT, new StringValue(
- ConfigSchemaConstants.ADS_REPL_PROVIDER_OC ) );
-
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
-
- IndexCursor<Long, Entry, Long> cursor = se.cursor( configPartition.getSuffix(),
- AliasDerefMode.NEVER_DEREF_ALIASES, filter, controls );
-
- List<SyncreplConfiguration> syncReplConfigLst = new ArrayList<SyncreplConfiguration>();
-
- if ( !cursor.next() )
- {
- return syncReplConfigLst;
- }
-
- do
- {
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor.get();
-
- ClonedServerEntry entry = configPartition.lookup( forwardEntry.getId() );
-
- LOG.debug( "syncrepl configuration entry {}", entry );
-
- if( !isEnabled( entry ) )
- {
- continue;
- }
-
- SyncreplConfiguration config = new SyncreplConfiguration();
-
- // mandatory attribues
- config.setReplicaId( getInt( ConfigSchemaConstants.ADS_DS_REPLICA_ID, entry ) );
- config.setProviderHost( entry.get( ConfigSchemaConstants.ADS_REPL_PROV_HOST_NAME ).getString() );
- config.setBaseDn( entry.get( ConfigSchemaConstants.ADS_SEARCH_BASE ).getString() );
-
- // optional attributes
-
- EntryAttribute aliasDerefAttr = entry.get( ConfigSchemaConstants.ADS_REPL_ALIAS_DEREF_MODE );
- if( aliasDerefAttr != null )
- {
- config.setAliasDerefMode( AliasDerefMode.getDerefMode( getInt( aliasDerefAttr ) ) );
- }
-
- EntryAttribute replSrchAtAttr = entry.get( ConfigSchemaConstants.ADS_REPL_ATTRIBUTE );
- if( replSrchAtAttr != null )
- {
- int size = replSrchAtAttr.size();
- String[] attrNames = new String[ size ];
- for( int i=0; i< size; i++ )
- {
- attrNames[i] = replSrchAtAttr.get( i ).getString();
- }
-
- config.setAttributes( attrNames );
- }
-
- EntryAttribute provPortAttr = entry.get( ConfigSchemaConstants.ADS_REPL_PROV_PORT );
- if( provPortAttr != null )
- {
- config.setPort( getInt( provPortAttr ) );
- }
-
- EntryAttribute refreshIntAttr = entry.get( ConfigSchemaConstants.ADS_REPL_REFRESH_INTERVAL );
- if( refreshIntAttr != null )
- {
- config.setRefreshInterval( getInt( refreshIntAttr) );
- }
-
- EntryAttribute refNPersistAttr = entry.get( ConfigSchemaConstants.ADS_REPL_REFRESH_N_PERSIST );
- if( refNPersistAttr != null )
- {
- config.setRefreshNPersist( Boolean.parseBoolean( refNPersistAttr.getString() ) );
- }
-
- EntryAttribute searchScopeAttr = entry.get( ConfigSchemaConstants.ADS_REPL_SEARCH_SCOPE );
- if( searchScopeAttr != null )
- {
- config.setSearchScope( SearchScope.getSearchScope( getInt( searchScopeAttr ) ) );
- }
-
- EntryAttribute searchFilterAttr = entry.get( ConfigSchemaConstants.ADS_REPL_SEARCH_FILTER );
- if( searchFilterAttr != null )
- {
- config.setFilter( searchFilterAttr.getString() );
- }
-
- EntryAttribute searchSizeAttr = entry.get( ConfigSchemaConstants.ADS_REPL_SEARCH_SIZE_LIMIT );
- if( searchSizeAttr != null )
- {
- config.setSearchSizeLimit( getInt( searchSizeAttr ) );
- }
-
- EntryAttribute searchTimeAttr = entry.get( ConfigSchemaConstants.ADS_REPL_SEARCH_TIMEOUT );
- if( searchTimeAttr != null )
- {
- config.setSearchTimeout( getInt( searchTimeAttr ) );
- }
-
-
- EntryAttribute replUserAttr = entry.get( ConfigSchemaConstants.ADS_REPL_USER_DN );
- if( replUserAttr != null )
- {
- config.setReplUserDn( replUserAttr.getString() );
- }
-
- EntryAttribute replUserPwdAttr = entry.get( ConfigSchemaConstants.ADS_REPL_USER_PASSWORD );
- if( replUserPwdAttr != null )
- {
- config.setReplUserPassword( replUserPwdAttr.getBytes() );
- }
-
- EntryAttribute replCookieAttr = entry.get( ConfigSchemaConstants.ADS_REPL_COOKIE );
- if( replCookieAttr != null )
- {
- config.setCookie( replCookieAttr.getBytes() );
- }
-
- EntryAttribute replUseTls = entry.get( ConfigSchemaConstants.ADS_REPL_USE_TLS );
- if( replUseTls != null )
- {
- config.setUseTls( Boolean.parseBoolean( replUseTls.getString() ) );
- }
-
- EntryAttribute replPeerCertificate = entry.get( ConfigSchemaConstants.ADS_REPL_PEER_CERTIFICATE );
- if( replPeerCertificate != null )
- {
- // directly add to the ReplicationTrustManager instead of storing it in the config
- ReplicationTrustManager.addCertificate( String.valueOf( config.getReplicaId() ), replPeerCertificate.getBytes() );
- }
- else
- {
- config.setStrictCertVerification( false );
- }
-
- syncReplConfigLst.add( config );
- }
- while( cursor.next() );
-
- cursor.close();
-
- return syncReplConfigLst;
- }
-
-
- /**
- * reads the Interceptor configuration and instantiates them in the order specified
- *
- * @param dirServiceDN the DN under which interceptors are configured
- * @return a list of InterceptorBean objects
- * @throws Exception If the configuraton cannot be read
- */
- private Set<InterceptorBean> readInterceptors( DN dirServiceDN ) throws Exception
- {
- AttributeType adsInterceptorIdAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_INTERCEPTOR_ID );
- PresenceNode filter = new PresenceNode( adsInterceptorIdAt );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- IndexCursor<Long, Entry, Long> cursor = se.cursor( dirServiceDN, AliasDerefMode.NEVER_DEREF_ALIASES,
- filter, controls );
-
- Set<InterceptorBean> interceptorBeans = new TreeSet<InterceptorBean>();
-
- while ( cursor.next() )
- {
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- Entry interceptorEntry = configPartition.lookup( forwardEntry.getId() );
-
- if( ! isEnabled( interceptorEntry ) )
- {
- continue;
- }
-
- String id = getString( ConfigSchemaConstants.ADS_INTERCEPTOR_ID, interceptorEntry );
- String fqcn = getString( ConfigSchemaConstants.ADS_INTERCEPTOR_CLASSNAME, interceptorEntry );
- int order = getInt( ConfigSchemaConstants.ADS_INTERCEPTOR_ORDER, interceptorEntry );
-
- InterceptorBean interceptorBean = new InterceptorBean();
-
- interceptorBean.setInterceptorId( id );
- interceptorBean.setFqcn( fqcn );
- interceptorBean.setInterceptorOrder( order );
-
- interceptorBeans.add( interceptorBean );
- }
-
- cursor.close();
-
- return interceptorBeans;
- }
-
-
- /**
- * Creates the Interceptor instances from the configuration
- *
- * @param dirServiceDN the DN under which interceptors are configured
- * @return a list of instantiated Interceptor objects
- * @throws Exception If the instanciation failed
- */
- private List<Interceptor> createInterceptors( DN dirServiceDN ) throws Exception
- {
- Set<InterceptorBean> interceptorBeans = readInterceptors( dirServiceDN );
-
- List<Interceptor> interceptors = new ArrayList<Interceptor>( interceptorBeans.size() );
-
- for ( InterceptorBean interceptorBean : interceptorBeans )
- {
- try
- {
- LOG.debug( "loading the interceptor class {} and instantiating", interceptorBean.getInterceptorClassName() );
- Interceptor ic = ( Interceptor ) Class.forName( interceptorBean.getInterceptorClassName() ).newInstance();
- interceptors.add( ic );
- }
- catch ( Exception e )
- {
- throw e;
- }
- }
-
- return interceptors;
- }
-
-
- /**
- * Read the Partition from the configuration in DIT
- *
- * @param dirServiceDN the DN under which Partitions are configured
- * @return A map of partitions
- * @throws Exception If we cannot read some partition
- */
- private Map<String, PartitionBean> readPartitions( DN dirServiceDN ) throws Exception
- {
- AttributeType adsPartitionIdeAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_PARTITION_ID );
- PresenceNode filter = new PresenceNode( adsPartitionIdeAt );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- IndexCursor<Long, Entry, Long> cursor = se.cursor( dirServiceDN, AliasDerefMode.NEVER_DEREF_ALIASES,
- filter, controls );
-
- Map<String, PartitionBean> partitionBeans = new HashMap<String, PartitionBean>();
-
- while ( cursor.next() )
- {
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- Entry partitionEntry = configPartition.lookup( forwardEntry.getId() );
-
- if ( !isEnabled( partitionEntry ) )
- {
- continue;
- }
-
- EntryAttribute ocAttr = partitionEntry.get( OBJECT_CLASS_AT );
-
- if ( ocAttr.contains( ConfigSchemaConstants.ADS_JDBMPARTITION ) )
- {
- JdbmPartitionBean jdbmPartitionBean = readJdbmPartition( partitionEntry );
- partitionBeans.put( jdbmPartitionBean.getPartitionId(), jdbmPartitionBean );
- }
- else
- {
- throw new NotImplementedException( I18n.err( I18n.ERR_506 ) );
- }
- }
-
- cursor.close();
-
- return partitionBeans;
- }
-
-
- /**
- * Create the set of Partitions instanciated from the configuration
- *
- * @param dirServiceDN the DN under which Partitions are configured
- * @return A Map of all the instanciated partitions
- * @throws Exception If we cannot process some Partition
- */
- public Map<String, Partition> createPartitions( DN dirServiceDN ) throws Exception
- {
- Map<String, PartitionBean> partitionBeans = readPartitions( dirServiceDN );
- Map<String, Partition> partitions = new HashMap<String, Partition>( partitionBeans.size() );
-
- for ( String key : partitionBeans.keySet() )
- {
- PartitionBean partitionBean = partitionBeans.get( key );
-
- JdbmPartition partition = createJdbmPartition( (JdbmPartitionBean)partitionBean );
- partitions.put( key, partition );
- }
-
- return partitions;
- }
-
-
- /**
- * Read the JdbmPartitionBean from the configuration in DIT
- *
- * @param partitionEntry The Entry containing the configuration for this partition
- * @return An bean containing the JdbmPartition configuration
- * @throws Exception If the configuration cannot be read
- */
- public JdbmPartitionBean readJdbmPartition( Entry partitionEntry ) throws Exception
- {
- JdbmPartitionBean jdbmPartitionBean = new JdbmPartitionBean();
-
- jdbmPartitionBean.setPartitionId( getString( ConfigSchemaConstants.ADS_PARTITION_ID, partitionEntry ) );
- //jdbmPartitionBean.setPartitionDir( workDir + File.separator + jdbmPartitionBean.getPartitionId() );
-
- DN systemDn = new DN( getString( ConfigSchemaConstants.ADS_PARTITION_SUFFIX, partitionEntry ), schemaManager );
- jdbmPartitionBean.setPartitionSuffix( systemDn );
-
- EntryAttribute cacheAttr = partitionEntry.get( ConfigSchemaConstants.ADS_PARTITION_CACHE_SIZE );
-
- if ( cacheAttr != null )
- {
- jdbmPartitionBean.setPartitionCacheSize( Integer.parseInt( cacheAttr.getString() ) );
- }
-
- EntryAttribute optimizerAttr = partitionEntry.get( ConfigSchemaConstants.ADS_JDBM_PARTITION_OPTIMIZER_ENABLED );
-
- if ( optimizerAttr != null )
- {
- jdbmPartitionBean.setJdbmPartitionOptimizerEnabled( Boolean.parseBoolean( optimizerAttr.getString() ) );
- }
-
- EntryAttribute syncAttr = partitionEntry.get( ConfigSchemaConstants.ADS_PARTITION_SYNCONWRITE );
-
- if ( syncAttr != null )
- {
- jdbmPartitionBean.setPartitionSyncOnWrite( Boolean.parseBoolean( syncAttr.getString() ) );
- }
-
- Set<JdbmIndexBean<String, Entry>> indexedAttributes = readIndexes( partitionEntry.getDn() );
- jdbmPartitionBean.setIndexedAttributes( indexedAttributes );
-
- return jdbmPartitionBean;
- }
-
-
- /**
- * Create a new instance of a JdbmPartition from an instance of JdbmIndexBean
- *
- * @param partitionEntry The entry containing the JdbmPartition configuration
- * @return An JdbmPartition instance
- * @throws Exception If the instance cannot be created
- */
- public JdbmPartition createJdbmPartition( Entry partitionEntry ) throws Exception
- {
- JdbmPartition partition = new JdbmPartition();
- JdbmPartitionBean jdbmPartitionBean = readJdbmPartition( partitionEntry );
-
- partition.setSchemaManager( schemaManager );
- partition.setCacheSize( jdbmPartitionBean.getPartitionCacheSize() );
- partition.setId( jdbmPartitionBean.getPartitionId() );
- partition.setOptimizerEnabled( jdbmPartitionBean.isJdbmPartitionOptimizerEnabled() );
- partition.setPartitionDir( new File( workDir + File.separator + jdbmPartitionBean.getPartitionId() ) );
- partition.setSuffix( jdbmPartitionBean.getPartitionSuffix() );
- partition.setSyncOnWrite( jdbmPartitionBean.isPartitionSyncOnWrite() );
- partition.setIndexedAttributes( createIndexes( jdbmPartitionBean.getJdbmIndexes() ) );
-
- return partition;
- }
-
-
- /**
- * Create a new instance of a JdbmPartition from an instance of JdbmIndexBean
- *
- * @param partitionEntry The entry containing the JdbmPartition configuration
- * @return An JdbmPartition instance
- * @throws Exception If the instance cannot be created
- */
- private JdbmPartition createJdbmPartition( JdbmPartitionBean jdbmPartitionBean ) throws Exception
- {
- JdbmPartition partition = new JdbmPartition();
-
- partition.setSchemaManager( schemaManager );
- partition.setCacheSize( jdbmPartitionBean.getPartitionCacheSize() );
- partition.setId( jdbmPartitionBean.getPartitionId() );
- partition.setOptimizerEnabled( jdbmPartitionBean.isJdbmPartitionOptimizerEnabled() );
- partition.setPartitionDir( new File( workDir + File.separator + jdbmPartitionBean.getPartitionId() ) );
- partition.setSuffix( jdbmPartitionBean.getPartitionSuffix() );
- partition.setSyncOnWrite( jdbmPartitionBean.isPartitionSyncOnWrite() );
- partition.setIndexedAttributes( createIndexes( jdbmPartitionBean.getJdbmIndexes() ) );
-
- return partition;
- }
-
-
- private Set<JdbmIndexBean<String, Entry>> readIndexes( DN partitionDN ) throws Exception
- {
- AttributeType adsIndexAttributeIdAt = schemaManager.getAttributeType( ConfigSchemaConstants.ADS_INDEX_ATTRIBUTE_ID );
- PresenceNode filter = new PresenceNode( adsIndexAttributeIdAt );
- SearchControls controls = new SearchControls();
- controls.setSearchScope( SearchControls.SUBTREE_SCOPE );
- IndexCursor<Long, Entry, Long> cursor = se.cursor( partitionDN, AliasDerefMode.NEVER_DEREF_ALIASES, filter,
- controls );
-
- Set<JdbmIndexBean<String, Entry>> indexesBean = new HashSet<JdbmIndexBean<String, Entry>>();
-
- while ( cursor.next() )
- {
- ForwardIndexEntry<Long, Entry, Long> forwardEntry = ( ForwardIndexEntry<Long, Entry, Long> ) cursor
- .get();
- Entry indexEntry = configPartition.lookup( forwardEntry.getId() );
-
- if ( !isEnabled( indexEntry ) )
- {
- continue;
- }
-
- EntryAttribute ocAttr = indexEntry.get( OBJECT_CLASS_AT );
-
- if ( ocAttr.contains( ConfigSchemaConstants.ADS_JDBMINDEX ) )
- {
- indexesBean.add( readJdbmIndex( indexEntry ) );
- }
- else
- {
- throw new NotImplementedException( I18n.err( I18n.ERR_506 ) );
- }
- }
-
- return indexesBean;
- }
-
-
- private Set<Index<?, Entry, Long>> createIndexes( DN partitionDN ) throws Exception
- {
- Set<JdbmIndexBean<String, Entry>> indexesBean = readIndexes( partitionDN );
-
- Set<Index<?, Entry, Long>> indexes = new HashSet<Index<?, Entry, Long>>();
-
- for ( JdbmIndexBean<String, Entry> indexBean : indexesBean )
- {
- indexes.add( createJdbmIndex( indexBean ) );
- }
-
- return indexes;
- }
-
-
- private Set<Index<?, Entry, Long>> createIndexes( Set<JdbmIndexBean<String, Entry>> indexesBean ) throws Exception
- {
- Set<Index<?, Entry, Long>> indexes = new HashSet<Index<?, Entry, Long>>();
-
- for ( JdbmIndexBean<String, Entry> indexBean : indexesBean )
- {
- indexes.add( createJdbmIndex( indexBean ) );
- }
-
- return indexes;
- }
-
-
- /**
- * Read the JdbmIndex from the configuration in DIT
- *
- * @param indexEntry The Entry containing the configuration for this index
- * @return An bean containing the JdbmEntry configuration
- * @throws Exception If the configuration cannot be read
- */
- public JdbmIndexBean<String, Entry> readJdbmIndex( Entry indexEntry ) throws Exception
- {
- JdbmIndexBean<String, Entry> index = new JdbmIndexBean<String, Entry>();
- index.setIndexAttributeId( getString( ConfigSchemaConstants.ADS_INDEX_ATTRIBUTE_ID, indexEntry ) );
- EntryAttribute cacheAttr = indexEntry.get( ConfigSchemaConstants.ADS_INDEX_CACHESIZE );
-
- if ( cacheAttr != null )
- {
- index.setIndexCacheSize( Integer.parseInt( cacheAttr.getString() ) );
- }
-
- EntryAttribute numDupAttr = indexEntry.get( ConfigSchemaConstants.ADS_INDEX_NUM_DUP_LIMIT );
-
- if ( numDupAttr != null )
- {
- index.setIndexNumDupLimit( Integer.parseInt( numDupAttr.getString() ) );
- }
-
- return index;
- }
-
-
- /**
- * Create a new instance of a JdbmIndex from the configuration read from the DIT
- *
- * @param indexEntry The entry containing the JdbmIndex configuration
- * @return An JdbmIndex instance
- * @throws Exception If the instance cannot be created
- */
- public JdbmIndex<?, Entry> createJdbmIndex( Entry indexEntry ) throws Exception
- {
- JdbmIndex<String, Entry> index = new JdbmIndex<String, Entry>();
- JdbmIndexBean<String, Entry> indexBean = readJdbmIndex( indexEntry );
-
- index.setAttributeId( indexBean.getIndexAttributeId() );
- index.setCacheSize( indexBean.getIndexCacheSize() );
- index.setNumDupLimit( indexBean.getIndexNumDupLimit() );
-
- return index;
- }
-
-
- /**
- * Create a new instance of a JdbmIndex from an instance of JdbmIndexBean
- *
- * @param JdbmIndexBean The JdbmIndexBean to convert
- * @return An JdbmIndex instance
- * @throws Exception If the instance cannot be created
- */
[... 739 lines stripped ...]