use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddAttributeTypeNoSupInvalidOrderingMR.
/**
* Try to inject an AttributeType with an invalid ORDERING MR
*/
@Test
public void testAddAttributeTypeNoSupInvalidOrderingMR() throws Exception {
SchemaManager schemaManager = loadSystem();
int atrSize = schemaManager.getAttributeTypeRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableAttributeType attributeType = new MutableAttributeType("1.1.0");
attributeType.setEqualityOid(null);
attributeType.setOrderingOid("0.0");
attributeType.setSubstringOid(null);
attributeType.setSyntaxOid("1.3.6.1.4.1.1466.115.121.1.26");
attributeType.setUsage(UsageEnum.USER_APPLICATIONS);
// It should fail
assertFalse(schemaManager.add(attributeType));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertFalse(isATPresent(schemaManager, "1.1.0"));
assertEquals(atrSize, schemaManager.getAttributeTypeRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup.
/**
* Addition of an ABSTRACT OC with some AUXILIARY superior
*/
@Test
public void testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.ABSTRACT);
objectClass.addSuperiorOids("extensibleObject");
assertFalse(schemaManager.add(objectClass));
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddObjectClassSuperiorsATInMayPresentInSuperiorsMust.
/**
* Addition of an OC with some AT present in MAY and in MUST in one of its
* superior : not allowed
*/
@Test
public void testAddObjectClassSuperiorsATInMayPresentInSuperiorsMust() throws Exception {
SchemaManager schemaManager = loadSystem();
int ocrSize = schemaManager.getObjectClassRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableObjectClass objectClass = new MutableObjectClass("1.1.1");
objectClass.setNames("Test");
objectClass.setType(ObjectClassTypeEnum.STRUCTURAL);
objectClass.addSuperiorOids("alias", "OpenLDAProotDSE");
objectClass.addMayAttributeTypeOids("aliasedObjectName", "cn");
assertFalse(schemaManager.add(objectClass));
assertEquals(1, schemaManager.getErrors().size());
assertTrue(schemaManager.getErrors().get(0) instanceof LdapSchemaException);
assertFalse(isOCPresent(schemaManager, "1.1.1"));
assertEquals(ocrSize, schemaManager.getObjectClassRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException 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.exception.LdapSchemaException in project directory-ldap-api by apache.
the class ObjectClassHelper method buildMay.
/**
* Build and check the MAY AT for this ObjectClass
*/
private static void buildMay(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
AttributeTypeRegistry atRegistry = registries.getAttributeTypeRegistry();
List<String> mayAttributeTypeOids = objectClass.getMayAttributeTypeOids();
if (mayAttributeTypeOids != null) {
objectClass.getMayAttributeTypes().clear();
for (String mayAttributeTypeName : mayAttributeTypeOids) {
try {
AttributeType attributeType = atRegistry.lookup(mayAttributeTypeName);
if (attributeType.isCollective()) {
// Collective Attributes are not allowed in MAY or MUST
String msg = I18n.err(I18n.ERR_13779_COLLECTIVE_NOT_ALLOWED_IN_MAY, mayAttributeTypeName, objectClass.getOid());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_COLLECTIVE_NOT_ALLOWED_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
if (objectClass.getMayAttributeTypes().contains(attributeType)) {
// Already registered : this is an error
String msg = I18n.err(I18n.ERR_13770_CANNOT_REGISTER_DUPLICATE_AT_IN_MAY, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY, msg);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
objectClass.getMayAttributeTypes().add(attributeType);
} catch (LdapException ne) {
// Cannot find the AT
String msg = I18n.err(I18n.ERR_13771_CANNOT_REGISTER_AT_IN_MAY_DOES_NOT_EXIST, objectClass.getOid(), mayAttributeTypeName);
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_MAY_AT, msg, ne);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setRelatedId(mayAttributeTypeName);
errors.add(ldapSchemaException);
LOG.info(msg);
continue;
}
}
}
}
Aggregations