Search in sources :

Example 46 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class OpenLdapSchemaParserTest method testParseOpenLdapInetOrgPersonSchema.

@Test
public void testParseOpenLdapInetOrgPersonSchema() throws Exception {
    InputStream input = getClass().getResourceAsStream("inetorgperson.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(9, attributeTypes.size());
    assertEquals(1, objectClassTypes.size());
    assertEquals(0, objectIdentifierMacros.size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) OpenLdapObjectIdentifierMacro(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro) InputStream(java.io.InputStream) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 47 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class LdapNetworkConnection method addSchema.

/**
 * parses the given schema file present in OpenLDAP schema format
 * and adds all the SchemaObjects present in it to the SchemaManager
 *
 * @param schemaFile the schema file in OpenLDAP schema format
 * @throws LdapException in case of any errors while parsing
 */
public void addSchema(File schemaFile) throws LdapException {
    try {
        if (schemaManager == null) {
            loadSchema();
        }
        if (schemaManager == null) {
            throw new LdapException("Cannot load the schema");
        }
        OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
        olsp.setQuirksMode(true);
        olsp.parse(schemaFile);
        Registries registries = schemaManager.getRegistries();
        List<Throwable> errors = new ArrayList<>();
        for (AttributeType atType : olsp.getAttributeTypes()) {
            registries.buildReference(errors, atType);
            registries.getAttributeTypeRegistry().register(atType);
        }
        for (ObjectClass oc : olsp.getObjectClassTypes()) {
            registries.buildReference(errors, oc);
            registries.getObjectClassRegistry().register(oc);
        }
        LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
    } catch (Exception e) {
        LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
        throw new LdapException(e);
    }
}
Also used : OpenLdapSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ArrayList(java.util.ArrayList) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 48 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithExistingOCName.

/**
 * Addition of an OC with an existing OC name
 */
@Test
public void testAddObjectClassNoSuperiorWithExistingOCName() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass objectClass = new ObjectClass("1.1.0");
    objectClass.setNames("Test", "referral");
    assertFalse(schemaManager.add(objectClass));
    assertEquals(1, schemaManager.getErrors().size());
    Throwable error = schemaManager.getErrors().get(0);
    assertTrue(error instanceof LdapSchemaException);
    assertFalse(isOCPresent(schemaManager, "1.1.0"));
    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 49 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddObjectClassNoSuperiorWithATName.

/**
 * Addition of an OC with an AT name
 */
@Test
public void testAddObjectClassNoSuperiorWithATName() throws Exception {
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    ObjectClass objectClass = new ObjectClass("1.1.1");
    objectClass.setNames("Test", "cn");
    assertTrue(schemaManager.add(objectClass));
    assertEquals(0, schemaManager.getErrors().size());
    ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
    assertNotNull(added);
    assertTrue(added.getNames().contains("Test"));
    assertTrue(added.getNames().contains("cn"));
    assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 50 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.

the class SchemaManagerAddTest method testAddObjectClassSuperiorsValid.

// -------------------------------------------------------------------------
// Then, with superiors
// -------------------------------------------------------------------------
/**
 * Addition of a valid OC with some superiors
 */
@Test
public void testAddObjectClassSuperiorsValid() 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.STRUCTURAL);
    objectClass.addSuperiorOids("alias", "referral", "top");
    assertTrue(schemaManager.add(objectClass));
    assertEquals(0, schemaManager.getErrors().size());
    ObjectClass added = schemaManager.lookupObjectClassRegistry("1.1.1");
    assertNotNull(added);
    assertTrue(added.getNames().contains("Test"));
    assertNotNull(added.getSuperiors());
    assertEquals(3, added.getSuperiors().size());
    Set<String> expectedSups = new HashSet<String>();
    expectedSups.add("alias");
    expectedSups.add("referral");
    expectedSups.add("top");
    for (ObjectClass addedOC : added.getSuperiors()) {
        assertTrue(expectedSups.contains(addedOC.getName()));
        expectedSups.remove(addedOC.getName());
    }
    assertEquals(ocrSize + 1, schemaManager.getObjectClassRegistry().size());
    assertEquals(goidSize + 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)53 Test (org.junit.Test)34 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)11 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)11 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)10 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)9 MutableObjectClass (org.apache.directory.api.ldap.model.schema.MutableObjectClass)6 ParseException (java.text.ParseException)5 HashSet (java.util.HashSet)5 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 LdapNoSuchAttributeException (org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)3 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)3 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2