You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2010/12/20 14:30:42 UTC
svn commit: r1051098 - in /directory/apacheds/trunk/server-config/src:
main/java/org/apache/directory/server/config/
main/java/org/apache/directory/server/config/beans/
test/java/org/apache/directory/server/config/
Author: pamarcelot
Date: Mon Dec 20 13:30:41 2010
New Revision: 1051098
URL: http://svn.apache.org/viewvc?rev=1051098&view=rev
Log:
Added an 'optional' flag and a default value to the ConfigurationElement annotation to allow the writer to exclude attributes with default values from the generated LDIF entries.
Modified:
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigurationElement.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/DirectoryServiceBean.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JdbmIndexBean.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/PasswordPolicyBean.java
directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigWriter.java Mon Dec 20 13:30:41 2010
@@ -403,6 +403,16 @@ public class ConfigWriter
// Adding the field value to the parent entry
addAttributeTypeValues( attributeTypeForParentEntry, fieldValue, parentEntry );
}
+
+ // Checking if the field is optional and if the default value matches
+ if ( configurationElement.isOptional() )
+ {
+ if ( configurationElement.defaultValue().equalsIgnoreCase( fieldValue.toString() ) )
+ {
+ // Skipping the additin of the value
+ continue;
+ }
+ }
// Adding values to the entry
addAttributeTypeValues( configurationElement.attributeType(), fieldValue, entry );
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigurationElement.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigurationElement.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigurationElement.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/ConfigurationElement.java Mon Dec 20 13:30:41 2010
@@ -67,4 +67,23 @@ public @interface ConfigurationElement
* the string value of the DN of the container.
*/
String container() default "";
+
+
+ /**
+ * Returns true if the qualified field is optional.
+ *
+ * @return
+ * <code>true</code> if the qualified field is optional,
+ * <code>false</code> if not.
+ */
+ boolean isOptional() default false;
+
+
+ /**
+ * Returns the string value of the default value.
+ *
+ * @return
+ * the string value of the default value
+ */
+ String defaultValue() default "";
}
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/DirectoryServiceBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/DirectoryServiceBean.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/DirectoryServiceBean.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/DirectoryServiceBean.java Mon Dec 20 13:30:41 2010
@@ -58,7 +58,7 @@ public class DirectoryServiceBean extend
private int dsMaxPDUSize = 2048;
/** The flag that tells if the password should be returned as a normal attribute or not */
- @ConfigurationElement(attributeType = "ads-dsPasswordHidden")
+ @ConfigurationElement(attributeType = "ads-dsPasswordHidden", isOptional = true, defaultValue = "false")
private boolean dsPasswordHidden = false;
/** The delay between two flushes on disk */
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JdbmIndexBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JdbmIndexBean.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JdbmIndexBean.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/JdbmIndexBean.java Mon Dec 20 13:30:41 2010
@@ -41,7 +41,7 @@ public class JdbmIndexBean<K, E> extends
private int indexCacheSize = DEFAULT_INDEX_CACHE_SIZE;
/** duplicate limit before duplicate keys switch to using a btree for values */
- @ConfigurationElement(attributeType = "ads-indexNumDupLimit")
+ @ConfigurationElement(attributeType = "ads-indexNumDupLimit", isOptional = true, defaultValue = "512")
private int indexNumDupLimit = DEFAULT_DUPLICATE_LIMIT;
/** The index file name */
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/PasswordPolicyBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/PasswordPolicyBean.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/PasswordPolicyBean.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/PasswordPolicyBean.java Mon Dec 20 13:30:41 2010
@@ -49,7 +49,7 @@ public class PasswordPolicyBean extends
* holds the number of seconds that must elapse between modifications to the password.
* Default value is 0
*/
- @ConfigurationElement(attributeType = "ads-pwdMinAge")
+ @ConfigurationElement(attributeType = "ads-pwdMinAge", isOptional = true, defaultValue = "0")
private int pwdMinAge = 0;
/**
@@ -57,33 +57,33 @@ public class PasswordPolicyBean extends
* Default value is 0, does not expire. If not 0, the value must be greater than or equal
* to the value of the pwdMinAge.
*/
- @ConfigurationElement(attributeType = "ads-pwdMaxAge")
- private int pwdMaxAge;
+ @ConfigurationElement(attributeType = "ads-pwdMaxAge", isOptional = true, defaultValue = "0")
+ private int pwdMaxAge = 0;
/**
* specifies the maximum number of used passwords stored in the pwdHistory attribute.
* Default value is 0, no password history maintained
*/
- @ConfigurationElement(attributeType = "ads-pwdInHistory")
+ @ConfigurationElement(attributeType = "ads-pwdInHistory", isOptional = true, defaultValue = "0")
private int pwdInHistory = 0;
/** indicates how the password quality will be verified while being modified or added.
* Default value 0, do not check
*/
- @ConfigurationElement(attributeType = "ads-pwdCheckQuality")
+ @ConfigurationElement(attributeType = "ads-pwdCheckQuality", isOptional = true, defaultValue = "0")
private int pwdCheckQuality = 0;
/** this attribute holds the minimum number of characters that must be used in a password.
* Default value 0, no minimum length enforced
*/
- @ConfigurationElement(attributeType = "ads-pwdMinLength")
+ @ConfigurationElement(attributeType = "ads-pwdMinLength", isOptional = true, defaultValue = "0")
private int pwdMinLength = 0;
/**
* this attribute holds the maximum number of characters that may be used in a password.
* Default value 0, no maximum length enforced
*/
- @ConfigurationElement(attributeType = "ads-pwdMaxLength")
+ @ConfigurationElement(attributeType = "ads-pwdMaxLength", isOptional = true, defaultValue = "0")
private int pwdMaxLength = 0;
/**
@@ -91,21 +91,21 @@ public class PasswordPolicyBean extends
* messages will be returned to an authenticating user.
* Default value is 0, never send a warning message.
*/
- @ConfigurationElement(attributeType = "ads-pwdExpireWarning")
+ @ConfigurationElement(attributeType = "ads-pwdExpireWarning", isOptional = true, defaultValue = "0")
private int pwdExpireWarning = 0;
/**
* the number of times an expired password can be used to authenticate.
* Default value is 0, do not allow a expired password for authentication.
*/
- @ConfigurationElement(attributeType = "ads-pwdGraceAuthNLimit")
+ @ConfigurationElement(attributeType = "ads-pwdGraceAuthNLimit", isOptional = true, defaultValue = "0")
private int pwdGraceAuthNLimit = 0;
/**
* specifies the number of seconds the grace authentications are valid
* Default value is 0, no limit.
*/
- @ConfigurationElement(attributeType = "ads-pwdGraceExpire")
+ @ConfigurationElement(attributeType = "ads-pwdGraceExpire", isOptional = true, defaultValue = "0")
private int pwdGraceExpire = 0;
/**
@@ -113,15 +113,15 @@ public class PasswordPolicyBean extends
* consecutive failed bind attempts. The maximum number of consecutive
* failed bind attempts is specified in {@link #pwdMaxFailure}
*/
- @ConfigurationElement(attributeType = "ads-pwdLockout")
- private boolean pwdLockout;
+ @ConfigurationElement(attributeType = "ads-pwdLockout", isOptional = true, defaultValue = "false")
+ private boolean pwdLockout = false;
/**
* the number of seconds that the password cannot be used to authenticate due to
* too many failed bind attempts.
* Default value is 300 seconds.
*/
- @ConfigurationElement(attributeType = "ads-pwdLockoutDuration")
+ @ConfigurationElement(attributeType = "ads-pwdLockoutDuration", isOptional = true, defaultValue = "300")
private int pwdLockoutDuration = 300;
/**
@@ -129,26 +129,26 @@ public class PasswordPolicyBean extends
* be used to authenticate.
* Default value is 0, no limit on the number of authentication failures
*/
- @ConfigurationElement(attributeType = "ads-pwdMaxFailure")
- private int pwdMaxFailure;
+ @ConfigurationElement(attributeType = "ads-pwdMaxFailure", isOptional = true, defaultValue = "0")
+ private int pwdMaxFailure = 0;
/**
* the number of seconds after which the password failures are purged from the failure counter.
* Default value is 0, reset all pwdFailureTimes after a successful authentication.
*/
- @ConfigurationElement(attributeType = "ads-pwdFailureCountInterval")
- private int pwdFailureCountInterval;
+ @ConfigurationElement(attributeType = "ads-pwdFailureCountInterval", isOptional = true, defaultValue = "0")
+ private int pwdFailureCountInterval = 0;
/**
* flag to indicate if the password must be changed by the user after they bind to the
* directory after a password is set or reset by a password administrator.
* Default value is false, no need to change the password by user.
*/
- @ConfigurationElement(attributeType = "ads-pwdMustChange")
+ @ConfigurationElement(attributeType = "ads-pwdMustChange", isOptional = true, defaultValue = "false")
private boolean pwdMustChange = false;
/** indicates whether users can change their own passwords. Default value is true, allow change */
- @ConfigurationElement(attributeType = "ads-pwdAllowUserChange")
+ @ConfigurationElement(attributeType = "ads-pwdAllowUserChange", isOptional = true, defaultValue = "true")
private boolean pwdAllowUserChange = true;
/**
@@ -156,26 +156,26 @@ public class PasswordPolicyBean extends
* new password when being changed.
* Default value is false.
*/
- @ConfigurationElement(attributeType = "ads-pwdSafeModify")
+ @ConfigurationElement(attributeType = "ads-pwdSafeModify", isOptional = true, defaultValue = "false")
private boolean pwdSafeModify = false;
/**
* the number of seconds to delay responding to the first failed authentication attempt
* Default value 0, no delay.
*/
- @ConfigurationElement(attributeType = "ads-pwdMinDelay")
+ @ConfigurationElement(attributeType = "ads-pwdMinDelay", isOptional = true, defaultValue = "0")
private int pwdMinDelay = 0;
/** the maximum number of seconds to delay when responding to a failed authentication attempt.*/
- @ConfigurationElement(attributeType = "ads-pwdMaxDelay")
- private int pwdMaxDelay;
+ @ConfigurationElement(attributeType = "ads-pwdMaxDelay", isOptional = true, defaultValue = "0")
+ private int pwdMaxDelay = 0;
/**
* the number of seconds an account may remain unused before it becomes locked
* Default value is 0, no check for idle time.
*/
- @ConfigurationElement(attributeType = "ads-pwdMaxIdle")
- private int pwdMaxIdle;
+ @ConfigurationElement(attributeType = "ads-pwdMaxIdle", isOptional = true, defaultValue = "0")
+ private int pwdMaxIdle = 0;
public String getPwdAttribute()
Modified: directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java (original)
+++ directory/apacheds/trunk/server-config/src/main/java/org/apache/directory/server/config/beans/TransportBean.java Mon Dec 20 13:30:41 2010
@@ -49,15 +49,15 @@ public class TransportBean extends AdsBa
private int systemPort = -1;
/** A flag set if SSL is enabled */
- @ConfigurationElement(attributeType = "ads-transportEnableSsl")
+ @ConfigurationElement(attributeType = "ads-transportEnableSsl", isOptional = true, defaultValue = "false")
private boolean transportEnableSsl = false;
/** The number of threads to use for the IoAcceptor executor */
- @ConfigurationElement(attributeType = "ads-transportNbThreads")
+ @ConfigurationElement(attributeType = "ads-transportNbThreads", isOptional = true, defaultValue = "3")
private int transportNbThreads = DEFAULT_NB_THREADS;
/** The backlog for the transport services */
- @ConfigurationElement(attributeType = "ads-transportBackLog")
+ @ConfigurationElement(attributeType = "ads-transportBackLog", isOptional = true, defaultValue = "50")
private int transportBackLog = DEFAULT_BACKLOG_NB;
Modified: directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java?rev=1051098&r1=1051097&r2=1051098&view=diff
==============================================================================
--- directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java (original)
+++ directory/apacheds/trunk/server-config/src/test/java/org/apache/directory/server/config/ConfigWriterTest.java Mon Dec 20 13:30:41 2010
@@ -42,6 +42,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.ldif.LdifEntry;
import org.apache.directory.shared.ldap.ldif.LdifReader;
import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.SchemaManager;
import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
@@ -55,7 +56,7 @@ import org.junit.runner.RunWith;
/**
- * Test class for ConfigPartitionReader
+ * Test class for ConfigWriter
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@@ -104,10 +105,10 @@ public class ConfigWriterTest
@Test
- public void testConfigReader() throws Exception
+ public void testConfigWriter() throws Exception
{
// Extracting of the config file
- File configDir = new File( workDir, "configReader" ); // could be any directory, cause the config is now in a single file
+ File configDir = new File( workDir, "configWriter" ); // could be any directory, cause the config is now in a single file
String configFile = LdifConfigExtractor.extractSingleFileConfig( configDir, "config.ldif", true );
// Creating of the config partition
@@ -158,17 +159,6 @@ public class ConfigWriterTest
// Comparing DNs
assertTrue( originalConfigEntry.getDn().getNormName().equals( generatedConfigEntry.getDn().getNormName() ) );
-
- // Comparing attributes
- Iterator<EntryAttribute> attributesIterator = originalConfigEntry.iterator();
- while ( attributesIterator.hasNext() )
- {
- EntryAttribute originalEntryAttribute = ( EntryAttribute ) attributesIterator.next();
- assertTrue( generatedConfigEntry.contains( originalEntryAttribute ) );
-
- EntryAttribute generatedEntryAttribute = generatedConfigEntry.get( originalEntryAttribute.getId() );
- assertTrue( originalEntryAttribute.equals( generatedEntryAttribute ) );
- }
}
// Destroying the config partition