Search in sources :

Example 16 with LdapUnwillingToPerformException

use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.

the class Registries method dissociateFromSchema.

/**
 * Store the given SchemaObject in the Map associating SchemaObjetcs to their
 * related Schema.
 *
 * @param errors The list that collect errors
 * @param schemaObject The schemaObject to register
 * @throws LdapException If there is a problem
 */
public void dissociateFromSchema(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
    LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is already registered
    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);
        Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
        errors.add(error);
        return;
    }
    // Get a normalized form of schema name
    String schemaName = getSchemaName(schemaObject);
    String oid = schemaObject.getOid();
    // And unregister the schemaObject from its schema
    Set<SchemaObjectWrapper> content = schemaObjects.get(schemaName);
    SchemaObjectWrapper schemaObjectWrapper = new SchemaObjectWrapper(schemaObject);
    if (!content.contains(schemaObjectWrapper)) {
        // Not present !
        // What should we do ?
        LOG.info("Unregistering of {}:{} failed, is not present in the Registries", schemaObject.getObjectType(), schemaObject.getOid());
    } else {
        // Remove the association
        content.remove(schemaObjectWrapper);
        // an instance of LoadableSchemaObject
        if (!(schemaObject instanceof LoadableSchemaObject)) {
            try {
                globalOidRegistry.unregister(oid);
            } catch (LdapException ne) {
                errors.add(ne);
                return;
            }
        }
        LOG.debug("Unregistered {} for OID {}", schemaObject.getName(), schemaObject.getOid());
    }
}
Also used : LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 17 with LdapUnwillingToPerformException

use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.

the class SchemaManagerLoadTest method testLoadWrongSchema.

/**
 * Test loading a wrong schema
 */
@Test
public void testLoadWrongSchema() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    assertTrue(schemaManager.load("system"));
    try {
        schemaManager.loadWithDeps("bad");
        fail();
    } catch (LdapUnwillingToPerformException lonse) {
    // expected
    }
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(38, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(35, schemaManager.getComparatorRegistry().size());
    assertEquals(35, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(35, schemaManager.getNormalizerRegistry().size());
    assertEquals(9, schemaManager.getObjectClassRegistry().size());
    assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(59, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(141, schemaManager.getGlobalOidRegistry().size());
    assertEquals(1, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("bad"));
}
Also used : LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 18 with LdapUnwillingToPerformException

use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.

the class DefaultSchemaManager method toArray.

/**
 * Transform a String[] array of schema to a Schema[]
 */
private Schema[] toArray(String... schemas) throws LdapException {
    Schema[] schemaArray = new Schema[schemas.length];
    int n = 0;
    for (String schemaName : schemas) {
        Schema schema = schemaMap.get(schemaName);
        if (schema != null) {
            schemaArray[n++] = schema;
        } else {
            throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err(I18n.ERR_11001, schemaName));
        }
    }
    return schemaArray;
}
Also used : LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 19 with LdapUnwillingToPerformException

use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.

the class DefaultSchemaManager method copy.

private SchemaObject copy(SchemaObject schemaObject) {
    SchemaObject copy = null;
    if (!(schemaObject instanceof LoadableSchemaObject)) {
        copy = schemaObject.copy();
    } else {
        // Check the schemaObject here.
        if (((LoadableSchemaObject) schemaObject).isValid()) {
            copy = schemaObject;
        } else {
            // We have an invalid SchemaObject, no need to go any further
            Throwable error = new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err(I18n.ERR_11007, schemaObject.getOid()));
            errors.add(error);
        }
    }
    return copy;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)

Example 20 with LdapUnwillingToPerformException

use of org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException in project directory-ldap-api by apache.

the class SchemaEntityFactory method getMatchingRule.

/**
 * {@inheritDoc}
 * @throws LdapInvalidAttributeValueException If the MatchingRule does not exist
 * @throws LdapUnwillingToPerformException If the schema is not loaded
 */
@Override
public MatchingRule getMatchingRule(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapUnwillingToPerformException, LdapInvalidAttributeValueException {
    checkEntry(entry, SchemaConstants.MATCHING_RULE);
    // The MatchingRule OID
    String oid = getOid(entry, SchemaConstants.MATCHING_RULE, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested MatchingRule
        String msg = I18n.err(I18n.ERR_16028_CANNOT_ADD_MR, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16029_CANNOT_ADD_MR_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    MutableMatchingRule matchingRule = new MutableMatchingRule(oid);
    // The syntax field
    Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
    if (mSyntax != null) {
        matchingRule.setSyntaxOid(mSyntax.getString());
    }
    // The normalizer and comparator fields will be updated when we will
    // apply the registry
    // Common properties
    setSchemaObjectProperties(matchingRule, entry, schema);
    return matchingRule;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Aggregations

LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)21 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)11 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)4 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)4 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)4 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)4 Test (org.junit.Test)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)3 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)3 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 CommunicationException (javax.naming.CommunicationException)1