use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class Registries method unregister.
/**
* Unregister a SchemaObject from the registries
*
* @param schemaObject The SchemaObject we want to deregister
* @throws LdapException If the removal failed
*/
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is present in the registries
if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
SchemaObject unregistered;
// First call the specific registry's register method
switch(schemaObject.getObjectType()) {
case ATTRIBUTE_TYPE:
unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
break;
case COMPARATOR:
unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
break;
case DIT_CONTENT_RULE:
unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
break;
case DIT_STRUCTURE_RULE:
unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
break;
case LDAP_SYNTAX:
unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
break;
case MATCHING_RULE:
unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
break;
case MATCHING_RULE_USE:
unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
break;
case NAME_FORM:
unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
break;
case NORMALIZER:
unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
break;
case OBJECT_CLASS:
unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
break;
case SYNTAX_CHECKER:
unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
break;
default:
throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
}
return unregistered;
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class Registries method check.
/**
* Check the registries for invalid relations. This check stops at the first error.
*
* @return true if the Registries is consistent, false otherwise
*/
public boolean check() {
// Check the Syntaxes : check for a SyntaxChecker
LOG.debug("Checking Syntaxes");
for (LdapSyntax syntax : ldapSyntaxRegistry) {
// Check that each Syntax has a SyntaxChecker
if (syntax.getSyntaxChecker() == null) {
LOG.debug("The Syntax {} has no SyntaxChecker", syntax);
return false;
}
if (!syntaxCheckerRegistry.contains(syntax.getSyntaxChecker().getOid())) {
LOG.debug("Cannot find the SyntaxChecker {} for the Syntax {}", syntax.getSyntaxChecker().getOid(), syntax);
return false;
}
// Check the references : Syntax -> SyntaxChecker and SyntaxChecker -> Syntax
if (!checkReferences(syntax, syntax.getSyntaxChecker(), "SyntaxChecker")) {
return false;
}
}
// Check the MatchingRules : check for a Normalizer, a Comparator and a Syntax
LOG.debug("Checking MatchingRules...");
for (MatchingRule matchingRule : matchingRuleRegistry) {
// Check that each MatchingRule has a Normalizer
if (matchingRule.getNormalizer() == null) {
LOG.debug("The MatchingRule {} has no Normalizer", matchingRule);
return false;
}
// Check that each MatchingRule has a Normalizer
if (!normalizerRegistry.contains(matchingRule.getNormalizer().getOid())) {
LOG.debug("Cannot find the Normalizer {} for the MatchingRule {}", matchingRule.getNormalizer().getOid(), matchingRule);
return false;
}
// Check that each MatchingRule has a Comparator
if (matchingRule.getLdapComparator() == null) {
LOG.debug("The MatchingRule {} has no Comparator", matchingRule);
return false;
}
if (!comparatorRegistry.contains(matchingRule.getLdapComparator().getOid())) {
LOG.debug("Cannot find the Comparator {} for the MatchingRule {}", matchingRule.getLdapComparator().getOid(), matchingRule);
return false;
}
// Check that each MatchingRule has a Syntax
if (matchingRule.getSyntax() == null) {
LOG.debug("The MatchingRule {} has no Syntax", matchingRule);
return false;
}
if (!ldapSyntaxRegistry.contains(matchingRule.getSyntax().getOid())) {
LOG.debug("Cannot find the Syntax {} for the MatchingRule {}", matchingRule.getSyntax().getOid(), matchingRule);
return false;
}
// Check the references : MR -> S and S -> MR
if (!checkReferences(matchingRule, matchingRule.getSyntax(), "Syntax")) {
return false;
}
// Check the references : MR -> N
if (!checkReferences(matchingRule, matchingRule.getNormalizer(), "Normalizer")) {
return false;
}
// Check the references : MR -> C and C -> MR
if (!checkReferences(matchingRule, matchingRule.getLdapComparator(), "Comparator")) {
return false;
}
}
// Check the ObjectClasses : check for MAY, MUST, SUPERIORS
LOG.debug("Checking ObjectClasses...");
for (ObjectClass objectClass : objectClassRegistry) {
// Check that each ObjectClass has all the MAY AttributeTypes
if (objectClass.getMayAttributeTypes() != null) {
for (AttributeType may : objectClass.getMayAttributeTypes()) {
if (!attributeTypeRegistry.contains(may.getOid())) {
LOG.debug("Cannot find the AttributeType {} for the ObjectClass {} MAY", may, objectClass);
return false;
}
// Check the references : OC -> AT and AT -> OC (MAY)
if (!checkReferences(objectClass, may, "AttributeType")) {
return false;
}
}
}
// Check that each ObjectClass has all the MUST AttributeTypes
if (objectClass.getMustAttributeTypes() != null) {
for (AttributeType must : objectClass.getMustAttributeTypes()) {
if (!attributeTypeRegistry.contains(must.getOid())) {
LOG.debug("Cannot find the AttributeType {} for the ObjectClass {} MUST", must, objectClass);
return false;
}
// Check the references : OC -> AT and AT -> OC (MUST)
if (!checkReferences(objectClass, must, "AttributeType")) {
return false;
}
}
}
// Check that each ObjectClass has all the SUPERIORS ObjectClasses
if (objectClass.getSuperiors() != null) {
for (ObjectClass superior : objectClass.getSuperiors()) {
if (!objectClassRegistry.contains(objectClass.getOid())) {
LOG.debug("Cannot find the ObjectClass {} for the ObjectClass {} SUPERIORS", superior, objectClass);
return false;
}
// Check the references : OC -> OC and OC -> OC (SUPERIORS)
if (!checkReferences(objectClass, superior, "ObjectClass")) {
return false;
}
}
}
}
// Check the AttributeTypes : check for MatchingRules, Syntaxes
LOG.debug("Checking AttributeTypes...");
for (AttributeType attributeType : attributeTypeRegistry) {
// Check that each AttributeType has a SYNTAX
if (attributeType.getSyntax() == null) {
LOG.debug("The AttributeType {} has no Syntax", attributeType);
return false;
}
if (!ldapSyntaxRegistry.contains(attributeType.getSyntax().getOid())) {
LOG.debug("Cannot find the Syntax {} for the AttributeType {}", attributeType.getSyntax().getOid(), attributeType);
return false;
}
// Check the references for AT -> S and S -> AT
if (!checkReferences(attributeType, attributeType.getSyntax(), "AttributeType")) {
return false;
}
// Check the EQUALITY MatchingRule
if (attributeType.getEquality() != null) {
if (!matchingRuleRegistry.contains(attributeType.getEquality().getOid())) {
LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getEquality().getOid(), attributeType);
return false;
}
// Check the references for AT -> MR and MR -> AT
if (!checkReferences(attributeType, attributeType.getEquality(), "AttributeType")) {
return false;
}
}
// Check the ORDERING MatchingRule
if (attributeType.getOrdering() != null) {
if (!matchingRuleRegistry.contains(attributeType.getOrdering().getOid())) {
LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getOrdering().getOid(), attributeType);
return false;
}
// Check the references for AT -> MR and MR -> AT
if (!checkReferences(attributeType, attributeType.getOrdering(), "AttributeType")) {
return false;
}
}
// Check the SUBSTR MatchingRule
if (attributeType.getSubstring() != null) {
if (!matchingRuleRegistry.contains(attributeType.getSubstring().getOid())) {
LOG.debug("Cannot find the MatchingRule {} for the AttributeType {}", attributeType.getSubstring().getOid(), attributeType);
return false;
}
// Check the references for AT -> MR and MR -> AT
if (!checkReferences(attributeType, attributeType.getSubstring(), "AttributeType")) {
return false;
}
}
// Check the SUP
if (attributeType.getSuperior() != null) {
AttributeType superior = attributeType.getSuperior();
if (!attributeTypeRegistry.contains(superior.getOid())) {
LOG.debug("Cannot find the AttributeType {} for the AttributeType {} SUPERIOR", superior, attributeType);
return false;
}
// Check the references : AT -> AT and AT -> AT (SUPERIOR)
if (!checkReferences(attributeType, superior, "AttributeType")) {
return false;
}
}
}
return true;
}
use of org.apache.directory.api.ldap.model.schema.AttributeType 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.schema.AttributeType 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;
}
}
use of org.apache.directory.api.ldap.model.schema.AttributeType in project directory-ldap-api by apache.
the class DefaultAttributeTypeRegistry method hasDescendants.
/**
* {@inheritDoc}
*/
@Override
public boolean hasDescendants(String ancestorId) throws LdapException {
try {
String oid = getOidByName(ancestorId);
Set<AttributeType> descendants = oidToDescendantSet.get(oid);
return (descendants != null) && !descendants.isEmpty();
} catch (LdapException ne) {
throw new LdapNoSuchAttributeException(ne.getMessage(), ne);
}
}
Aggregations