use of org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry in project directory-ldap-api by apache.
the class ObjectClassHelper method buildSuperiors.
/**
* Build the references to this ObjectClass SUPERIORS, checking that the type
* hierarchy is correct.
*/
private static void buildSuperiors(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
List<String> superiorOids = objectClass.getSuperiorOids();
if (superiorOids != null) {
objectClass.getSuperiors().clear();
for (String superiorName : superiorOids) {
try {
ObjectClass superior = ocRegistry.lookup(ocRegistry.getOidByName(superiorName));
// Before adding the superior, check that the ObjectClass type is consistent
switch(objectClass.getType()) {
case ABSTRACT:
if (superior.getType() != ObjectClassTypeEnum.ABSTRACT) {
// An ABSTRACT OC can only inherit from ABSTRACT OCs
String msg = I18n.err(I18n.ERR_13766_ABSTRACT_OC_CANNOT_INHERIT_FROM_OC, objectClass.getOid(), superior.getObjectType(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case AUXILIARY:
if (superior.getType() == ObjectClassTypeEnum.STRUCTURAL) {
// An AUXILIARY OC cannot inherit from STRUCTURAL OCs
String msg = I18n.err(I18n.ERR_13767_AUX_OC_CANNOT_INHERIT_FROM_STRUCT_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
case STRUCTURAL:
if (superior.getType() == ObjectClassTypeEnum.AUXILIARY) {
// A STRUCTURAL OC cannot inherit from AUXILIARY OCs
String msg = I18n.err(I18n.ERR_13768_STRUCT_OC_CANNOT_INHERIT_FROM_AUX_OC, objectClass.getOid(), superior);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg);
ldapSchemaException.setSourceObject(objectClass);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13717_UNEXPECTED_OBJECT_CLASS_TYPE_ENUM, objectClass.getType()));
}
objectClass.getSuperiors().add(superior);
} catch (LdapException ne) {
// Cannot find the OC
String msg = I18n.err(I18n.ERR_13769_CANNOT_REGISTER_SUPERIOR_MISSING, objectClass.getOid(), superiorName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(superiorName);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry in project directory-ldap-api by apache.
the class ObjectClassHelper method removeFromRegistries.
/**
* Remove the ObjectClass from the registries, updating the references to
* other SchemaObject.
*
* If one of the referenced SchemaObject does not exist (SUPERIORS, MAY, MUST),
* an exception is thrown.
*
* @param objectClass The ObjectClass to remove fro the registries
* @param errors The errors we got while removing the ObjectClass from the registries
* @param registries The Registries
* @throws LdapException If the ObjectClass is not valid
*/
public static void removeFromRegistries(ObjectClass objectClass, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
ObjectClassRegistry objectClassRegistry = registries.getObjectClassRegistry();
// Unregister this ObjectClass into the Descendant map
objectClassRegistry.unregisterDescendants(objectClass, objectClass.getSuperiors());
/**
* Remove the OC references (using and usedBy) :
* OC -> AT (for MAY and MUST)
* OC -> OC
*/
if (objectClass.getMayAttributeTypes() != null) {
for (AttributeType may : objectClass.getMayAttributeTypes()) {
registries.delReference(objectClass, may);
}
}
if (objectClass.getMustAttributeTypes() != null) {
for (AttributeType must : objectClass.getMustAttributeTypes()) {
registries.delReference(objectClass, must);
}
}
if (objectClass.getSuperiors() != null) {
for (ObjectClass superior : objectClass.getSuperiors()) {
registries.delReference(objectClass, superior);
}
}
}
}
use of org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry in project structr by structr.
the class StructrLDAPWrapper method add.
public void add(final Entry entry) throws LdapException {
try (final Tx tx = app().tx()) {
// create while descending
final Dn dn = entry.getDn();
final LDAPNode parent = find(dn.getParent());
if (parent != null) {
final Attribute objectClasses = entry.get(schemaManager.getAttributeType(SchemaConstants.OBJECT_CLASS_AT_OID));
final ObjectClassRegistry reg = schemaManager.getObjectClassRegistry();
final Set<String> classes = new LinkedHashSet<>();
final Rdn rdn = dn.getRdn();
String mainClass = null;
// make rdn schema aware
if (!rdn.isSchemaAware()) {
rdn.apply(schemaManager);
}
if (objectClasses != null) {
for (final Value<?> value : objectClasses) {
final String cls = value.getString();
final String objectClassOid = reg.getOidByName(cls);
if (reg.get(objectClassOid).isStructural()) {
mainClass = cls;
} else {
classes.add(cls);
}
}
final LDAPNode newChild = parent.createChild(rdn.getNormName(), rdn.getName(), mainClass, classes);
if (newChild != null) {
for (final Attribute attr : entry) {
AttributeType type = attr.getAttributeType();
String oid = null;
if (type != null) {
oid = type.getOid();
} else {
type = schemaManager.getAttributeType(attr.getUpId());
oid = type.getOid();
}
newChild.createAttribute(oid, attr.getUpId(), attr);
}
} else {
logger.warn("Unable to add entry {}, could not create new instance", entry);
}
} else {
logger.warn("Unable to add entry {}, could not determine object class(es)", entry);
}
} else {
logger.warn("Unable to add entry {}, parent not found", entry);
}
tx.success();
} catch (FrameworkException fex) {
handleException(fex);
}
}
use of org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry in project directory-ldap-api by apache.
the class DitContentRuleHelper method addToRegistries.
/**
* Inject the DitContentRule into the registries, updating the references to
* other SchemaObject
*
* @param ditContentRule The DitContentRule to add to the Registries
* @param errors The errors we got while adding the DitContentRule to the Registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
public static void addToRegistries(DitContentRule ditContentRule, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
ditContentRule.unlock();
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
if (ditContentRule.getMayAttributeTypeOids() != null) {
ditContentRule.getMayAttributeTypes().clear();
for (String oid : ditContentRule.getMayAttributeTypeOids()) {
ditContentRule.getMayAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getMustAttributeTypeOids() != null) {
ditContentRule.getMustAttributeTypes().clear();
for (String oid : ditContentRule.getMustAttributeTypeOids()) {
ditContentRule.getMustAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getNotAttributeTypeOids() != null) {
ditContentRule.getNotAttributeTypes().clear();
for (String oid : ditContentRule.getNotAttributeTypeOids()) {
ditContentRule.getNotAttributeTypes().add(atRegistry.lookup(oid));
}
}
if (ditContentRule.getAuxObjectClassOids() != null) {
ditContentRule.getAuxObjectClasses().clear();
for (String oid : ditContentRule.getAuxObjectClassOids()) {
ditContentRule.getAuxObjectClasses().add(ocRegistry.lookup(oid));
}
}
} finally {
ditContentRule.lock();
}
}
}
Aggregations