Search in sources :

Example 16 with ObjectClass

use of org.apache.directory.api.ldap.model.schema.ObjectClass 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 17 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testNovellDcObject.

@Test
public void testNovellDcObject() throws ParseException, NamingException {
    String value = "( 1.3.6.1.4.1.1466.344 NAME 'dcObject' AUXILIARY MUST dc X-NDS_NAMING 'dc' X-NDS_NOT_CONTAINER '1' X-NDS_NONREMOVABLE '1' )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("1.3.6.1.4.1.1466.344", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("dcObject", objectClass.getNames().get(0));
    assertNull(objectClass.getDescription());
    assertEquals(0, objectClass.getSuperiorOids().size());
    assertEquals(ObjectClassTypeEnum.AUXILIARY, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("dc", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(0, objectClass.getMayAttributeTypeOids().size());
    assertEquals(3, objectClass.getExtensions().size());
    assertNotNull(objectClass.getExtension("X-NDS_NAMING"));
    assertEquals(1, objectClass.getExtension("X-NDS_NAMING").size());
    assertEquals("dc", objectClass.getExtension("X-NDS_NAMING").get(0));
    assertNotNull(objectClass.getExtension("X-NDS_NOT_CONTAINER"));
    assertEquals(1, objectClass.getExtension("X-NDS_NOT_CONTAINER").size());
    assertEquals("1", objectClass.getExtension("X-NDS_NOT_CONTAINER").get(0));
    assertNotNull(objectClass.getExtension("X-NDS_NONREMOVABLE"));
    assertEquals(1, objectClass.getExtension("X-NDS_NONREMOVABLE").size());
    assertEquals("1", objectClass.getExtension("X-NDS_NONREMOVABLE").get(0));
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 18 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testMust.

/**
 * Test MUST and its values.
 * Very similar to SUP, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testMust() throws ParseException {
    String value = null;
    ObjectClass objectClass = null;
    // no MUST
    value = "( 1.1 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(0, objectClass.getMustAttributeTypeOids().size());
    // MUST simple numericoid
    value = "( 1.1 MUST 1.2.3 )";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("1.2.3", objectClass.getMustAttributeTypeOids().get(0));
    // MUST multiple
    value = "(1.1 MUST(cn$sn\r$11.22.33.44.55         $  objectClass   ))";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(4, objectClass.getMustAttributeTypeOids().size());
    assertEquals("cn", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals("sn", objectClass.getMustAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", objectClass.getMustAttributeTypeOids().get(2));
    assertEquals("objectClass", objectClass.getMustAttributeTypeOids().get(3));
    // MUST multiple, no $ separator
    value = "(1.1 MUST(cn sn\t'11.22.33.44.55'\n'objectClass'))";
    objectClass = parser.parseObjectClassDescription(value);
    assertEquals(4, objectClass.getMustAttributeTypeOids().size());
    assertEquals("cn", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals("sn", objectClass.getMustAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", objectClass.getMustAttributeTypeOids().get(2));
    assertEquals("objectClass", objectClass.getMustAttributeTypeOids().get(3));
    // no MUST values
    value = "( 1.1 MUST )";
    try {
        objectClass = parser.parseObjectClassDescription(value);
        fail("Exception expected, no MUST value");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // invalid value
        value = "( 1.1 MUST ( c_n ) )";
        try {
            objectClass = parser.parseObjectClassDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 19 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testQuirksMode.

/**
 * Tests quirks mode.
 */
@Test
public void testQuirksMode() throws ParseException, NamingException {
    SchemaParserTestUtils.testQuirksMode(parser, "");
    try {
        String value = null;
        ObjectClass objectClass = null;
        parser.setQuirksMode(true);
        // ensure all other test pass in quirks mode
        testNumericOid();
        testNames();
        testDescription();
        testObsolete();
        testSuperior();
        testKind();
        testMust();
        testMay();
        testExtensions();
        testFull();
        testUniqueElements();
        testIgnoreElementOrder();
        testRfcTop();
        testRfcSimpleSecurityObject();
        testSunAlias();
        testNovellDcObject();
        testNovellList();
        testMicrosoftAds2000Locality();
        testMicrosoftAds2003Msieee();
        testSiemensDirxX500Subschema();
        testMultiThreaded();
        // NAME with special chars
        value = "( 1.2.3 NAME 't-e_s.t;' )";
        objectClass = parser.parseObjectClassDescription(value);
        assertEquals(1, objectClass.getNames().size());
        assertEquals("t-e_s.t;", objectClass.getNames().get(0));
        // SUP with underscore
        value = "( 1.1 SUP te_st )";
        objectClass = parser.parseObjectClassDescription(value);
        assertEquals(1, objectClass.getSuperiorOids().size());
        assertEquals("te_st", objectClass.getSuperiorOids().get(0));
        // MAY with underscore
        value = "( 1.1 MAY te_st )";
        objectClass = parser.parseObjectClassDescription(value);
        assertEquals(1, objectClass.getMayAttributeTypeOids().size());
        assertEquals("te_st", objectClass.getMayAttributeTypeOids().get(0));
        // MUST with underscore
        value = "( 1.1 MUST te_st )";
        objectClass = parser.parseObjectClassDescription(value);
        assertEquals(1, objectClass.getMustAttributeTypeOids().size());
        assertEquals("te_st", objectClass.getMustAttributeTypeOids().get(0));
        // Netscape object class
        value = "( nsAdminGroup-oid NAME 'nsAdminGroup' DESC 'Netscape defined objectclass' SUP top STRUCTURAL MUST cn MAY ( nsAdminGroupName $ description $ nsConfigRoot $ nsAdminSIEDN ) X-ORIGIN 'Netscape' )";
        objectClass = parser.parseObjectClassDescription(value);
        assertEquals("nsAdminGroup-oid", objectClass.getOid());
        assertEquals(1, objectClass.getNames().size());
        assertEquals("nsAdminGroup", objectClass.getNames().get(0));
    } finally {
        parser.setQuirksMode(false);
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) Test(org.junit.Test)

Example 20 with ObjectClass

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

the class ObjectClassDescriptionSchemaParserTest method testRfcTop.

// //////////////////////////////////////////////////////////////
// Some real-world object class definitions          //
// //////////////////////////////////////////////////////////////
@Test
public void testRfcTop() throws ParseException, NamingException {
    String value = "( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )";
    ObjectClass objectClass = parser.parseObjectClassDescription(value);
    assertEquals("2.5.6.0", objectClass.getOid());
    assertEquals(1, objectClass.getNames().size());
    assertEquals("top", objectClass.getNames().get(0));
    assertEquals("top of the superclass chain", objectClass.getDescription());
    assertEquals(0, objectClass.getSuperiorOids().size());
    assertEquals(ObjectClassTypeEnum.ABSTRACT, objectClass.getType());
    assertEquals(1, objectClass.getMustAttributeTypeOids().size());
    assertEquals("objectClass", objectClass.getMustAttributeTypeOids().get(0));
    assertEquals(0, objectClass.getMayAttributeTypeOids().size());
    assertEquals(0, objectClass.getExtensions().size());
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) 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