use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class SchemaManagerLoadWithDepsTest method testLoadCoreInetOrgPersonAndBad.
/**
* test loading the "InetOrgPerson", "core" and a bad schema
*/
@Test
public void testLoadCoreInetOrgPersonAndBad() throws Exception {
LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
SchemaManager schemaManager = new DefaultSchemaManager(loader);
try {
schemaManager.loadWithDeps("core", "bad", "InetOrgPerson");
fail();
} catch (LdapUnwillingToPerformException lonse) {
// expected
}
// No SchemaObject should be loaded as we had an error
assertTrue(schemaManager.getErrors().isEmpty());
assertEquals(0, schemaManager.getAttributeTypeRegistry().size());
assertEquals(0, schemaManager.getComparatorRegistry().size());
assertEquals(0, schemaManager.getMatchingRuleRegistry().size());
assertEquals(0, schemaManager.getNormalizerRegistry().size());
assertEquals(0, schemaManager.getObjectClassRegistry().size());
assertEquals(0, schemaManager.getSyntaxCheckerRegistry().size());
assertEquals(0, schemaManager.getLdapSyntaxRegistry().size());
assertEquals(0, schemaManager.getGlobalOidRegistry().size());
assertEquals(0, schemaManager.getRegistries().getLoadedSchemas().size());
assertNull(schemaManager.getRegistries().getLoadedSchema("system"));
assertNull(schemaManager.getRegistries().getLoadedSchema("core"));
assertNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
assertNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class Registries method associateWithSchema.
/**
* Store the given SchemaObject in the Map associating SchemaObjetcs to their
* related Schema.
*
* @param errors The list of errors we are accumulating while checking the schema
* @param schemaObject The schemaObject to register
*/
public void associateWithSchema(List<Throwable> errors, SchemaObject schemaObject) {
LOG.debug("Registering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
// Check that the SchemaObject is not already registered
if (!(schemaObject instanceof LoadableSchemaObject) && globalOidRegistry.contains(schemaObject.getOid())) {
String msg = I18n.err(I18n.ERR_13750_REGISTERING_FAILED_ALREADY_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
LOG.error(msg);
Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
errors.add(error);
return;
}
// Get a normalized form of schema name
String schemaName = getSchemaName(schemaObject);
// And register the schemaObject within its schema
Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
if (content == null) {
content = new HashSet<>();
schemaObjects.put(Strings.toLowerCaseAscii(schemaName), content);
}
SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
if (content.contains(schemaObjectWrapper)) {
// Already present !
// What should we do ?
LOG.info("Registering of {}:{} failed, is already present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
} else {
// Create the association
content.add(schemaObjectWrapper);
// an instance of LoadableSchemaObject
if (!(schemaObject instanceof LoadableSchemaObject)) {
try {
globalOidRegistry.register(schemaObject);
} catch (LdapException ne) {
errors.add(ne);
return;
}
}
LOG.debug("registered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException 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.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class WrappedPartialResultException method wrap.
/**
* Wraps a LDAP exception into a NaingException
*
* @param t The original exception
* @throws NamingException The wrapping JNDI exception
*/
public static void wrap(Throwable t) throws NamingException {
if (t instanceof NamingException) {
throw (NamingException) t;
}
NamingException ne;
if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
ne = new NamingException(t.getLocalizedMessage());
} else if (t instanceof LdapAttributeInUseException) {
ne = new AttributeInUseException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationException) {
ne = new AuthenticationException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationNotSupportedException) {
ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
} else if (t instanceof LdapContextNotEmptyException) {
ne = new ContextNotEmptyException(t.getLocalizedMessage());
} else if (t instanceof LdapEntryAlreadyExistsException) {
ne = new NameAlreadyBoundException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeTypeException) {
ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeValueException) {
ne = new InvalidAttributeValueException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidDnException) {
ne = new InvalidNameException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidSearchFilterException) {
ne = new InvalidSearchFilterException(t.getLocalizedMessage());
} else if (t instanceof LdapNoPermissionException) {
ne = new NoPermissionException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchAttributeException) {
ne = new NoSuchAttributeException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchObjectException) {
ne = new NameNotFoundException(t.getLocalizedMessage());
} else if (t instanceof LdapProtocolErrorException) {
ne = new CommunicationException(t.getLocalizedMessage());
} else if (t instanceof LdapReferralException) {
ne = new WrappedReferralException((LdapReferralException) t);
} else if (t instanceof LdapPartialResultException) {
ne = new WrappedPartialResultException((LdapPartialResultException) t);
} else if (t instanceof LdapSchemaViolationException) {
ne = new SchemaViolationException(t.getLocalizedMessage());
} else if (t instanceof LdapServiceUnavailableException) {
ne = new ServiceUnavailableException(t.getLocalizedMessage());
} else if (t instanceof LdapTimeLimitExceededException) {
ne = new TimeLimitExceededException(t.getLocalizedMessage());
} else if (t instanceof LdapUnwillingToPerformException) {
ne = new OperationNotSupportedException(t.getLocalizedMessage());
} else {
ne = new NamingException(t.getLocalizedMessage());
}
ne.setRootCause(t);
throw ne;
}
use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.
the class DnNode method add.
/**
* Add a new node in the tree. We can't add a node if its Dn is empty. The
* added element is attached to the node, which is named by the Dn's Rdn.<br>
*
* @param dn The node's Dn
* @param element The element to associate with this Node. Can be null.
* @return the corresponding node
* @throws LdapException if the Dn is null or empty
*/
public synchronized DnNode<N> add(Dn dn, N element) throws LdapException {
checkDn(dn);
// We first have to find the Node which will be the parent
DnNode<N> parentNode = getNode(dn);
if (parentNode == null) {
// No parent : add a new node to the root
DnNode<N> childNode = createNode(dn, element, dn.size());
childNode.parent = this;
children.put(childNode.nodeRdn.getNormName(), childNode);
return childNode;
} else {
// We have a parent. Add the new node to the found parent
int nbRdns = dn.size() - parentNode.depth;
if (nbRdns == 0) {
// That means the added Dn is already present. Check if it already has an element
if (parentNode.hasElement()) {
String message = "Cannot add a node to a node already having an element";
LOG.error(message);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, message);
} else // We may try to add twice the same Dn, without any element
if (element == null) {
String message = "Cannot add a node with no element if it already exists";
LOG.error(message);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, message);
} else // All is fine : we are just injecting some data into an existing node
{
parentNode.setElement(element);
return parentNode;
}
} else {
DnNode<N> childNode = createNode(dn, element, nbRdns);
// done. now, add the newly created tree to the parent node
childNode.parent = parentNode;
parentNode.children.put(childNode.nodeRdn.getNormName(), childNode);
return childNode;
}
}
}
Aggregations