From a849a42d97109bc9242c50c7abbd9857e865bb5e Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 24 Jun 2011 14:57:52 +0000
Subject: [PATCH] Fix OPENDJ-205: Add support for rejecting and skipping records to the LDIF readers
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java | 50 ++++++++++++++++++++++++++++++++++----------------
1 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
index 5f13925..5e15fb0 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFEntryReader.java
@@ -43,6 +43,7 @@
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.*;
import org.forgerock.opendj.ldap.schema.Schema;
+import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy;
import com.forgerock.opendj.util.Validator;
@@ -393,32 +394,34 @@
public LDIFEntryReader setSchema(final Schema schema)
{
Validator.ensureNotNull(schema);
- this.schema = validateSchema ? schema.asStrictSchema() : schema
- .asNonStrictSchema();
+ this.schema = schemaValidationPolicy.checkAttributesAndObjectClasses()
+ .needsChecking() ? schema.asStrictSchema() : schema.asNonStrictSchema();
return this;
}
/**
- * Specifies whether or not schema validation should be performed for entries
- * that are read from LDIF.
- * <p>
- * When enabled, this LDIF reader will implicitly use a strict schema so that
- * unrecognized attribute types will be detected.
+ * Specifies the schema validation which should be used when reading LDIF
+ * entry records. If attribute value validation is enabled then all checks
+ * will be performed.
* <p>
* Schema validation is disabled by default.
+ * <p>
+ * <b>NOTE:</b> this method copies the provided policy so changes made to it
+ * after this method has been called will have no effect.
*
- * @param validateSchema
- * {@code true} if schema validation should be performed, or
- * {@code false} otherwise.
+ * @param policy
+ * The schema validation which should be used when reading LDIF entry
+ * records.
* @return A reference to this {@code LDIFEntryReader}.
*/
- public LDIFEntryReader setValidateSchema(final boolean validateSchema)
+ public LDIFEntryReader setSchemaValidationPolicy(
+ final SchemaValidationPolicy policy)
{
- this.validateSchema = validateSchema;
- this.schema = validateSchema ? schema.asStrictSchema() : schema
- .asNonStrictSchema();
+ this.schemaValidationPolicy = SchemaValidationPolicy.copyOf(policy);
+ this.schema = schemaValidationPolicy.checkAttributesAndObjectClasses()
+ .needsChecking() ? schema.asStrictSchema() : schema.asNonStrictSchema();
return this;
}
@@ -458,11 +461,16 @@
// Use an Entry for the AttributeSequence.
final Entry entry = new LinkedHashMapEntry(entryDN);
+ boolean schemaValidationFailure = false;
final List<LocalizableMessage> schemaErrors = new LinkedList<LocalizableMessage>();
while (record.iterator.hasNext())
{
final String ldifLine = record.iterator.next();
- readLDIFRecordAttributeValue(record, ldifLine, entry, schemaErrors);
+ if (!readLDIFRecordAttributeValue(record, ldifLine, entry,
+ schemaErrors))
+ {
+ schemaValidationFailure = true;
+ }
}
// Skip if the entry is excluded by any filters.
@@ -474,12 +482,22 @@
continue;
}
- if (!schemaErrors.isEmpty())
+ if (!schema.validateEntry(entry, schemaValidationPolicy, schemaErrors))
+ {
+ schemaValidationFailure = true;
+ }
+
+ if (schemaValidationFailure)
{
handleSchemaValidationFailure(record, schemaErrors);
continue;
}
+ if (!schemaErrors.isEmpty())
+ {
+ handleSchemaValidationWarning(record, schemaErrors);
+ }
+
nextEntry = entry;
}
catch (final DecodeException e)
--
Gitblit v1.10.0