Search in sources :

Example 81 with LdapException

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

the class Registries method associateWithSchema.

/**
 * Store the given SchemaObject in the Map associating SchemaObjetcs to their
 * related Schema.
 *
 * @param errors The list of errors we are accumulating while checking the schema
 * @param schemaObject The schemaObject to register
 */
public void associateWithSchema(List<Throwable> errors, SchemaObject schemaObject) {
    LOG.debug("Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is not already registered
    if (!(schemaObject instanceof LoadableSchemaObject) && globalOidRegistry.contains(schemaObject.getOid())) {
        String msg = I18n.err(I18n.ERR_13750_REGISTERING_FAILED_ALREADY_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
        LOG.error(msg);
        Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
        errors.add(error);
        return;
    }
    // Get a normalized form of schema name
    String schemaName = getSchemaName(schemaObject);
    // And register the schemaObject within its schema
    Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
    if (content == null) {
        content = new HashSet<>();
        schemaObjects.put(Strings.toLowerCaseAscii(schemaName), content);
    }
    SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
    if (content.contains(schemaObjectWrapper)) {
        // Already present !
        // What should we do ?
        LOG.info("Registering of {}:{} failed, is already present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
    } else {
        // Create the association
        content.add(schemaObjectWrapper);
        // an instance of LoadableSchemaObject
        if (!(schemaObject instanceof LoadableSchemaObject)) {
            try {
                globalOidRegistry.register(schemaObject);
            } catch (LdapException ne) {
                errors.add(ne);
                return;
            }
        }
        LOG.debug("registered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 82 with LdapException

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

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

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

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

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)361 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)161 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)111 ArrayList (java.util.ArrayList)94 FinderException (org.apache.directory.fortress.core.FinderException)73 Modification (org.apache.directory.api.ldap.model.entry.Modification)70 Entry (org.apache.directory.api.ldap.model.entry.Entry)68 IOException (java.io.IOException)57 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)57 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)53 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)29 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)23 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22