Search in sources :

Example 1 with MatchingRuleUse

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

the class DefaultSchemaLoader method loadMatchingRuleUses.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRuleUses(Schema... schemas) throws LdapException, IOException {
    List<Entry> matchingRuleUseEntries = new ArrayList<>();
    if (schemas == null) {
        return matchingRuleUseEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof MatchingRuleUse) {
                MatchingRuleUse matchingRuleUse = (MatchingRuleUse) schemaObject;
                Entry matchingRuleUseEntry = factory.convert(matchingRuleUse, schema, null);
                matchingRuleUseEntries.add(matchingRuleUseEntry);
            }
        }
    }
    return matchingRuleUseEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 2 with MatchingRuleUse

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

the class DefaultSchemaLoader method loadMatchingRuleUses.

private void loadMatchingRuleUses(Attribute matchingRuleUses) throws LdapException {
    if (matchingRuleUses == null) {
        return;
    }
    for (Value value : matchingRuleUses) {
        String desc = value.getValue();
        try {
            MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parseMatchingRuleUseDescription(desc);
            updateSchemas(matchingRuleUse);
        } catch (ParseException pe) {
            throw new LdapException(pe);
        }
    }
}
Also used : MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) Value(org.apache.directory.api.ldap.model.entry.Value) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 3 with MatchingRuleUse

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

the class Registries method unregister.

/**
 * Unregister a SchemaObject from the registries
 *
 * @param schemaObject The SchemaObject we want to deregister
 * @throws LdapException If the removal failed
 */
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
    LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is present in the registries
    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);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    SchemaObject unregistered;
    // First call the specific registry's register method
    switch(schemaObject.getObjectType()) {
        case ATTRIBUTE_TYPE:
            unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
            break;
        case COMPARATOR:
            unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
            break;
        case DIT_CONTENT_RULE:
            unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
            break;
        case DIT_STRUCTURE_RULE:
            unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
            break;
        case LDAP_SYNTAX:
            unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
            break;
        case MATCHING_RULE:
            unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
            break;
        case MATCHING_RULE_USE:
            unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
            break;
        case NAME_FORM:
            unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
            break;
        case NORMALIZER:
            unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
            break;
        case OBJECT_CLASS:
            unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
            break;
        case SYNTAX_CHECKER:
            unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
            break;
        default:
            throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
    }
    return unregistered;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 4 with MatchingRuleUse

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

the class MatchingRuleUseDescriptionSchemaParserTest method testApplies.

@Test
public void testApplies() throws ParseException {
    String value = null;
    MatchingRuleUse matchingRuleUse = null;
    // APPLIES simple numericoid
    value = "( 1.1 APPLIES 1.2.3.4.5.6.7.8.9.0 )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("1.2.3.4.5.6.7.8.9.0", matchingRuleUse.getApplicableAttributeOids().get(0));
    // SUP simple descr
    value = "( 1.1 APPLIES abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", matchingRuleUse.getApplicableAttributeOids().get(0));
    // APPLIES single numericoid
    value = "( 1.1 APPLIES ( 123.4567.890 ) )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("123.4567.890", matchingRuleUse.getApplicableAttributeOids().get(0));
    // APPLIES single descr
    value = "(1.1 APPLIES(a-z-A-Z-0-9))";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("a-z-A-Z-0-9", matchingRuleUse.getApplicableAttributeOids().get(0));
    // APPLIES multi numericoid
    value = "( 1.1 APPLIES ( 1.2.3 $ 4.5.6 $ 7.8.90 ) )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(3, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("1.2.3", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("4.5.6", matchingRuleUse.getApplicableAttributeOids().get(1));
    assertEquals("7.8.90", matchingRuleUse.getApplicableAttributeOids().get(2));
    // APPLIES multi descr
    value = "( 1.1 APPLIES ( test1 $ test2 ) )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(2, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("test1", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("test2", matchingRuleUse.getApplicableAttributeOids().get(1));
    // APPLIES multi mixed, tabs
    value = "\t(\t1.1\tAPPLIES\t(\ttest1\t$\t1.2.3.4\t$\ttest2\t)\t)\t";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(3, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("test1", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get(1));
    assertEquals("test2", matchingRuleUse.getApplicableAttributeOids().get(2));
    // APPLIES multi mixed no space
    value = "(1.1 APPLIES(TEST-1$1.2.3.4$TEST-2))";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(3, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("TEST-1", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get(1));
    assertEquals("TEST-2", matchingRuleUse.getApplicableAttributeOids().get(2));
    // APPLIES multi mixed many spaces
    value = "(          1.1          APPLIES          (          test1          $          1.2.3.4$test2          )          )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(3, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("test1", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get(1));
    assertEquals("test2", matchingRuleUse.getApplicableAttributeOids().get(2));
    // quoted value
    value = "( 1.1 APPLIES 'test' )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("test", matchingRuleUse.getApplicableAttributeOids().get(0));
    // quoted value
    value = "( 1.1 APPLIES '1.2.3.4' )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(1, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get(0));
    // no $ separator
    value = "( 1.1 APPLIES ( test1 test2 ) )";
    matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals(2, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("test1", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("test2", matchingRuleUse.getApplicableAttributeOids().get(1));
    // invalid character
    value = "( 1.1 APPLIES 1.2.3.4.A )";
    try {
        matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
        fail("Exception expected, invalid APPLIES '1.2.3.4.A' (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // empty APPLIES
    value = "( 1.1 APPLIES )";
    try {
        matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
        fail("Exception expected, no APPLIES value");
    } catch (ParseException pe) {
    // expected
    }
    // APPLIES must only appear once
    value = "( 1.1 APPLIES test1 APPLIES test2 )";
    try {
        matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
        fail("Exception expected, APPLIES appears twice");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // APPLIES is required
        value = "( 1.1 )";
        try {
            matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
            fail("Exception expected, APPLIES is required");
        } catch (ParseException pe) {
        // expected
        }
        // invalid start
        value = "( 1.1 APPLIES ( test1 $ -test2 ) )";
        try {
            matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
            fail("Exception expected, invalid APPLIES '-test' (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 5 with MatchingRuleUse

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

the class MatchingRuleUseDescriptionSchemaParserTest method testOpenldap1.

// //////////////////////////////////////////////////////////////
// Some real-world matching rule use descriptons        //
// //////////////////////////////////////////////////////////////
@Test
public void testOpenldap1() throws ParseException {
    String value = "( 2.5.13.17 NAME 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) )";
    MatchingRuleUse matchingRuleUse = parser.parseMatchingRuleUseDescription(value);
    assertEquals("2.5.13.17", matchingRuleUse.getOid());
    assertEquals(1, matchingRuleUse.getNames().size());
    assertEquals("octetStringMatch", matchingRuleUse.getNames().get(0));
    assertNull(matchingRuleUse.getDescription());
    assertFalse(matchingRuleUse.isObsolete());
    assertEquals(2, matchingRuleUse.getApplicableAttributeOids().size());
    assertEquals("javaSerializedData", matchingRuleUse.getApplicableAttributeOids().get(0));
    assertEquals("userPassword", matchingRuleUse.getApplicableAttributeOids().get(1));
    assertEquals(0, matchingRuleUse.getExtensions().size());
}
Also used : MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) Test(org.junit.Test)

Aggregations

MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)8 Test (org.junit.Test)4 ParseException (java.text.ParseException)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 NameForm (org.apache.directory.api.ldap.model.schema.NameForm)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1