Search in sources :

Example 11 with LdapUnwillingToPerformException

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

the class SchemaManagerLoadWithDepsTest method testLoadCoreInetOrgPersonAndBad.

/**
 * test loading the "InetOrgPerson", "core" and a bad schema
 */
@Test
public void testLoadCoreInetOrgPersonAndBad() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    try {
        schemaManager.loadWithDeps("core", "bad", "InetOrgPerson");
        fail();
    } catch (LdapUnwillingToPerformException lonse) {
    // expected
    }
    // No SchemaObject should be loaded as we had an error
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(0, schemaManager.getComparatorRegistry().size());
    assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(0, schemaManager.getNormalizerRegistry().size());
    assertEquals(0, schemaManager.getObjectClassRegistry().size());
    assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(0, schemaManager.getGlobalOidRegistry().size());
    assertEquals(0, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNull(schemaManager.getRegistries().getLoadedSchema("system"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("core"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
}
Also used : LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 12 with LdapUnwillingToPerformException

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

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

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

the class WrappedPartialResultException method wrap.

/**
 * Wraps a LDAP exception into a NaingException
 *
 * @param t The original exception
 * @throws NamingException The wrapping JNDI exception
 */
public static void wrap(Throwable t) throws NamingException {
    if (t instanceof NamingException) {
        throw (NamingException) t;
    }
    NamingException ne;
    if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
        ne = new NamingException(t.getLocalizedMessage());
    } else if (t instanceof LdapAttributeInUseException) {
        ne = new AttributeInUseException(t.getLocalizedMessage());
    } else if (t instanceof LdapAuthenticationException) {
        ne = new AuthenticationException(t.getLocalizedMessage());
    } else if (t instanceof LdapAuthenticationNotSupportedException) {
        ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
    } else if (t instanceof LdapContextNotEmptyException) {
        ne = new ContextNotEmptyException(t.getLocalizedMessage());
    } else if (t instanceof LdapEntryAlreadyExistsException) {
        ne = new NameAlreadyBoundException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidAttributeTypeException) {
        ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidAttributeValueException) {
        ne = new InvalidAttributeValueException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidDnException) {
        ne = new InvalidNameException(t.getLocalizedMessage());
    } else if (t instanceof LdapInvalidSearchFilterException) {
        ne = new InvalidSearchFilterException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoPermissionException) {
        ne = new NoPermissionException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoSuchAttributeException) {
        ne = new NoSuchAttributeException(t.getLocalizedMessage());
    } else if (t instanceof LdapNoSuchObjectException) {
        ne = new NameNotFoundException(t.getLocalizedMessage());
    } else if (t instanceof LdapProtocolErrorException) {
        ne = new CommunicationException(t.getLocalizedMessage());
    } else if (t instanceof LdapReferralException) {
        ne = new WrappedReferralException((LdapReferralException) t);
    } else if (t instanceof LdapPartialResultException) {
        ne = new WrappedPartialResultException((LdapPartialResultException) t);
    } else if (t instanceof LdapSchemaViolationException) {
        ne = new SchemaViolationException(t.getLocalizedMessage());
    } else if (t instanceof LdapServiceUnavailableException) {
        ne = new ServiceUnavailableException(t.getLocalizedMessage());
    } else if (t instanceof LdapTimeLimitExceededException) {
        ne = new TimeLimitExceededException(t.getLocalizedMessage());
    } else if (t instanceof LdapUnwillingToPerformException) {
        ne = new OperationNotSupportedException(t.getLocalizedMessage());
    } else {
        ne = new NamingException(t.getLocalizedMessage());
    }
    ne.setRootCause(t);
    throw ne;
}
Also used : LdapEntryAlreadyExistsException(org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException) LdapOperationErrorException(org.apache.directory.api.ldap.model.exception.LdapOperationErrorException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) AuthenticationException(javax.naming.AuthenticationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) LdapInvalidAttributeTypeException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) LdapAliasException(org.apache.directory.api.ldap.model.exception.LdapAliasException) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) LdapPartialResultException(org.apache.directory.api.ldap.model.exception.LdapPartialResultException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) LdapLoopDetectedException(org.apache.directory.api.ldap.model.exception.LdapLoopDetectedException) InvalidNameException(javax.naming.InvalidNameException) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapReferralException(org.apache.directory.api.ldap.model.exception.LdapReferralException) NamingException(javax.naming.NamingException) SchemaViolationException(javax.naming.directory.SchemaViolationException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) LdapAliasDereferencingException(org.apache.directory.api.ldap.model.exception.LdapAliasDereferencingException) InvalidAttributeIdentifierException(javax.naming.directory.InvalidAttributeIdentifierException) CommunicationException(javax.naming.CommunicationException) InvalidSearchFilterException(javax.naming.directory.InvalidSearchFilterException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) NameNotFoundException(javax.naming.NameNotFoundException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapAffectMultipleDsaException(org.apache.directory.api.ldap.model.exception.LdapAffectMultipleDsaException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvalidAttributeValueException(javax.naming.directory.InvalidAttributeValueException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoPermissionException(javax.naming.NoPermissionException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) TimeLimitExceededException(javax.naming.TimeLimitExceededException) AttributeInUseException(javax.naming.directory.AttributeInUseException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 15 with LdapUnwillingToPerformException

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

the class DnNode method add.

/**
 * Add a new node in the tree. We can't add a node if its Dn is empty. The
 * added element is attached to the node, which is named by the Dn's Rdn.<br>
 *
 * @param dn The node's Dn
 * @param element The element to associate with this Node. Can be null.
 * @return the corresponding node
 * @throws LdapException if the Dn is null or empty
 */
public synchronized DnNode<N> add(Dn dn, N element) throws LdapException {
    checkDn(dn);
    // We first have to find the Node which will be the parent
    DnNode<N> parentNode = getNode(dn);
    if (parentNode == null) {
        // No parent : add a new node to the root
        DnNode<N> childNode = createNode(dn, element, dn.size());
        childNode.parent = this;
        children.put(childNode.nodeRdn.getNormName(), childNode);
        return childNode;
    } else {
        // We have a parent. Add the new node to the found parent
        int nbRdns = dn.size() - parentNode.depth;
        if (nbRdns == 0) {
            // That means the added Dn is already present. Check if it already has an element
            if (parentNode.hasElement()) {
                String message = "Cannot add a node to a node already having an element";
                LOG.error(message);
                throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, message);
            } else // We may try to add twice the same Dn, without any element
            if (element == null) {
                String message = "Cannot add a node with no element if it already exists";
                LOG.error(message);
                throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, message);
            } else // All is fine : we are just injecting some data into an existing node
            {
                parentNode.setElement(element);
                return parentNode;
            }
        } else {
            DnNode<N> childNode = createNode(dn, element, nbRdns);
            // done. now, add the newly created tree to the parent node
            childNode.parent = parentNode;
            parentNode.children.put(childNode.nodeRdn.getNormName(), childNode);
            return childNode;
        }
    }
}
Also used : LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)

Aggregations

LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)21 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)11 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)4 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)4 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)4 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)4 Test (org.junit.Test)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)3 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)3 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 CommunicationException (javax.naming.CommunicationException)1