Search in sources :

Example 21 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.

the class MatchingRuleHelper method addToRegistries.

/**
 * Inject the MatchingRule into the Registries, updating the references to
 * other SchemaObject
 *
 * @param matchingRule The MatchingRule to add to the Registries
 * @param errors The errors we got while adding the MatchingRule to the registries
 * @param registries The Registries
 * @throws LdapException If the addition failed
 */
@SuppressWarnings("rawtypes")
public static void addToRegistries(MutableMatchingRule matchingRule, List<Throwable> errors, Registries registries) throws LdapException {
    if (registries != null) {
        try {
            matchingRule.unlock();
            LdapComparator<?> ldapComparator = null;
            Normalizer normalizer = null;
            LdapSyntax ldapSyntax = null;
            try {
                // Gets the associated Comparator
                ldapComparator = registries.getComparatorRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to a catch all comparator
                ldapComparator = new ComparableComparator(matchingRule.getOid());
            }
            try {
                // Gets the associated Normalizer
                normalizer = registries.getNormalizerRegistry().lookup(matchingRule.getOid());
            } catch (LdapException ne) {
                // Default to the NoOp normalizer
                normalizer = new NoOpNormalizer(matchingRule.getOid());
            }
            try {
                // Get the associated LdapSyntax
                ldapSyntax = registries.getLdapSyntaxRegistry().lookup(matchingRule.getSyntaxOid());
            } catch (LdapException ne) {
                // The Syntax is a mandatory element, it must exist.
                String msg = I18n.err(I18n.ERR_13765_MR_MUST_REFER_EXISTING_SYNTAX);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.MR_NONEXISTENT_SYNTAX, msg, ne);
                ldapSchemaException.setSourceObject(matchingRule);
                ldapSchemaException.setRelatedId(matchingRule.getSyntaxOid());
                errors.add(ldapSchemaException);
                LOG.info(msg);
            }
            /**
             * Add the MR references (using and usedBy) :
             * MR -> C
             * MR -> N
             * MR -> S
             */
            if (ldapComparator != null) {
                registries.addReference(matchingRule, ldapComparator);
                matchingRule.setLdapComparator(ldapComparator);
            }
            if (normalizer != null) {
                registries.addReference(matchingRule, normalizer);
                matchingRule.setNormalizer(normalizer);
            }
            if (ldapSyntax != null) {
                registries.addReference(matchingRule, ldapSyntax);
                matchingRule.setSyntax(ldapSyntax);
            }
        } finally {
            matchingRule.lock();
        }
    }
}
Also used : NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) NoOpNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) ComparableComparator(org.apache.directory.api.ldap.model.schema.comparators.ComparableComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 22 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.

the class Registries method resolveRecursive.

private void resolveRecursive(ObjectClass objectClass, Set<String> processed, List<Throwable> errors) {
    // Process the Superiors, if any
    List<String> superiorOids = objectClass.getSuperiorOids();
    ObjectClass superior = null;
    for (String superiorOid : superiorOids) {
        // Check if the Superior is present in the registries
        try {
            superior = objectClassRegistry.lookup(superiorOid);
        } catch (LdapException ne) {
            // This OC's superior has not been loaded into the Registries.
            if (!processed.contains(superiorOid)) {
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, ne);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setRelatedId(superiorOid);
                errors.add(ldapSchemaException);
            }
        }
        // processed yet.
        if (superior != null) {
            if (!processed.contains(superior.getOid())) {
                resolveRecursive(superior, processed, errors);
                processed.add(objectClass.getOid());
            } else {
                // Not allowed : we have a cyle
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_CYCLE_CLASS_HIERARCHY);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setOtherObject(superior);
                errors.add(ldapSchemaException);
                return;
            }
        }
    }
    // Process the MAY attributeTypes.
    for (String mayOid : objectClass.getMayAttributeTypeOids()) {
        // Check if the MAY AttributeType is present in the registries
        try {
            attributeTypeRegistry.lookup(mayOid);
        } catch (LdapException ne) {
            // This AT has not been loaded into the Registries.
            errors.add(ne);
        }
    }
    // Process the MUST attributeTypes.
    for (String mustOid : objectClass.getMustAttributeTypeOids()) {
        // Check if the MUST AttributeType is present in the registries
        try {
            attributeTypeRegistry.lookup(mustOid);
        } catch (LdapException ne) {
            // This AT has not been loaded into the Registries.
            errors.add(ne);
        }
    }
    // All is done for this ObjectClass, let's apply the registries
    try {
        ObjectClassHelper.addToRegistries(objectClass, errors, this);
    } catch (LdapException ne) {
    // Do nothing. We may have a broken OC,
    // but at this point, it doesn't matter.
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 23 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.

the class AttributeTypeHelper method checkUsage.

/**
 * Check the constraints for the Usage field.
 */
private static void checkUsage(AttributeType attributeType, List<Throwable> errors) {
    AttributeType superior = attributeType.getSuperior();
    // Check that the AT usage is the same that its superior
    if ((superior != null) && (attributeType.getUsage() != superior.getUsage())) {
        // This is an error
        String msg = I18n.err(I18n.ERR_13762_AT_MUST_HAVE_SUPERIOR_USAGE, attributeType.getName());
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_MUST_HAVE_SAME_USAGE_THAN_SUPERIOR, msg);
        ldapSchemaException.setSourceObject(attributeType);
        errors.add(ldapSchemaException);
        LOG.info(msg);
        return;
    }
    // Now, check that the AttributeType's USAGE does not conflict
    if (!attributeType.isUserModifiable() && (attributeType.getUsage() == UsageEnum.USER_APPLICATIONS)) {
        // Cannot have a not user modifiable AT which is not an operational AT
        String msg = I18n.err(I18n.ERR_13763_AT_MUST_BE_USER_MODIFIABLE, attributeType.getName());
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_USER_APPLICATIONS_USAGE_MUST_BE_USER_MODIFIABLE, msg);
        ldapSchemaException.setSourceObject(attributeType);
        errors.add(ldapSchemaException);
        LOG.info(msg);
    }
}
Also used : 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)

Example 24 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.

the class AttributeTypeHelper method buildSubstring.

/**
 * Build the SUBSTR MR reference for an AttributeType
 */
private static void buildSubstring(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String substringOid = attributeType.getSubstringOid();
    // The Substring MR. It can be null
    if (substringOid != null) {
        MatchingRule currentSubstring = null;
        try {
            currentSubstring = registries.getMatchingRuleRegistry().lookup(substringOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13760_CANNOT_FIND_SUBSTR_MR_OBJECT, substringOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(substringOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentSubstring != null) {
            attributeType.setSubstring(currentSubstring);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13761_CANNOT_FIND_SUBSTR_MR_INSTANCE, substringOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUBSTRING_MATCHING_RULE, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(substringOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
    } else {
        AttributeType superior = attributeType.getSuperior();
        // If the AT has a superior, take its Substring MR if any
        if ((superior != null) && (superior.getSubstring() != null)) {
            attributeType.setSubstring(superior.getSubstring());
        }
    }
}
Also used : 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) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 25 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.

the class AttributeTypeHelper method checkCollective.

/**
 * Check the constraints for the Collective field.
 */
private static void checkCollective(MutableAttributeType attributeType, List<Throwable> errors) {
    AttributeType superior = attributeType.getSuperior();
    if ((superior != null) && superior.isCollective()) {
        // An AttributeType will be collective if its superior is collective
        attributeType.setCollective(true);
    }
    if (attributeType.isCollective() && (attributeType.getUsage() != UsageEnum.USER_APPLICATIONS)) {
        // An AttributeType which is collective must be a USER attributeType
        String msg = I18n.err(I18n.ERR_13764_AT_COLLECTIVE_SHOULD_BE_USER_APP, attributeType.getName());
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_COLLECTIVE_MUST_HAVE_USER_APPLICATIONS_USAGE, msg);
        ldapSchemaException.setSourceObject(attributeType);
        errors.add(ldapSchemaException);
        LOG.info(msg);
    }
    if (attributeType.isCollective() && attributeType.isSingleValued()) {
        // A collective attribute must be multi-valued
        String msg = I18n.err(I18n.ERR_13777_COLLECTIVE_NOT_MULTI_VALUED, attributeType.getName());
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_COLLECTIVE_CANNOT_BE_SINGLE_VALUED, msg);
        ldapSchemaException.setSourceObject(attributeType);
        errors.add(ldapSchemaException);
        LOG.info(msg);
    }
}
Also used : 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)

Aggregations

LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)54 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)34 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)34 Test (org.junit.Test)34 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)19 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)16 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)5 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)5 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)5 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)3 AttributeTypeRegistry (org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 Method (java.lang.reflect.Method)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)1 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)1