Search in sources :

Example 1 with LdapUnwillingToPerformException

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

the class SchemaManagerLoadTest 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);
    assertTrue(schemaManager.load("system"));
    try {
        assertFalse(schemaManager.load("core", "bad", "cosine", "InetOrgPerson"));
        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("core"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
    assertNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
}
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 2 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getSyntaxChecker.

/**
 * {@inheritDoc}
 */
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, SyntaxCheckerDescription syntaxCheckerDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // The Comparator OID
    String oid = getOid(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested SyntaxChecker
        String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, syntaxCheckerDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // get the byteCode
    Attribute byteCode = getByteCode(syntaxCheckerDescription, SchemaConstants.SYNTAX_CHECKER);
    // Class load the SyntaxChecker
    SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(syntaxChecker, syntaxCheckerDescription, schema);
    return syntaxChecker;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) 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 3 with LdapUnwillingToPerformException

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

the class SchemaEntityFactory method getAttributeType.

/**
 * {@inheritDoc}
 * @throws LdapInvalidAttributeValueException If the AttributeType does not exist
 * @throws LdapUnwillingToPerformException If the schema is not loaded
 */
@Override
public AttributeType getAttributeType(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapInvalidAttributeValueException, LdapUnwillingToPerformException {
    checkEntry(entry, SchemaConstants.ATTRIBUTE_TYPE);
    // The AttributeType OID
    String oid = getOid(entry, SchemaConstants.ATTRIBUTE_TYPE, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded, this is an error
        String msg = I18n.err(I18n.ERR_16032_CANNOT_ADD_AT, 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_16033_CANNOT_ADD_AT_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // Create the new AttributeType
    MutableAttributeType attributeType = new MutableAttributeType(oid);
    if (schemaManager.isRelaxed()) {
        attributeType.setRelaxed(true);
    }
    // Syntax
    Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
    if ((mSyntax != null) && (mSyntax.get() != null)) {
        attributeType.setSyntaxOid(mSyntax.getString());
    }
    // Syntax Length
    Attribute mSyntaxLength = entry.get(MetaSchemaConstants.M_LENGTH_AT);
    if (mSyntaxLength != null) {
        attributeType.setSyntaxLength(Integer.parseInt(mSyntaxLength.getString()));
    }
    // Equality
    Attribute mEquality = entry.get(MetaSchemaConstants.M_EQUALITY_AT);
    if (mEquality != null) {
        attributeType.setEqualityOid(mEquality.getString());
    }
    // Ordering
    Attribute mOrdering = entry.get(MetaSchemaConstants.M_ORDERING_AT);
    if (mOrdering != null) {
        attributeType.setOrderingOid(mOrdering.getString());
    }
    // Substr
    Attribute mSubstr = entry.get(MetaSchemaConstants.M_SUBSTR_AT);
    if (mSubstr != null) {
        attributeType.setSubstringOid(mSubstr.getString());
    }
    Attribute mSupAttributeType = entry.get(MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT);
    // Sup
    if (mSupAttributeType != null) {
        attributeType.setSuperiorOid(mSupAttributeType.getString());
    }
    // isCollective
    Attribute mCollective = entry.get(MetaSchemaConstants.M_COLLECTIVE_AT);
    if (mCollective != null) {
        String val = mCollective.getString();
        attributeType.setCollective("TRUE".equalsIgnoreCase(val));
    }
    // isSingleValued
    Attribute mSingleValued = entry.get(MetaSchemaConstants.M_SINGLE_VALUE_AT);
    if (mSingleValued != null) {
        String val = mSingleValued.getString();
        attributeType.setSingleValued("TRUE".equalsIgnoreCase(val));
    }
    // isReadOnly
    Attribute mNoUserModification = entry.get(MetaSchemaConstants.M_NO_USER_MODIFICATION_AT);
    if (mNoUserModification != null) {
        String val = mNoUserModification.getString();
        attributeType.setUserModifiable(!"TRUE".equalsIgnoreCase(val));
    }
    // Usage
    Attribute mUsage = entry.get(MetaSchemaConstants.M_USAGE_AT);
    if (mUsage != null) {
        attributeType.setUsage(UsageEnum.getUsage(mUsage.getString()));
    }
    // Common properties
    setSchemaObjectProperties(attributeType, entry, schema);
    return attributeType;
}
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) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Example 4 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, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.COMPARATOR);
    // The Comparator OID
    String oid = getOid(entry, SchemaConstants.COMPARATOR, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Comparator
        String msg = I18n.err(I18n.ERR_16022_CANNOT_ADD_CMP, 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_16023_CANNOT_ADD_CMP_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // The FQCN
    String fqcn = getFqcn(entry, SchemaConstants.COMPARATOR);
    // The ByteCode
    Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
    try {
        // Class load the comparator
        LdapComparator<?> comparator = classLoadComparator(schemaManager, oid, fqcn, byteCode);
        // Update the common fields
        setSchemaObjectProperties(comparator, entry, schema);
        // return the resulting comparator
        return comparator;
    } 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) 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 5 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, NormalizerDescription normalizerDescription, Registries targetRegistries, String schemaName) throws LdapException {
    checkDescription(normalizerDescription, SchemaConstants.NORMALIZER);
    // The Comparator OID
    String oid = getOid(normalizerDescription, SchemaConstants.NORMALIZER);
    // Get the schema
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is not loaded. We can't create the requested Normalizer
        String msg = I18n.err(I18n.ERR_16024_CANNOT_ADD_NORMALIZER, normalizerDescription.getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    // The FQCN
    String fqcn = getFqcn(normalizerDescription, SchemaConstants.NORMALIZER);
    // get the byteCode
    Attribute byteCode = getByteCode(normalizerDescription, SchemaConstants.NORMALIZER);
    // Class load the normalizer
    Normalizer normalizer = classLoadNormalizer(schemaManager, oid, fqcn, byteCode);
    // Update the common fields
    setSchemaObjectProperties(normalizer, normalizerDescription, schema);
    return normalizer;
}
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)

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