Search in sources :

Example 11 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class QuirkySchemaTest method testLoadQuirkySchema.

/**
 * Try to load a quirky schema. This schema has a lot of issues that violate the
 * standards. Therefore load the schema in relaxed mode. We should be able to work
 * with this schema anyway. E.g. the loader and schema manager should not die on
 * null pointer or similar trivial error.
 */
@Test
public void testLoadQuirkySchema() throws Exception {
    LdapConnection connection = createFakeConnection("src/test/resources/schema-quirky.ldif");
    DefaultSchemaLoader loader = new DefaultSchemaLoader(connection, true);
    Collection<Schema> allEnabled = loader.getAllEnabled();
    assertEquals(1, allEnabled.size());
    Schema schema = allEnabled.iterator().next();
    assertNotNull(schema);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    boolean loaded = schemaManager.loadAllEnabledRelaxed();
    if (!loaded) {
        fail("Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()));
    }
    assertTrue("Surprisingly no errors after load", schemaManager.getErrors().size() > 0);
    assertTrue(schemaManager.getRegistries().getAttributeTypeRegistry().contains("cn"));
    ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup("person");
    assertNotNull(person);
    assertEquals(2, person.getMustAttributeTypes().size());
    assertEquals(5, person.getMayAttributeTypes().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 12 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class Registries method resolve.

private void resolve(ObjectClass objectClass, List<Throwable> errors) {
    // This set is used to avoid having more than one error
    // for an ObjectClass. It's mandatory when processing
    // the Superiors, as they may be broken and referenced more than once.
    Set<String> processed = new HashSet<>();
    // Store the ObjectClass itself in the processed, to avoid cycle
    processed.add(objectClass.getOid());
    // Call the recursive method, as we may have superiors to deal with
    resolveRecursive(objectClass, processed, errors);
    // Check that the MAY and MUST AT are consistent (no AT in MAY and in MUST
    // in one of its superior
    List<AttributeType> musts = getMustRecursive(new ArrayList<AttributeType>(), new HashSet<ObjectClass>(), objectClass);
    if (musts != null) {
        for (AttributeType may : objectClass.getMayAttributeTypes()) {
            if (musts.contains(may)) {
                // This is not allowed.
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setOtherObject(may);
                errors.add(ldapSchemaException);
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) HashSet(java.util.HashSet)

Example 13 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class Registries method unregister.

/**
 * Unregister a SchemaObject from the registries
 *
 * @param schemaObject The SchemaObject we want to deregister
 * @throws LdapException If the removal failed
 */
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
    LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is present in the registries
    if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
        String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
        LOG.error(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    SchemaObject unregistered;
    // First call the specific registry's register method
    switch(schemaObject.getObjectType()) {
        case ATTRIBUTE_TYPE:
            unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
            break;
        case COMPARATOR:
            unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
            break;
        case DIT_CONTENT_RULE:
            unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
            break;
        case DIT_STRUCTURE_RULE:
            unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
            break;
        case LDAP_SYNTAX:
            unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
            break;
        case MATCHING_RULE:
            unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
            break;
        case MATCHING_RULE_USE:
            unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
            break;
        case NAME_FORM:
            unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
            break;
        case NORMALIZER:
            unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
            break;
        case OBJECT_CLASS:
            unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
            break;
        case SYNTAX_CHECKER:
            unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
            break;
        default:
            throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
    }
    return unregistered;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 14 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class Registries method check.

/**
 * Check the registries for invalid relations. This check stops at the first error.
 *
 * @return true if the Registries is consistent, false otherwise
 */
public boolean check() {
    // Check the Syntaxes : check for a SyntaxChecker
    LOG.debug("Checking Syntaxes");
    for (LdapSyntax syntax : ldapSyntaxRegistry) {
        // Check that each Syntax has a SyntaxChecker
        if (syntax.getSyntaxChecker() == null) {
            LOG.debug("The Syntax {} has no SyntaxChecker", syntax);
            return false;
        }
        if (!syntaxCheckerRegistry.contains(syntax.getSyntaxChecker().getOid())) {
            LOG.debug("Cannot find the SyntaxChecker {} for the Syntax {}", syntax.getSyntaxChecker().getOid(), syntax);
            return false;
        }
        // Check the references : Syntax -> SyntaxChecker and SyntaxChecker -> Syntax
        if (!checkReferences(syntax, syntax.getSyntaxChecker(), "SyntaxChecker")) {
            return false;
        }
    }
    // Check the MatchingRules : check for a Normalizer, a Comparator and a Syntax
    LOG.debug("Checking MatchingRules...");
    for (MatchingRule matchingRule : matchingRuleRegistry) {
        // Check that each MatchingRule has a Normalizer
        if (matchingRule.getNormalizer() == null) {
            LOG.debug("The MatchingRule {} has no Normalizer", matchingRule);
            return false;
        }
        // Check that each MatchingRule has a Normalizer
        if (!normalizerRegistry.contains(matchingRule.getNormalizer().getOid())) {
            LOG.debug("Cannot find the Normalizer {} for the MatchingRule {}", matchingRule.getNormalizer().getOid(), matchingRule);
            return false;
        }
        // Check that each MatchingRule has a Comparator
        if (matchingRule.getLdapComparator() == null) {
            LOG.debug("The MatchingRule {} has no Comparator", matchingRule);
            return false;
        }
        if (!comparatorRegistry.contains(matchingRule.getLdapComparator().getOid())) {
            LOG.debug("Cannot find the Comparator {} for the MatchingRule {}", matchingRule.getLdapComparator().getOid(), matchingRule);
            return false;
        }
        // Check that each MatchingRule has a Syntax
        if (matchingRule.getSyntax() == null) {
            LOG.debug("The MatchingRule {} has no Syntax", matchingRule);
            return false;
        }
        if (!ldapSyntaxRegistry.contains(matchingRule.getSyntax().getOid())) {
            LOG.debug("Cannot find the Syntax {} for the MatchingRule {}", matchingRule.getSyntax().getOid(), matchingRule);
            return false;
        }
        // Check the references : MR -> S and S -> MR
        if (!checkReferences(matchingRule, matchingRule.getSyntax(), "Syntax")) {
            return false;
        }
        // Check the references : MR -> N
        if (!checkReferences(matchingRule, matchingRule.getNormalizer(), "Normalizer")) {
            return false;
        }
        // Check the references : MR -> C and C -> MR
        if (!checkReferences(matchingRule, matchingRule.getLdapComparator(), "Comparator")) {
            return false;
        }
    }
    // Check the ObjectClasses : check for MAY, MUST, SUPERIORS
    LOG.debug("Checking ObjectClasses...");
    for (ObjectClass objectClass : objectClassRegistry) {
        // Check that each ObjectClass has all the MAY AttributeTypes
        if (objectClass.getMayAttributeTypes() != null) {
            for (AttributeType may : objectClass.getMayAttributeTypes()) {
                if (!attributeTypeRegistry.contains(may.getOid())) {
                    LOG.debug("Cannot find the AttributeType {} for the ObjectClass {} MAY", may, objectClass);
                    return false;
                }
                // Check the references : OC -> AT  and AT -> OC (MAY)
                if (!checkReferences(objectClass, may, "AttributeType")) {
                    return false;
                }
            }
        }
        // Check that each ObjectClass has all the MUST AttributeTypes
        if (objectClass.getMustAttributeTypes() != null) {
            for (AttributeType must : objectClass.getMustAttributeTypes()) {
                if (!attributeTypeRegistry.contains(must.getOid())) {
                    LOG.debug("Cannot find the AttributeType {} for the ObjectClass {} MUST", must, objectClass);
                    return false;
                }
                // Check the references : OC -> AT  and AT -> OC (MUST)
                if (!checkReferences(objectClass, must, "AttributeType")) {
                    return false;
                }
            }
        }
        // Check that each ObjectClass has all the SUPERIORS ObjectClasses
        if (objectClass.getSuperiors() != null) {
            for (ObjectClass superior : objectClass.getSuperiors()) {
                if (!objectClassRegistry.contains(objectClass.getOid())) {
                    LOG.debug("Cannot find the ObjectClass {} for the ObjectClass {} SUPERIORS", superior, objectClass);
                    return false;
                }
                // Check the references : OC -> OC  and OC -> OC (SUPERIORS)
                if (!checkReferences(objectClass, superior, "ObjectClass")) {
                    return false;
                }
            }
        }
    }
    // Check the AttributeTypes : check for MatchingRules, Syntaxes
    LOG.debug("Checking AttributeTypes...");
    for (AttributeType attributeType : attributeTypeRegistry) {
        // Check that each AttributeType has a SYNTAX
        if (attributeType.getSyntax() == null) {
            LOG.debug("The AttributeType {} has no Syntax", attributeType);
            return false;
        }
        if (!ldapSyntaxRegistry.contains(attributeType.getSyntax().getOid())) {
            LOG.debug("Cannot find the Syntax {} for the AttributeType {}", attributeType.getSyntax().getOid(), attributeType);
            return false;
        }
        // Check the references for AT -> S and S -> AT
        if (!checkReferences(attributeType, attributeType.getSyntax(), "AttributeType")) {
            return false;
        }
        // Check the EQUALITY MatchingRule
        if (attributeType.getEquality() != null) {
            if (!matchingRuleRegistry.contains(attributeType.getEquality().getOid())) {
                LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getEquality().getOid(), attributeType);
                return false;
            }
            // Check the references for AT -> MR and MR -> AT
            if (!checkReferences(attributeType, attributeType.getEquality(), "AttributeType")) {
                return false;
            }
        }
        // Check the ORDERING MatchingRule
        if (attributeType.getOrdering() != null) {
            if (!matchingRuleRegistry.contains(attributeType.getOrdering().getOid())) {
                LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getOrdering().getOid(), attributeType);
                return false;
            }
            // Check the references for AT -> MR and MR -> AT
            if (!checkReferences(attributeType, attributeType.getOrdering(), "AttributeType")) {
                return false;
            }
        }
        // Check the SUBSTR MatchingRule
        if (attributeType.getSubstring() != null) {
            if (!matchingRuleRegistry.contains(attributeType.getSubstring().getOid())) {
                LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getSubstring().getOid(), attributeType);
                return false;
            }
            // Check the references for AT -> MR and MR -> AT
            if (!checkReferences(attributeType, attributeType.getSubstring(), "AttributeType")) {
                return false;
            }
        }
        // Check the SUP
        if (attributeType.getSuperior() != null) {
            AttributeType superior = attributeType.getSuperior();
            if (!attributeTypeRegistry.contains(superior.getOid())) {
                LOG.debug("Cannot find the AttributeType {} for the AttributeType {} SUPERIOR", superior, attributeType);
                return false;
            }
            // Check the references : AT -> AT  and AT -> AT (SUPERIOR)
            if (!checkReferences(attributeType, superior, "AttributeType")) {
                return false;
            }
        }
    }
    return true;
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 15 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class DefaultObjectClassRegistry method descendants.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Iterator<ObjectClass> descendants(String ancestorId) throws LdapException {
    try {
        String oid = getOidByName(ancestorId);
        Set<ObjectClass> descendants = oidToDescendants.get(oid);
        if (descendants == null) {
            return Collections.EMPTY_SET.iterator();
        }
        return descendants.iterator();
    } catch (LdapException ne) {
        throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Aggregations

ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)53 Test (org.junit.Test)34 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)9 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)6 ParseException (java.text.ParseException)5 HashSet (java.util.HashSet)5 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)3 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2