use of org.apache.directory.api.ldap.model.schema.ObjectClass 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");
}
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class Registries method clone.
/**
* Clone the Registries. This is done in two steps :
* - first clone the SchemaObjetc registries
* - second restore the relation between them
*/
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
// First clone the structure
Registries clone = (Registries) super.clone();
// Now, clone the oidRegistry
clone.globalOidRegistry = globalOidRegistry.copy();
// We have to clone every SchemaObject registries now
clone.attributeTypeRegistry = attributeTypeRegistry.copy();
clone.comparatorRegistry = comparatorRegistry.copy();
clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
clone.matchingRuleRegistry = matchingRuleRegistry.copy();
clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
clone.nameFormRegistry = nameFormRegistry.copy();
clone.normalizerRegistry = normalizerRegistry.copy();
clone.objectClassRegistry = objectClassRegistry.copy();
clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
// Store all the SchemaObjects into the globalOid registry
for (AttributeType attributeType : clone.attributeTypeRegistry) {
clone.globalOidRegistry.put(attributeType);
}
for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
clone.globalOidRegistry.put(ditContentRule);
}
for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
clone.globalOidRegistry.put(ditStructureRule);
}
for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
clone.globalOidRegistry.put(matchingRule);
}
for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
clone.globalOidRegistry.put(matchingRuleUse);
}
for (NameForm nameForm : clone.nameFormRegistry) {
clone.globalOidRegistry.put(nameForm);
}
for (ObjectClass objectClass : clone.objectClassRegistry) {
clone.globalOidRegistry.put(objectClass);
}
for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
clone.globalOidRegistry.put(syntax);
}
// Clone the schema list
clone.loadedSchemas = new HashMap<>();
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
// We don't clone the schemas
clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
}
// Clone the Using and usedBy structures
// They will be empty
clone.using = new HashMap<>();
clone.usedBy = new HashMap<>();
// Last, rebuild the using and usedBy references
clone.buildReferences();
// Now, check the registries. We don't care about errors
clone.checkRefInteg();
clone.schemaObjects = new HashMap<>();
// SchemaObjects
for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
Set<SchemaObjectWrapper> objects = new HashSet<>();
for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
SchemaObject original = schemaObjectWrapper.get();
try {
if (!(original instanceof LoadableSchemaObject)) {
SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
objects.add(newWrapper);
} else {
SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
objects.add(newWrapper);
}
} catch (LdapException ne) {
// Nothing to do
}
}
clone.schemaObjects.put(entry.getKey(), objects);
}
return clone;
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class Registries method resolveRecursive.
private void resolveRecursive(ObjectClass objectClass, Set<String> processed, List<Throwable> errors) {
// Process the Superiors, if any
List<String> superiorOids = objectClass.getSuperiorOids();
ObjectClass superior = null;
for (String superiorOid : superiorOids) {
// Check if the Superior is present in the registries
try {
superior = objectClassRegistry.lookup(superiorOid);
} catch (LdapException ne) {
// This OC's superior has not been loaded into the Registries.
if (!processed.contains(superiorOid)) {
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(superiorOid);
errors.add(ldapSchemaException);
}
}
// processed yet.
if (superior != null) {
if (!processed.contains(superior.getOid())) {
resolveRecursive(superior, processed, errors);
processed.add(objectClass.getOid());
} else {
// Not allowed : we have a cyle
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_CYCLE_CLASS_HIERARCHY);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setOtherObject(superior);
errors.add(ldapSchemaException);
return;
}
}
}
// Process the MAY attributeTypes.
for (String mayOid : objectClass.getMayAttributeTypeOids()) {
// Check if the MAY AttributeType is present in the registries
try {
attributeTypeRegistry.lookup(mayOid);
} catch (LdapException ne) {
// This AT has not been loaded into the Registries.
errors.add(ne);
}
}
// Process the MUST attributeTypes.
for (String mustOid : objectClass.getMustAttributeTypeOids()) {
// Check if the MUST AttributeType is present in the registries
try {
attributeTypeRegistry.lookup(mustOid);
} catch (LdapException ne) {
// This AT has not been loaded into the Registries.
errors.add(ne);
}
}
// All is done for this ObjectClass, let's apply the registries
try {
ObjectClassHelper.addToRegistries(objectClass, errors, this);
} catch (LdapException ne) {
// Do nothing. We may have a broken OC,
// but at this point, it doesn't matter.
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class DefaultObjectClassRegistry method registerDescendants.
/**
* {@inheritDoc}
*/
@Override
public void registerDescendants(ObjectClass objectClass, List<ObjectClass> ancestors) throws LdapException {
// add this attribute to descendant list of other attributes in superior chain
if ((ancestors == null) || ancestors.isEmpty()) {
return;
}
for (ObjectClass ancestor : ancestors) {
// Get the ancestor's descendant, if any
Set<ObjectClass> descendants = oidToDescendants.get(ancestor.getOid());
// Initialize the descendant Set to store the descendants for the attributeType
if (descendants == null) {
descendants = new HashSet<>(1);
oidToDescendants.put(ancestor.getOid(), descendants);
}
// Add the current ObjectClass as a descendant
descendants.add(objectClass);
try {
// And recurse until we reach the top of the hierarchy
registerDescendants(objectClass, ancestor.getSuperiors());
} catch (LdapException ne) {
throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
}
}
}
use of org.apache.directory.api.ldap.model.schema.ObjectClass in project directory-ldap-api by apache.
the class DefaultObjectClassRegistry method unregister.
/**
* {@inheritDoc}
*/
@Override
public ObjectClass unregister(String numericOid) throws LdapException {
try {
ObjectClass removed = super.unregister(numericOid);
// Deleting an ObjectClass which might be used as a superior means we have
// to recursively update the descendant map. We also have to remove
// the at.oid -> descendant relation
oidToDescendants.remove(numericOid);
// Now recurse if needed
unregisterDescendants(removed, removed.getSuperiors());
return removed;
} catch (LdapException ne) {
throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
}
}
Aggregations