Search in sources :

Example 1 with DitContentRule

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

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

the class DitContentRuleDescriptionSchemaParserTest method testMay.

/**
 * Test MAY and its values.
 * Very similar to AUX, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testMay() throws ParseException {
    String value = null;
    DitContentRule ditContentRule = null;
    // no MAY
    value = "( 1.1 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(0, ditContentRule.getMayAttributeTypeOids().size());
    // MAY simple numericoid
    value = "( 1.1 MAY 1.2.3 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getMayAttributeTypeOids().size());
    assertEquals("1.2.3", ditContentRule.getMayAttributeTypeOids().get(0));
    // MAY mulitple
    value = "(1.1 MAY (cn$sn       $11.22.33.44.55         $  objectClass   ))";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(4, ditContentRule.getMayAttributeTypeOids().size());
    assertEquals("cn", ditContentRule.getMayAttributeTypeOids().get(0));
    assertEquals("sn", ditContentRule.getMayAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", ditContentRule.getMayAttributeTypeOids().get(2));
    assertEquals("objectClass", ditContentRule.getMayAttributeTypeOids().get(3));
    if (!parser.isQuirksMode()) {
        // invalid value
        value = "( 1.1 MAY ( c_n ) )";
        try {
            ditContentRule = parser.parseDITContentRuleDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 3 with DitContentRule

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

the class DitContentRuleDescriptionSchemaParserTest method testAux.

/**
 * Test AUX and its values.
 *
 * @throws ParseException
 */
@Test
public void testAux() throws ParseException {
    String value = null;
    DitContentRule ditContentRule = null;
    // no AUX
    value = "( 1.1 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(0, ditContentRule.getAuxObjectClassOids().size());
    // AUX simple numericoid
    value = "( 1.1 AUX 1.2.3 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("1.2.3", ditContentRule.getAuxObjectClassOids().get(0));
    // AUX simple descr
    value = "( 1.1 AUX top )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top", ditContentRule.getAuxObjectClassOids().get(0));
    // AUX single numericoid
    value = "( 1.1 AUX ( 1.2.3.4.5 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("1.2.3.4.5", ditContentRule.getAuxObjectClassOids().get(0));
    // AUX single descr
    value = "( 1.1 AUX ( A-Z-0-9 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("A-Z-0-9", ditContentRule.getAuxObjectClassOids().get(0));
    // AUX multi numericoid
    value = "( 1.1 AUX ( 1.2.3 $ 1.2.3.4.5 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(2, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("1.2.3", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("1.2.3.4.5", ditContentRule.getAuxObjectClassOids().get(1));
    // AUX multi descr
    value = "( 1.1 AUX ( top1 $ top2 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(2, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top1", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("top2", ditContentRule.getAuxObjectClassOids().get(1));
    // AUX multi mixed
    value = "( 1.1 AUX ( top1 $ 1.2.3.4 $ top2 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(3, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top1", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("1.2.3.4", ditContentRule.getAuxObjectClassOids().get(1));
    assertEquals("top2", ditContentRule.getAuxObjectClassOids().get(2));
    // AUX multi mixed no space
    value = "(1.1 AUX(TOP-1$1.2.3.4$TOP-2))";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(3, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("TOP-1", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("1.2.3.4", ditContentRule.getAuxObjectClassOids().get(1));
    assertEquals("TOP-2", ditContentRule.getAuxObjectClassOids().get(2));
    // AUX multi mixed many spaces
    value = "(          1.1          AUX          (          top1          $          1.2.3.4$top2          )          )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(3, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top1", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("1.2.3.4", ditContentRule.getAuxObjectClassOids().get(1));
    assertEquals("top2", ditContentRule.getAuxObjectClassOids().get(2));
    // no quote allowed
    value = "( 1.1 AUX 'top' )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top", ditContentRule.getAuxObjectClassOids().get(0));
    // quoted value
    value = "( 1.1 AUX '1.2.3.4' )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("1.2.3.4", ditContentRule.getAuxObjectClassOids().get(0));
    // no $ separator
    value = "( 1.1 AUX ( top1 top2 ) )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(2, ditContentRule.getAuxObjectClassOids().size());
    assertEquals("top1", ditContentRule.getAuxObjectClassOids().get(0));
    assertEquals("top2", ditContentRule.getAuxObjectClassOids().get(1));
    // invalid character
    value = "( 1.1 AUX 1.2.3.4.A )";
    try {
        ditContentRule = parser.parseDITContentRuleDescription(value);
        fail("Exception expected, invalid AUX '1.2.3.4.A' (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // empty AUX
    value = "( 1.1 AUX )";
    try {
        ditContentRule = parser.parseDITContentRuleDescription(value);
        fail("Exception expected, no AUX value");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // invalid start
        value = "( 1.1 AUX ( top1 $ -top2 ) )";
        try {
            ditContentRule = parser.parseDITContentRuleDescription(value);
            fail("Exception expected, invalid AUX '-top' (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 4 with DitContentRule

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

the class Registries method clone.

/**
 * Clone the Registries. This is done in two steps :
 * - first clone the SchemaObjetc registries
 * - second restore the relation between them
 */
// False positive
@Override
public Registries clone() throws CloneNotSupportedException {
    // First clone the structure
    Registries clone = (Registries) super.clone();
    // Now, clone the oidRegistry
    clone.globalOidRegistry = globalOidRegistry.copy();
    // We have to clone every SchemaObject registries now
    clone.attributeTypeRegistry = attributeTypeRegistry.copy();
    clone.comparatorRegistry = comparatorRegistry.copy();
    clone.ditContentRuleRegistry = ditContentRuleRegistry.copy();
    clone.ditStructureRuleRegistry = ditStructureRuleRegistry.copy();
    clone.ldapSyntaxRegistry = ldapSyntaxRegistry.copy();
    clone.matchingRuleRegistry = matchingRuleRegistry.copy();
    clone.matchingRuleUseRegistry = matchingRuleUseRegistry.copy();
    clone.nameFormRegistry = nameFormRegistry.copy();
    clone.normalizerRegistry = normalizerRegistry.copy();
    clone.objectClassRegistry = objectClassRegistry.copy();
    clone.syntaxCheckerRegistry = syntaxCheckerRegistry.copy();
    // Store all the SchemaObjects into the globalOid registry
    for (AttributeType attributeType : clone.attributeTypeRegistry) {
        clone.globalOidRegistry.put(attributeType);
    }
    for (DitContentRule ditContentRule : clone.ditContentRuleRegistry) {
        clone.globalOidRegistry.put(ditContentRule);
    }
    for (DitStructureRule ditStructureRule : clone.ditStructureRuleRegistry) {
        clone.globalOidRegistry.put(ditStructureRule);
    }
    for (MatchingRule matchingRule : clone.matchingRuleRegistry) {
        clone.globalOidRegistry.put(matchingRule);
    }
    for (MatchingRuleUse matchingRuleUse : clone.matchingRuleUseRegistry) {
        clone.globalOidRegistry.put(matchingRuleUse);
    }
    for (NameForm nameForm : clone.nameFormRegistry) {
        clone.globalOidRegistry.put(nameForm);
    }
    for (ObjectClass objectClass : clone.objectClassRegistry) {
        clone.globalOidRegistry.put(objectClass);
    }
    for (LdapSyntax syntax : clone.ldapSyntaxRegistry) {
        clone.globalOidRegistry.put(syntax);
    }
    // Clone the schema list
    clone.loadedSchemas = new HashMap<>();
    for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
        // We don't clone the schemas
        clone.loadedSchemas.put(entry.getKey(), loadedSchemas.get(entry.getKey()));
    }
    // Clone the Using and usedBy structures
    // They will be empty
    clone.using = new HashMap<>();
    clone.usedBy = new HashMap<>();
    // Last, rebuild the using and usedBy references
    clone.buildReferences();
    // Now, check the registries. We don't care about errors
    clone.checkRefInteg();
    clone.schemaObjects = new HashMap<>();
    // SchemaObjects
    for (Map.Entry<String, Set<SchemaObjectWrapper>> entry : schemaObjects.entrySet()) {
        Set<SchemaObjectWrapper> objects = new HashSet<>();
        for (SchemaObjectWrapper schemaObjectWrapper : entry.getValue()) {
            SchemaObject original = schemaObjectWrapper.get();
            try {
                if (!(original instanceof LoadableSchemaObject)) {
                    SchemaObject copy = clone.globalOidRegistry.getSchemaObject(original.getOid());
                    SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(copy);
                    objects.add(newWrapper);
                } else {
                    SchemaObjectWrapper newWrapper = new SchemaObjectWrapper(original);
                    objects.add(newWrapper);
                }
            } catch (LdapException ne) {
            // Nothing to do
            }
        }
        clone.schemaObjects.put(entry.getKey(), objects);
    }
    return clone;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) HashSet(java.util.HashSet) Set(java.util.Set) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper) 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) HashMap(java.util.HashMap) Map(java.util.Map) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) HashSet(java.util.HashSet)

Example 5 with DitContentRule

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

the class DitContentRuleDescriptionSchemaParserTest method testNot.

/**
 * Test NOT and its values.
 * Very similar to AUX, so here are less test cases.
 *
 * @throws ParseException
 */
@Test
public void testNot() throws ParseException {
    String value = null;
    DitContentRule ditContentRule = null;
    // no NOT
    value = "( 1.1 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(0, ditContentRule.getNotAttributeTypeOids().size());
    // NOT simple numericoid
    value = "( 1.1 NOT 1.2.3 )";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(1, ditContentRule.getNotAttributeTypeOids().size());
    assertEquals("1.2.3", ditContentRule.getNotAttributeTypeOids().get(0));
    // NOT mulitple
    value = "(1.1 NOT (cn\nsn\t$11.22.33.44.55         $  objectClass   ))";
    ditContentRule = parser.parseDITContentRuleDescription(value);
    assertEquals(4, ditContentRule.getNotAttributeTypeOids().size());
    assertEquals("cn", ditContentRule.getNotAttributeTypeOids().get(0));
    assertEquals("sn", ditContentRule.getNotAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", ditContentRule.getNotAttributeTypeOids().get(2));
    assertEquals("objectClass", ditContentRule.getNotAttributeTypeOids().get(3));
    if (!parser.isQuirksMode()) {
        // invalid value
        value = "( 1.1 NOT ( c_n ) )";
        try {
            ditContentRule = parser.parseDITContentRuleDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)9 ParseException (java.text.ParseException)5 Test (org.junit.Test)5 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 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 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)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