| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2013 ForgeRock AS |
| | | * Portions copyright 2011-2012 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | |
| | | this.isStrict = isStrict; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedNamesAndOptions() { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowNonStandardTelephoneNumbers() { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedJPEGPhotos() { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowZeroLengthDirectoryStrings() { |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public Syntax getDefaultSyntax() { |
| | | return Schema.getCoreSchema().getDefaultSyntax(); |
| | | } |
| | | |
| | | @Override |
| | | public MatchingRule getDefaultMatchingRule() { |
| | | return Schema.getCoreSchema().getDefaultMatchingRule(); |
| | | } |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public String getSchemaName() { |
| | | return "Empty Schema"; |
| | |
| | | this.strictImpl = strictImpl; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedNamesAndOptions() { |
| | | return strictImpl.allowMalformedNamesAndOptions(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedJPEGPhotos() { |
| | | return strictImpl.allowMalformedJPEGPhotos(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowNonStandardTelephoneNumbers() { |
| | | return strictImpl.allowNonStandardTelephoneNumbers(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowZeroLengthDirectoryStrings() { |
| | | return strictImpl.allowZeroLengthDirectoryStrings(); |
| | | } |
| | | |
| | | @Override |
| | | public Syntax getDefaultSyntax() { |
| | | return strictImpl.getDefaultSyntax(); |
| | | } |
| | | |
| | | @Override |
| | | public MatchingRule getDefaultMatchingRule() { |
| | | return strictImpl.getDefaultMatchingRule(); |
| | | } |
| | |
| | | this.warnings = Collections.unmodifiableList(warnings); |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedNamesAndOptions() { |
| | | return allowMalformedNamesAndOptions; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowMalformedJPEGPhotos() { |
| | | return allowMalformedJPEGPhotos; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowNonStandardTelephoneNumbers() { |
| | | return allowNonStandardTelephoneNumbers; |
| | | } |
| | | |
| | | @Override |
| | | public boolean allowZeroLengthDirectoryStrings() { |
| | | return allowZeroLengthDirectoryStrings; |
| | | } |
| | | |
| | | @Override |
| | | public Syntax getDefaultSyntax() { |
| | | return defaultSyntax; |
| | | } |
| | | |
| | | @Override |
| | | public MatchingRule getDefaultMatchingRule() { |
| | | return defaultMatchingRule; |
| | | } |
| | |
| | | public boolean validateEntry(final Entry entry, final SchemaValidationPolicy policy, |
| | | final Collection<LocalizableMessage> errorMessages) { |
| | | // First check that the object classes are recognized and that there is |
| | | // one |
| | | // structural object class. |
| | | // one structural object class. |
| | | ObjectClass structuralObjectClass = null; |
| | | final Attribute objectClassAttribute = entry.getAttribute(objectClass()); |
| | | final List<ObjectClass> objectClasses = new LinkedList<ObjectClass>(); |
| | |
| | | } |
| | | |
| | | // Check that the name of the entry conforms to at least one applicable |
| | | // name |
| | | // form. |
| | | // name form. |
| | | if (policy.checkNameForms().needsChecking() && structuralObjectClass != null) { |
| | | /** |
| | | * There may be multiple name forms registered with this structural |
| | |
| | | } |
| | | |
| | | // If there are any candidate name forms then at least one |
| | | // should be |
| | | // valid. |
| | | // should be valid. |
| | | foundMatchingNameForms = true; |
| | | |
| | | if (checkNameForm(entry, policy, nameFormWarnings, nf)) { |
| | |
| | | ditStructureRules = getDITStructureRules(nameForm); |
| | | } else { |
| | | // We couldn't match this entry against any of the name |
| | | // forms, so |
| | | // append the reasons why they didn't match and reject if |
| | | // required. |
| | | // forms, so append the reasons why they didn't match and |
| | | // reject if required. |
| | | if (errorMessages != null) { |
| | | errorMessages.addAll(nameFormWarnings); |
| | | } |
| | |
| | | foundMatchingRules = true; |
| | | |
| | | // A DIT structure rule with no superiors is automatically |
| | | // valid, so |
| | | // avoid reading the parent. |
| | | // valid, so avoid reading the parent. |
| | | if (rule.getSuperiorRules().isEmpty()) { |
| | | foundValidRule = true; |
| | | break; |
| | |
| | | } |
| | | |
| | | if (parentStructuralObjectClass != null) { |
| | | if (checkDITStructureRule(entry, policy, ruleWarnings, rule, |
| | | if (checkDITStructureRule(entry, ruleWarnings, rule, |
| | | structuralObjectClass, parentStructuralObjectClass)) { |
| | | foundValidRule = true; |
| | | break; |
| | |
| | | } |
| | | |
| | | // We could break out of the loop here in |
| | | // warn mode but |
| | | // continuing allows us to collect all |
| | | // conflicts. |
| | | // warn mode but continuing allows us to |
| | | // collect all conflicts. |
| | | } |
| | | } |
| | | } |
| | |
| | | if (checkObjectClasses || checkDITContentRule) { |
| | | for (final ObjectClass objectClass : objectClasses) { |
| | | // Make sure that any auxiliary object classes are permitted by |
| | | // the |
| | | // content rule. |
| | | // the content rule. |
| | | if (checkDITContentRule) { |
| | | if (objectClass.getObjectClassType() == ObjectClassType.AUXILIARY |
| | | && !ditContentRule.getAuxiliaryClasses().contains(objectClass)) { |
| | |
| | | } |
| | | |
| | | // Make sure that all of the attributes required by the object |
| | | // class are |
| | | // present. |
| | | // class are present. |
| | | if (checkObjectClasses) { |
| | | for (final AttributeType t : objectClass.getDeclaredRequiredAttributes()) { |
| | | final Attribute a = |
| | |
| | | } |
| | | |
| | | // Make sure that all of the attributes required by the content rule |
| | | // are |
| | | // present. |
| | | // are present. |
| | | if (checkDITContentRule) { |
| | | for (final AttributeType t : ditContentRule.getRequiredAttributes()) { |
| | | final Attribute a = Attributes.emptyAttribute(AttributeDescription.create(t)); |
| | |
| | | } |
| | | |
| | | // Make sure that attributes prohibited by the content rule are |
| | | // not |
| | | // present. |
| | | // not present. |
| | | for (final AttributeType t : ditContentRule.getProhibitedAttributes()) { |
| | | final Attribute a = Attributes.emptyAttribute(AttributeDescription.create(t)); |
| | | if (entry.containsAttribute(a, null)) { |
| | |
| | | return true; |
| | | } |
| | | |
| | | private boolean checkDITStructureRule(final Entry entry, final SchemaValidationPolicy policy, |
| | | private boolean checkDITStructureRule(final Entry entry, |
| | | final List<LocalizableMessage> ruleWarnings, final DITStructureRule rule, |
| | | final ObjectClass structuralObjectClass, final ObjectClass parentStructuralObjectClass) { |
| | | boolean matchFound = false; |