Search in sources :

Example 1 with OpenLdapObjectIdentifierMacro

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

the class OpenLdapSchemaParser method afterParse.

/**
 * Splits parsed schema descriptions and resolved
 * object identifier macros.
 *
 * @throws ParseException the parse exception
 */
private void afterParse() throws ParseException {
    objectClasses = new ArrayList<>();
    attributeTypes = new ArrayList<>();
    objectIdentifierMacros = new HashMap<>();
    // split parsed schema descriptions
    for (Object obj : schemaDescriptions) {
        if (obj instanceof OpenLdapObjectIdentifierMacro) {
            OpenLdapObjectIdentifierMacro oid = (OpenLdapObjectIdentifierMacro) obj;
            objectIdentifierMacros.put(oid.getName(), oid);
        } else if (obj instanceof AttributeType) {
            MutableAttributeType attributeType = (MutableAttributeType) obj;
            attributeTypes.add(attributeType);
        } else if (obj instanceof ObjectClass) {
            ObjectClass objectClass = (ObjectClass) obj;
            objectClasses.add(objectClass);
        }
    }
    if (isResolveObjectIdentifierMacros()) {
        // resolve object identifier macros
        for (OpenLdapObjectIdentifierMacro oid : objectIdentifierMacros.values()) {
            resolveObjectIdentifierMacro(oid);
        }
        // apply object identifier macros to object classes
        for (ObjectClass objectClass : objectClasses) {
            objectClass.setOid(getResolveOid(objectClass.getOid()));
        }
        // apply object identifier macros to attribute types
        for (MutableAttributeType attributeType : attributeTypes) {
            attributeType.setOid(getResolveOid(attributeType.getOid()));
            attributeType.setSyntaxOid(getResolveOid(attributeType.getSyntaxOid()));
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) OpenLdapObjectIdentifierMacro(org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Example 2 with OpenLdapObjectIdentifierMacro

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

the class OpenLdapSchemaParserTest method testParseOpenLdapCollectiveSchema.

@Test
public void testParseOpenLdapCollectiveSchema() throws Exception {
    InputStream input = getClass().getResourceAsStream("collective.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(13, attributeTypes.size());
    assertEquals(0, objectClassTypes.size());
    assertEquals(0, objectIdentifierMacros.size());
    for (AttributeType attributeTypeLiteral : attributeTypes) {
        assertTrue(attributeTypeLiteral.isCollective());
    }
}
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) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 3 with OpenLdapObjectIdentifierMacro

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

the class OpenLdapSchemaParserTest method testOpenLdapObjectIdentifiereMacros.

@Test
public void testOpenLdapObjectIdentifiereMacros() throws Exception {
    InputStream input = getClass().getResourceAsStream("dyngroup.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(2, attributeTypes.size());
    assertEquals(2, objectClassTypes.size());
    assertEquals(8, objectIdentifierMacros.size());
    // check that all macros are resolved
    for (OpenLdapObjectIdentifierMacro macro : objectIdentifierMacros.values()) {
        assertTrue(macro.isResolved());
        assertNotNull(macro.getResolvedOid());
        assertTrue(macro.getResolvedOid().matches("[0-9]+(\\.[0-9]+)+"));
    }
    // check that OIDs in attribute types and object classes are resolved
    for (ObjectClass objectClass : objectClassTypes) {
        List<String> asList = objectClass.getNames();
        if (asList.contains("groupOfURLs")) {
            assertEquals("2.16.840.1.113730.3.2.33", objectClass.getOid());
        } else if (asList.contains("dgIdentityAux")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.2.1", objectClass.getOid());
        } else {
            fail("object class 'groupOfURLs' or 'dgIdentityAux' expected");
        }
    }
    for (AttributeType attributeType : attributeTypes) {
        List<String> asList = attributeType.getNames();
        if (asList.contains("memberURL")) {
            assertEquals("2.16.840.1.113730.3.1.198", attributeType.getOid());
        } else if (asList.contains("dgIdentity")) {
            assertEquals("1.3.6.1.4.1.4203.666.11.8.1.1", attributeType.getOid());
        } else {
            fail("attribute type 'memberURL' or 'dgIdentity' expected");
        }
    }
}
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) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 4 with OpenLdapObjectIdentifierMacro

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

the class OpenLdapSchemaParserTest method testParseOpenLdapCoreSchema.

@Test
public void testParseOpenLdapCoreSchema() throws Exception {
    InputStream input = getClass().getResourceAsStream("core.schema");
    parser.parse(input);
    List<MutableAttributeType> attributeTypes = parser.getAttributeTypes();
    List<ObjectClass> objectClassTypes = parser.getObjectClassTypes();
    Map<String, OpenLdapObjectIdentifierMacro> objectIdentifierMacros = parser.getObjectIdentifierMacros();
    assertEquals(52, attributeTypes.size());
    assertEquals(27, 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 5 with OpenLdapObjectIdentifierMacro

use of org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro 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)

Aggregations

MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)5 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)5 OpenLdapObjectIdentifierMacro (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OpenLdapObjectIdentifierMacro)5 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)1