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()));
}
}
}
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));
}
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
}
}
}
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);
}
}
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());
}
Aggregations