Search in sources :

Example 16 with LdapSyntax

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

the class LdapSyntaxDescriptionSchemaParserTest method testSyntaxWithExtensions.

/**
 * Tests the parse of a simple AttributeType with the schema extension.
 */
@Test
public void testSyntaxWithExtensions() throws ParseException {
    String substrate = "( 1.3.6.1.4.1.18060.0.4.0.2.10000 DESC 'bogus description' X-SCHEMA 'blah' X-NOT-HUMAN-READABLE 'false' )";
    LdapSyntax ldapSyntax = parser.parseLdapSyntaxDescription(substrate);
    assertEquals("1.3.6.1.4.1.18060.0.4.0.2.10000", ldapSyntax.getOid());
    assertEquals("bogus description", ldapSyntax.getDescription());
    assertNotNull(ldapSyntax.getExtension("X-NOT-HUMAN-READABLE"));
    assertEquals(substrate, ldapSyntax.getSpecification());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Test(org.junit.Test)

Example 17 with LdapSyntax

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

the class LdapSyntaxDescriptionSchemaParserTest method testFull.

/**
 * Test full sytax description.
 *
 * @throws ParseException
 */
@Test
public void testFull() throws ParseException {
    String value = null;
    LdapSyntax ldapSyntax = null;
    value = "( 1.2.3.4.5.6.7.8.9.0 DESC 'Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577' X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
    ldapSyntax = parser.parseLdapSyntaxDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", ldapSyntax.getOid());
    assertEquals("Descripton \u00E4\u00F6\u00FC\u00DF \u90E8\u9577", ldapSyntax.getDescription());
    assertEquals(2, ldapSyntax.getExtensions().size());
    assertNotNull(ldapSyntax.getExtension("X-TEST-a"));
    assertEquals(2, ldapSyntax.getExtension("X-TEST-a").size());
    assertEquals("test1-1", ldapSyntax.getExtension("X-TEST-a").get(0));
    assertEquals("test1-2", ldapSyntax.getExtension("X-TEST-a").get(1));
    assertNotNull(ldapSyntax.getExtension("X-TEST-b"));
    assertEquals(2, ldapSyntax.getExtension("X-TEST-b").size());
    assertEquals("test2-1", ldapSyntax.getExtension("X-TEST-b").get(0));
    assertEquals("test2-2", ldapSyntax.getExtension("X-TEST-b").get(1));
    assertEquals(value, ldapSyntax.getSpecification());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Test(org.junit.Test)

Example 18 with LdapSyntax

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

the class LdapSyntaxDescriptionSchemaParserTest method testRfcBinary.

// //////////////////////////////////////////////////////////////
// Some real-world attribute type definitions         //
// //////////////////////////////////////////////////////////////
@Test
public void testRfcBinary() throws ParseException {
    String value = "( 1.3.6.1.4.1.1466.115.121.1.5 DESC 'Binary' X-NOT-HUMAN-READABLE 'TRUE' )";
    LdapSyntax ldapSyntax = parser.parseLdapSyntaxDescription(value);
    assertEquals("1.3.6.1.4.1.1466.115.121.1.5", ldapSyntax.getOid());
    assertEquals("Binary", ldapSyntax.getDescription());
    assertEquals(1, ldapSyntax.getExtensions().size());
    assertNotNull(ldapSyntax.getExtension("X-NOT-HUMAN-READABLE"));
    assertEquals(1, ldapSyntax.getExtension("X-NOT-HUMAN-READABLE").size());
    assertEquals("TRUE", ldapSyntax.getExtension("X-NOT-HUMAN-READABLE").get(0));
    assertEquals(value, ldapSyntax.getSpecification());
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Test(org.junit.Test)

Example 19 with LdapSyntax

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

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

the class SchemaUtilsTest method getSyntaxes.

public static LdapSyntax[] getSyntaxes() {
    LdapSyntax[] syntaxes = new LdapSyntax[3];
    syntaxes[0] = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.12", "Dn syntax", true);
    syntaxes[1] = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.15", "Directory String syntax", true);
    syntaxes[2] = new LdapSyntax("1.3.6.1.4.1.1466.115.121.1.58", "Substring assertion syntax", true);
    return syntaxes;
}
Also used : 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