use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class Registries method resolve.
private void resolve(ObjectClass objectClass, List<Throwable> errors) {
// This set is used to avoid having more than one error
// for an ObjectClass. It's mandatory when processing
// the Superiors, as they may be broken and referenced more than once.
Set<String> processed = new HashSet<>();
// Store the ObjectClass itself in the processed, to avoid cycle
processed.add(objectClass.getOid());
// Call the recursive method, as we may have superiors to deal with
resolveRecursive(objectClass, processed, errors);
// Check that the MAY and MUST AT are consistent (no AT in MAY and in MUST
// in one of its superior
List<AttributeType> musts = getMustRecursive(new ArrayList<AttributeType>(), new HashSet<ObjectClass>(), objectClass);
if (musts != null) {
for (AttributeType may : objectClass.getMayAttributeTypes()) {
if (musts.contains(may)) {
// This is not allowed.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_DUPLICATE_AT_IN_MAY_AND_MUST);
ldapSchemaException.setSourceObject(objectClass);
ldapSchemaException.setOtherObject(may);
errors.add(ldapSchemaException);
}
}
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class Registries method resolve.
/**
* Check if the Comparator, Normalizer and the syntax are
* existing for a matchingRule.
*/
private void resolve(MatchingRule matchingRule, List<Throwable> errors) {
// Process the Syntax. It can't be null
String syntaxOid = matchingRule.getSyntaxOid();
if (syntaxOid != null) {
// Check if the Syntax is present in the registries
try {
ldapSyntaxRegistry.lookup(syntaxOid);
} catch (LdapException ne) {
// This MR's syntax has not been loaded into the Registries.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()), ne);
ldapSchemaException.setSourceObject(matchingRule);
errors.add(ldapSchemaException);
}
} else {
// This is an error.
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OID_ALREADY_REGISTERED, I18n.err(I18n.ERR_13748_MATCHING_RULE_NO_SYNTAX, matchingRule.getOid()));
ldapSchemaException.setSourceObject(matchingRule);
errors.add(ldapSchemaException);
}
// Process the Normalizer
Normalizer normalizer = matchingRule.getNormalizer();
if (normalizer == null) {
// Ok, no normalizer, this is an error
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_13220_NO_NORMALIZER, matchingRule.getOid()));
errors.add(error);
}
// Process the Comparator
LdapComparator<?> comparator = matchingRule.getLdapComparator();
if (comparator == null) {
// Ok, no comparator, this is an error
Throwable error = new LdapSchemaViolationException(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err(I18n.ERR_04296, matchingRule.getOid()));
errors.add(error);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class AttributeTypeHelper method buildEquality.
/**
* Build the EQUALITY MR reference for an AttributeType
*/
private static void buildEquality(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
String equalityOid = attributeType.getEqualityOid();
// The equality MR. It can be null
if (equalityOid != null) {
MatchingRule currentEquality = null;
try {
currentEquality = registries.getMatchingRuleRegistry().lookup(equalityOid);
} catch (LdapException ne) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13756_CANNOT_FIND_EQUALITY_MR_OBJECT, equalityOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg, ne);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(equalityOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
if (currentEquality != null) {
attributeType.setEquality(currentEquality);
// Restore the old equality OID to preserve the user's provided value
attributeType.setEqualityOid(equalityOid);
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13757_CANNOT_FIND_EQUALITY_MR_INSTANCE, equalityOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_EQUALITY_MATCHING_RULE, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(equalityOid);
errors.add(ldapSchemaException);
LOG.info(msg);
}
} else {
AttributeType superior = attributeType.getSuperior();
// If the AT has a superior, take its Equality MR if any
if ((superior != null) && (superior.getEquality() != null)) {
attributeType.setEquality(superior.getEquality());
}
}
}
use of org.apache.directory.api.ldap.model.exception.LdapSchemaException in project directory-ldap-api by apache.
the class AttributeTypeHelper method buildSyntax.
/**
* Build the SYNTAX reference for an AttributeType
*/
private static void buildSyntax(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
String syntaxOid = attributeType.getSyntaxOid();
if (syntaxOid != null) {
LdapSyntax currentSyntax = null;
try {
currentSyntax = registries.getLdapSyntaxRegistry().lookup(syntaxOid);
} catch (LdapException ne) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg, ne);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(syntaxOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
if (currentSyntax != null) {
// Update the Syntax reference
attributeType.setSyntax(currentSyntax);
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(syntaxOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
} else {
// We inherit from the superior's syntax, if any
if (attributeType.getSuperior() != null) {
if (attributeType.getSuperior().getSyntax() != null) {
attributeType.setSyntax(attributeType.getSuperior().getSyntax());
} else {
String msg = I18n.err(I18n.ERR_13754_CANNOT_FIND_SYNTAX, syntaxOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SYNTAX, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(syntaxOid);
errors.add(ldapSchemaException);
LOG.info(msg);
return;
}
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13755_AT_MUST_HAVE_A_SYNTAX_OID, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_SYNTAX_OR_SUPERIOR_REQUIRED, msg);
ldapSchemaException.setSourceObject(attributeType);
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 AttributeTypeHelper method buildSuperior.
/**
* Build the Superior AttributeType reference for an AttributeType
*/
private static boolean buildSuperior(MutableAttributeType attributeType, List<Throwable> errors, Registries registries) {
MutableAttributeType currentSuperior;
AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();
String superiorOid = attributeType.getSuperiorOid();
if (superiorOid != null) {
// This AT has a superior
try {
currentSuperior = (MutableAttributeType) attributeTypeRegistry.lookup(superiorOid);
} catch (Exception e) {
// Not allowed.
String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg, e);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(superiorOid);
errors.add(ldapSchemaException);
LOG.info(msg);
// Get out now
return false;
}
if (currentSuperior != null) {
// a special case : if the superior is collective, this is an error
if (currentSuperior.isCollective()) {
String msg = I18n.err(I18n.ERR_13776_CANNOT_SUBTYPE_COLLECTIVE, currentSuperior, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CANNOT_SUBTYPE_COLLECTIVE_AT, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
return false;
}
attributeType.setSuperior(currentSuperior);
// handled.
if (currentSuperior.getSuperior() == null) {
registries.buildReference(errors, currentSuperior);
}
// Update the descendant MAP
try {
attributeTypeRegistry.registerDescendants(attributeType, currentSuperior);
} catch (LdapException ne) {
errors.add(ne);
LOG.info(ne.getMessage());
return false;
}
// Check for cycles now
Set<String> superiors = new HashSet<>();
superiors.add(attributeType.getOid());
AttributeType tmp = currentSuperior;
boolean isOk = true;
while (tmp != null) {
if (superiors.contains(tmp.getOid())) {
// There is a cycle : bad bad bad !
// Not allowed.
String msg = I18n.err(I18n.ERR_13753_CYCLE_DETECTED, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_CYCLE_TYPE_HIERARCHY, msg);
ldapSchemaException.setSourceObject(attributeType);
errors.add(ldapSchemaException);
LOG.info(msg);
isOk = false;
break;
} else {
superiors.add(tmp.getOid());
tmp = tmp.getSuperior();
}
}
superiors.clear();
return isOk;
} else {
// Not allowed.
String msg = I18n.err(I18n.ERR_13752_CANNOT_FIND_SUPERIOR, superiorOid, attributeType.getName());
LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.AT_NONEXISTENT_SUPERIOR, msg);
ldapSchemaException.setSourceObject(attributeType);
ldapSchemaException.setRelatedId(superiorOid);
errors.add(ldapSchemaException);
LOG.info(msg);
// Get out now
return false;
}
} else {
// No superior, just return
return true;
}
}
Aggregations