Search in sources :

Example 6 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getSyntax.

/**
 * {@inheritDoc}
 * @throws LdapInvalidAttributeValueException If the Syntax does not exist
 * @throws LdapUnwillingToPerformException If the schema is not loaded
 */
@Override
public LdapSyntax getSyntax(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapInvalidAttributeValueException, LdapUnwillingToPerformException {
    checkEntry(entry, SchemaConstants.SYNTAX);
    // The Syntax OID
    String oid = getOid(entry, SchemaConstants.SYNTAX, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Syntax
        String msg = I18n.err(I18n.ERR_16026_CANNOT_ADD_SYNTAX, 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_16027_CANNOT_ADD_SYNTAX_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the new LdapSyntax instance
    LdapSyntax syntax = new LdapSyntax(oid);
    // Common properties
    setSchemaObjectProperties(syntax, entry, schema);
    return syntax;
}
Also used : 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) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax)

Example 7 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getNormalizer.

/**
 * {@inheritDoc}
 */
@Override
public Normalizer getNormalizer(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.NORMALIZER);
    // The Normalizer OID
    String oid = getOid(entry, SchemaConstants.NORMALIZER, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Normalizer
        String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, 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_16025_CANNOT_ADD_NORMALIZER_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // The FQCN
    String className = getFqcn(entry, SchemaConstants.NORMALIZER);
    // The ByteCode
    Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
    try {
        // Class load the Normalizer
        Normalizer normalizer = classLoadNormalizer(schemaManager, oid, className, byteCode);
        // Update the common fields
        setSchemaObjectProperties(normalizer, entry, schema);
        // return the resulting Normalizer
        return normalizer;
    } catch (Exception e) {
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
    }
}
Also used : 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) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 8 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getLdapComparator.

/**
 * {@inheritDoc}
 */
@Override
public LdapComparator<?> getLdapComparator(SchemaManager schemaManager, LdapComparatorDescription comparatorDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(comparatorDescription, SchemaConstants.COMPARATOR);
    // The Comparator OID
    String oid = getOid(comparatorDescription, SchemaConstants.COMPARATOR);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested Comparator
        String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, comparatorDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(comparatorDescription, SchemaConstants.COMPARATOR);
    // get the byteCode
    Attribute byteCode = getByteCode(comparatorDescription, SchemaConstants.COMPARATOR);
    // Class load the comparator
    LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(comparator, comparatorDescription, schema);
    return comparator;
}
Also used : 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)

Example 9 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getObjectClass.

/**
 * {@inheritDoc}
 */
@Override
public ObjectClass getObjectClass(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.OBJECT_CLASS);
    // The ObjectClass OID
    String oid = getOid(entry, SchemaConstants.OBJECT_CLASS, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested ObjectClass
        String msg = I18n.err(I18n.ERR_16030_CANNOT_ADD_OC, 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_16031_CANNOT_ADD_OC_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the ObjectClass instance
    MutableObjectClass oc = new MutableObjectClass(oid);
    // The Sup field
    Attribute mSuperiors = entry.get(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
    if (mSuperiors != null) {
        oc.setSuperiorOids(getStrings(mSuperiors));
    }
    // The May field
    Attribute mMay = entry.get(MetaSchemaConstants.M_MAY_AT);
    if (mMay != null) {
        oc.setMayAttributeTypeOids(getStrings(mMay));
    }
    // The Must field
    Attribute mMust = entry.get(MetaSchemaConstants.M_MUST_AT);
    if (mMust != null) {
        oc.setMustAttributeTypeOids(getStrings(mMust));
    }
    // The objectClassType field
    Attribute mTypeObjectClass = entry.get(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT);
    if (mTypeObjectClass != null) {
        String type = mTypeObjectClass.getString();
        oc.setType(ObjectClassTypeEnum.getClassType(type));
    }
    // Common properties
    setSchemaObjectProperties(oc, entry, schema);
    return oc;
}
Also used : 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) MutableObjectClass(org.apache.directory.api.ldap.model.schema.MutableObjectClass)

Example 10 with LdapUnwillingToPerformException

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

the class SchemaManagerLoadWithDepsTest method testLoadWrongSchema.

/**
 * Test loading a wrong schema
 */
@Test
public void testLoadWrongSchema() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    try {
        schemaManager.loadWithDeps("bad");
        fail();
    } catch (LdapUnwillingToPerformException lonse) {
    // expected
    }
    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());
}
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)

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