Search in sources :

Example 1 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByAttributeType.

@Test
public void testDeleteExistingSyntaxUsedByAttributeType() throws Exception {
    // syntax 1.3.6.1.4.1.1466.115.121.1.15 is used by AT 1.3.6.1.1.4
    SchemaManager schemaManager = loadSchema("system");
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    LdapSyntax syntax = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.15");
    assertFalse(schemaManager.delete(syntax));
    assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 2 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByRemovedAttributeType.

/**
 * Check that a Syntax which has been used by a deleted AttributeType
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedAttributeType() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String AT_OID = "1.3.6.1.4.1.1466.101.120.16";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.54";
    // Check that the AT and S are present
    assertTrue(isAttributeTypePresent(schemaManager, AT_OID));
    assertTrue(isSyntaxPresent(schemaManager, S_OID));
    // Now try to remove the S
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry(S_OID);
    // shouldn't be deleted cause there is a AT associated with it
    assertFalse(schemaManager.delete(syntax));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using AT : it should be OK
    MutableAttributeType at = new MutableAttributeType(AT_OID);
    assertTrue(schemaManager.delete(at));
    assertEquals(atrSize - 1, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isAttributeTypePresent(schemaManager, AT_OID));
    // and try to delete the syntax again
    assertTrue(schemaManager.delete(syntax));
    assertFalse(isSyntaxPresent(schemaManager, S_OID));
    assertEquals(srSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 2, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) Test(org.junit.Test)

Example 3 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByRemovedMatchingRule.

/**
 * Check that a Syntax which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String MR_OID = "2.5.13.11";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.41";
    // Check that the MR and S are present
    assertTrue(isMatchingRulePresent(schemaManager, MR_OID));
    assertTrue(isSyntaxPresent(schemaManager, S_OID));
    // Now try to remove the S
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry(S_OID);
    // shouldn't be deleted cause there is a MR associated with it
    assertFalse(schemaManager.delete(syntax));
    List<Throwable> errors = schemaManager.getErrors();
    assertFalse(errors.isEmpty());
    assertTrue(errors.get(0) instanceof LdapProtocolErrorException);
    // Now delete the using MR : it should be OK
    MatchingRule mr = new MatchingRule(MR_OID);
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isMatchingRulePresent(schemaManager, MR_OID));
    // and try to delete the syntax again
    assertTrue(schemaManager.delete(syntax));
    assertFalse(isSyntaxPresent(schemaManager, S_OID));
    assertEquals(srSize - 1, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize - 2, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) Test(org.junit.Test)

Example 4 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax in project directory-ldap-api by apache.

the class SchemaManagerDelTest method testDeleteExistingSyntaxUsedByMatchingRule.

@Test
public void testDeleteExistingSyntaxUsedByMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    // 1.3.6.1.4.1.1466.115.121.1.26 is used by MR 1.3.6.1.4.1.1466.109.114.2
    LdapSyntax syntax = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.26");
    assertFalse(schemaManager.delete(syntax));
    // syntax 1.3.6.1.4.1.1466.115.121.1.12 is used by MR 2.5.13.1 and many AT
    syntax = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.12");
    assertFalse(schemaManager.delete(syntax));
    assertEquals(sSize, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 5 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax 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)

Aggregations

LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)34 Test (org.junit.Test)12 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)10 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)9 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)9 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)4 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)4 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)4 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)3 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2