Search in sources :

Example 46 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddAttributeTypeSupDifferentUsage.

/**
 * Try to inject an AttributeType with a superior and different USAGE
 */
@Test
public void testAddAttributeTypeSupDifferentUsage() 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("2.5.18.4");
    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)

Example 47 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithExistingOid.

/**
 * Addition of an OC with an existing OID
 */
@Test
public void testAddObjectClassNoSuperiorWithExistingOid() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass objectClass = new ObjectClass("2.5.17.0");
    assertFalse(schemaManager.add(objectClass));
    assertEquals(1, schemaManager.getErrors().size());
    Throwable error = schemaManager.getErrors().get(0);
    assertTrue(error instanceof LdapSchemaException);
    ObjectClass added = schemaManager.lookupObjectClassRegistry("2.5.17.0");
    assertNotNull(added);
    assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) 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) Test(org.junit.Test)

Example 48 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddAttributeTypeNoSupCollectiveOperational.

/**
 * Try to inject an AttributeType which is Collective, but an operational AT
 */
@Test
public void testAddAttributeTypeNoSupCollectiveOperational() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    attributeType.setUsage(UsageEnum.DIRECTORY_OPERATION);
    attributeType.setCollective(true);
    // 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)

Example 49 with LdapSchemaException

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

the class SchemaManagerAddTest method testAddAttributeTypeCollectiveOperationalSigleValue.

/**
 * Try to inject a single valued AttributeType which is Collective
 */
@Test
public void testAddAttributeTypeCollectiveOperationalSigleValue() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
    attributeType.setEqualityOid("2.5.13.1");
    attributeType.setOrderingOid(null);
    attributeType.setSubstringOid(null);
    attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
    attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
    attributeType.setCollective(true);
    attributeType.setSingleValued(true);
    // 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)

Example 50 with LdapSchemaException

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

the class SchemaEntityFactory method classLoadSyntaxChecker.

/**
 * Class load a syntaxChecker instance
 */
private SyntaxChecker classLoadSyntaxChecker(SchemaManager schemaManager, String oid, String className, Attribute byteCode) throws LdapException {
    // Try to class load the syntaxChecker
    Class<?> clazz;
    SyntaxChecker syntaxChecker;
    String byteCodeStr = StringConstants.EMPTY;
    if (byteCode == null) {
        try {
            clazz = Class.forName(className);
        } catch (ClassNotFoundException cnfe) {
            LOG.error(I18n.err(I18n.ERR_16048_CANNOT_FIND_SC_CTOR, className));
            throw new LdapSchemaException(I18n.err(I18n.ERR_16049_CANNOT_FIND_SC_CLASS, cnfe.getMessage()));
        }
    } else {
        classLoader.setAttribute(byteCode);
        try {
            clazz = classLoader.loadClass(className);
        } catch (ClassNotFoundException cnfe) {
            LOG.error(I18n.err(I18n.ERR_16050_CANNOT_LOAD_SC_CTOR, className));
            throw new LdapSchemaException(I18n.err(I18n.ERR_16051_CANNOT_LOAD_SC_CLASS, cnfe.getMessage()));
        }
        byteCodeStr = new String(Base64.encode(byteCode.getBytes()));
    }
    // Create the syntaxChecker instance
    try {
        Method builder = clazz.getMethod("builder", null);
        syntaxChecker = (SyntaxChecker) ((SCBuilder) builder.invoke(null, null)).setOid(oid).build();
    } catch (NoSuchMethodException nsme) {
        LOG.error(I18n.err(I18n.ERR_16052_CANNOT_INST_SC_CTOR, className));
        throw new LdapSchemaException(I18n.err(I18n.ERR_16053_CANNOT_INST_SC_CLASS, nsme.getMessage()));
    } catch (InvocationTargetException | IllegalAccessException e) {
        LOG.error(I18n.err(I18n.ERR_16054_CANNOT_ACCESS_SC_CTOR, className));
        throw new LdapSchemaException(I18n.err(I18n.ERR_16055_CANNOT_ACCESS_SC_CLASS, e.getMessage()));
    }
    // Update the common fields
    syntaxChecker.setBytecode(byteCodeStr);
    syntaxChecker.setFqcn(className);
    // Inject the SchemaManager for the comparator who needs it
    syntaxChecker.setSchemaManager(schemaManager);
    return syntaxChecker;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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