Search in sources :

Example 26 with LdapSchemaException

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

the class AttributeTypeHelper method buildOrdering.

/**
 * Build the ORDERING MR reference for an AttributeType
 */
private static void buildOrdering(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
    String orderingOid = attributeType.getOrderingOid();
    if (orderingOid != null) {
        MatchingRule currentOrdering = null;
        try {
            currentOrdering = registries.getMatchingRuleRegistry().lookup(orderingOid);
        } catch (LdapException ne) {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13758_CANNOT_FIND_ORDERING_MR_OBJECT, orderingOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg, ne);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(orderingOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
            return;
        }
        if (currentOrdering != null) {
            attributeType.setOrdering(currentOrdering);
        } else {
            // Not allowed.
            String msg = I18n.err(I18n.ERR_13759_CANNOT_FIND_ORDERING_MR_INSTANCE, orderingOid, attributeType.getName());
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_ORDERING_MATCHING_RULE, msg);
            ldapSchemaException.setSourceObject(attributeType);
            ldapSchemaException.setRelatedId(orderingOid);
            errors.add(ldapSchemaException);
            LOG.info(msg);
        }
    } else {
        AttributeType superior = attributeType.getSuperior();
        // If the AT has a superior, take its Ordering MR if any
        if ((superior != null) && (superior.getOrdering() != null)) {
            attributeType.setOrdering(superior.getOrdering());
        }
    }
}
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 27 with LdapSchemaException

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

the class DefaultSchemaObjectRegistry method register.

/**
 * {@inheritDoc}
 */
@Override
public void register(T schemaObject) throws LdapException {
    String oid = schemaObject.getOid();
    if (byName.containsKey(oid)) {
        String msg = I18n.err(I18n.ERR_13736_ELEMENT_FOR_OID_ALREADY_REGISTERED, schemaObjectType.name(), oid);
        LOG.warn(msg);
        LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, msg);
        ldapSchemaException.setSourceObject(schemaObject);
        throw ldapSchemaException;
    }
    byName.put(oid, schemaObject);
    /*
         * add the aliases/names to the name map along with their toLowerCase
         * versions of the name: this is used to make sure name lookups work
         */
    for (String name : schemaObject.getNames()) {
        String lowerName = Strings.trim(Strings.toLowerCaseAscii(name));
        if (byName.containsKey(lowerName)) {
            String msg = I18n.err(I18n.ERR_13737_ELEMENT_WITH_NAME_ALREADY_REGISTERED, schemaObjectType.name(), name);
            LOG.warn(msg);
            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.NAME_ALREADY_REGISTERED, msg);
            ldapSchemaException.setSourceObject(schemaObject);
            throw ldapSchemaException;
        } else {
            byName.put(lowerName, schemaObject);
        }
    }
    // And register the oid -> schemaObject relation
    oidRegistry.register(schemaObject);
    if (LOG.isDebugEnabled()) {
        LOG.debug("registered " + schemaObject.getName() + " for OID {}", oid);
    }
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException)

Example 28 with LdapSchemaException

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

the class InitSearchRequestAttributeDescList method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
    // Here, we have to inject the decoded filter into the SearchRequest
    SearchRequestDecorator searchRequestDecorator = container.getMessage();
    SearchRequest searchRequest = searchRequestDecorator.getDecorated();
    try {
        searchRequest.setFilter(searchRequestDecorator.getFilterNode());
    } catch (LdapSchemaException lse) {
        throw new DecoderException(lse.getMessage(), lse);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
    if (IS_DEBUG) {
        LOG.debug("Initialize AttributeDesc list");
    }
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)

Example 29 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddObjectClassSuperiorsAbstractWithStructuralInSup.

/**
 * Addition of an ABSTRACT OC with some STRUCTURAL superior
 */
@Test
public void testAddObjectClassSuperiorsAbstractWithStructuralInSup() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
    objectClass.setNames("Test");
    objectClass.setType(ObjectClassTypeEnum.ABSTRACT);
    objectClass.addSuperiorOids("referral");
    assertFalse(schemaManager.add(objectClass));
    assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.1"));
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) Test(org.junit.Test)

Example 30 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddAttributeTypeSupBadSup.

/**
 * Try to inject an AttributeType with a bad superior
 */
@Test
public void testAddAttributeTypeSupBadSup() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid(null);
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    attributeType.setSuperiorOid("0.0");
    attributeType.setUsage(UsageEnum.DISTRIBUTED_OPERATION);
    // It should fail
    assertFalse(schemaManager.add(attributeType));
    List<Throwable> errors = schemaManager.getErrors();
    assertEquals(1, errors.size());
    Throwable error = errors.get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertFalse(isATPresent(schemaManager, "1.1.0"));
    assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

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