Search in sources :

Example 6 with Normalizer

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

the class SchemaManagerDelTest method testDeleteExistingNormalizerUsedByRemovedMatchingRule.

/**
 * Check that a Normalizer which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingNormalizerUsedByRemovedMatchingRule() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    String OID = "2.5.13.33";
    // Check that the MR and N are present
    assertTrue(isMatchingRulePresent(schemaManager, OID));
    assertTrue(isNormalizerPresent(schemaManager, OID));
    // Now try to remove the N
    Normalizer normalizer = schemaManager.lookupNormalizerRegistry(OID);
    // shouldn't be deleted cause there is a MR associated with it
    assertFalse(schemaManager.delete(normalizer));
    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(OID);
    assertTrue(schemaManager.delete(mr));
    assertEquals(mrrSize - 1, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
    assertFalse(isMatchingRulePresent(schemaManager, OID));
    // and try to delete the normalizer again
    assertTrue(schemaManager.delete(normalizer));
    assertFalse(isNormalizerPresent(schemaManager, OID));
    assertEquals(nrSize - 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize - 1, schemaManager.getGlobalOidRegistry().size());
}
Also used : LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) 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 7 with Normalizer

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

the class SchemaManagerDelTest method testDeleteExistingNormalizer.

// =========================================================================
// MatchingRuleUse deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// NameForm deletion tests
// -------------------------------------------------------------------------
// TODO
// =========================================================================
// Normalizer deletion tests
// -------------------------------------------------------------------------
@Test
public void testDeleteExistingNormalizer() throws Exception {
    SchemaManager schemaManager = loadSchema("system");
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();
    Normalizer nr = new BooleanNormalizer();
    nr.setOid("0.1.1");
    assertTrue(schemaManager.add(nr));
    assertEquals(nrSize + 1, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
    // FIXME this lookup is failing ! but it shouldn't be
    nr = schemaManager.lookupNormalizerRegistry("0.1.1");
    assertNotNull(nr);
    assertTrue(schemaManager.delete(nr));
    try {
        schemaManager.lookupNormalizerRegistry("0.1.1");
        fail();
    } catch (Exception e) {
    // expected
    }
    assertEquals(nrSize, schemaManager.getNormalizerRegistry().size());
    assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
Also used : BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) BooleanNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 8 with Normalizer

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

Example 9 with Normalizer

use of org.apache.directory.api.ldap.model.schema.Normalizer 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 10 with Normalizer

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

the class TestEntryUtils method getCaseIgnoringAttributeNoNumbersType.

/* no protection*/
static AttributeType getCaseIgnoringAttributeNoNumbersType() {
    MutableAttributeType attributeType = new MutableAttributeType("1.1.3.1");
    LdapSyntax syntax = new LdapSyntax("1.1.1.1", "", true);
    syntax.setSyntaxChecker(new SyntaxChecker("1.1.2.1") {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public boolean isValidSyntax(Object value) {
            if (!(value instanceof String)) {
                return false;
            }
            String strval = (String) value;
            for (char c : strval.toCharArray()) {
                if (Character.isDigit(c)) {
                    return false;
                }
            }
            return true;
        }
    });
    MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2.1");
    matchingRule.setSyntax(syntax);
    matchingRule.setLdapComparator(new LdapComparator<String>(matchingRule.getOid()) {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public int compare(String o1, String o2) {
            return (o1 == null ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2)));
        }
    });
    Normalizer normalizer = new Normalizer("1.1.1") {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            return Strings.toLowerCaseAscii(value);
        }
    };
    matchingRule.setNormalizer(normalizer);
    attributeType.setEquality(matchingRule);
    attributeType.setSyntax(syntax);
    return attributeType;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) AssertionType(org.apache.directory.api.ldap.model.schema.PrepareString.AssertionType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Aggregations

Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)78 Test (org.junit.Test)59 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)20 DeepTrimNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimNormalizer)15 TelephoneNumberNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.TelephoneNumberNormalizer)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)10 NumericNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NumericNormalizer)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)7 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)6 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)6 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)5 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)5 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)5 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)4 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)4 ByteArrayComparator (org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator)4 BooleanNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.BooleanNormalizer)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3