Search in sources :

Example 16 with LdapSchemaException

use of org.apache.directory.api.ldap.model.exception.LdapSchemaException 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 17 with LdapSchemaException

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

the class Registries method resolve.

/**
 * Check if the Comparator, Normalizer and the syntax are
 * existing for a matchingRule.
 */
private void resolve(MatchingRule matchingRule, List<Throwable> errors) {
    // Process the Syntax. It can't be null
    String syntaxOid = matchingRule.getSyntaxOid();
    if (syntaxOid != null) {
        // Check if the Syntax is present in the registries
        try {
            ldapSyntaxRegistry.lookup(syntaxOid);
        } catch (LdapException ne) {
            // This MR's syntax has not been loaded into the Registries.
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()), ne);
            ldapSchemaException.setSourceObject(matchingRule);
            errors.add(ldapSchemaException);
        }
    } else {
        // This is an error.
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()));
        ldapSchemaException.setSourceObject(matchingRule);
        errors.add(ldapSchemaException);
    }
    // Process the Normalizer
    Normalizer normalizer = matchingRule.getNormalizer();
    if (normalizer == null) {
        // Ok, no normalizer, this is an error
        Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13220_NO_NORMALIZER, matchingRule.getOid()));
        errors.add(error);
    }
    // Process the Comparator
    LdapComparator<?> comparator = matchingRule.getLdapComparator();
    if (comparator == null) {
        // Ok, no comparator, this is an error
        Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_04296, matchingRule.getOid()));
        errors.add(error);
    }
}
Also used : LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 18 with LdapSchemaException

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

the class AttributeTypeHelper method buildEquality.

/**
 * Build the EQUALITY MR reference for an AttributeType
 */
private static void buildEquality(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String equalityOid = attributeType.getEqualityOid();
    // The equality MR. It can be null
    if (equalityOid != null) {
        MatchingRule currentEquality = null;
        try {
            currentEquality = registries.getMatchingRuleRegistry().lookup(equalityOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13756_CANNOT_FIND_EQUALITY_MR_OBJECT, equalityOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(equalityOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentEquality != null) {
            attributeType.setEquality(currentEquality);
            // Restore the old equality OID to preserve the user's provided value
            attributeType.setEqualityOid(equalityOid);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13757_CANNOT_FIND_EQUALITY_MR_INSTANCE, equalityOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(equalityOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
        }
    } else {
        AttributeType superior = attributeType.getSuperior();
        // If the AT has a superior, take its Equality MR if any
        if ((superior != null) && (superior.getEquality() != null)) {
            attributeType.setEquality(superior.getEquality());
        }
    }
}
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 19 with LdapSchemaException

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

the class AttributeTypeHelper method buildSyntax.

/**
 * Build the SYNTAX reference for an AttributeType
 */
private static void buildSyntax(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String syntaxOid = attributeType.getSyntaxOid();
    if (syntaxOid != null) {
        LdapSyntax currentSyntax = null;
        try {
            currentSyntax = registries.getLdapSyntaxRegistry().lookup(syntaxOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(syntaxOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentSyntax != null) {
            // Update the Syntax reference
            attributeType.setSyntax(currentSyntax);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(syntaxOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
    } else {
        // We inherit from the superior's syntax, if any
        if (attributeType.getSuperior() != null) {
            if (attributeType.getSuperior().getSyntax() != null) {
                attributeType.setSyntax(attributeType.getSuperior().getSyntax());
            } else {
                String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg);
                ldapSchemaException.setSourceObject(attributeType);
                ldapSchemaException.setRelatedId(syntaxOid);
                errors.add(ldapSchemaException);
                LOG.info(msg);
                return;
            }
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13755_AT_MUST_HAVE_A_SYNTAX_OID, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_SYNTAX_OR_SUPERIOR_REQUIRED, msg);
            ldapSchemaException.setSourceObject(attributeType);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
    }
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 20 with LdapSchemaException

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

the class AttributeTypeHelper method buildSuperior.

/**
 * Build the Superior AttributeType reference for an AttributeType
 */
private static boolean buildSuperior(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    MutableAttributeType currentSuperior;
    AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
    String superiorOid = attributeType.getSuperiorOid();
    if (superiorOid != null) {
        // This AT has a superior
        try {
            currentSuperior = (MutableAttributeType) attributeTypeRegistry.lookup(superiorOid);
        } catch (Exception e) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(superiorOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            // Get out now
            return false;
        }
        if (currentSuperior != null) {
            // a special case : if the superior is collective, this is an error
            if (currentSuperior.isCollective()) {
                String msg = I18n.err(I18n.ERR_13776_CANNOT_SUBTYPE_COLLECTIVE, currentSuperior, attributeType.getName());
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg);
                ldapSchemaException.setSourceObject(attributeType);
                errors.add(ldapSchemaException);
                LOG.info(msg);
                return false;
            }
            attributeType.setSuperior(currentSuperior);
            // handled.
            if (currentSuperior.getSuperior() == null) {
                registries.buildReference(errors, currentSuperior);
            }
            // Update the descendant MAP
            try {
                attributeTypeRegistry.registerDescendants(attributeType, currentSuperior);
            } catch (LdapException ne) {
                errors.add(ne);
                LOG.info(ne.getMessage());
                return false;
            }
            // Check for cycles now
            Set<String> superiors = new HashSet<>();
            superiors.add(attributeType.getOid());
            AttributeType tmp = currentSuperior;
            boolean isOk = true;
            while (tmp != null) {
                if (superiors.contains(tmp.getOid())) {
                    // There is a cycle : bad bad bad !
                    // Not allowed.
                    String msg = I18n.err(I18n.ERR_13753_CYCLE_DETECTED, attributeType.getName());
                    LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg);
                    ldapSchemaException.setSourceObject(attributeType);
                    errors.add(ldapSchemaException);
                    LOG.info(msg);
                    isOk = false;
                    break;
                } else {
                    superiors.add(tmp.getOid());
                    tmp = tmp.getSuperior();
                }
            }
            superiors.clear();
            return isOk;
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(superiorOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            // Get out now
            return false;
        }
    } else {
        // No superior, just return
        return true;
    }
}
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) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) AttributeTypeRegistry(org.apache.directory.api.ldap.model.schema.registries.AttributeTypeRegistry) HashSet(java.util.HashSet)

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