Search in sources :

Example 26 with SchemaObject

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

the class SchemaParserTestUtils method testNames.

/**
 * Tests NAME and its values
 *
 * @throws ParseException
 */
public static void testNames(AbstractSchemaParser parser, String oid, String required) throws ParseException {
    String value = null;
    SchemaObject asd = null;
    // alpha
    value = "( " + oid + " " + required + " NAME 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' )";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", asd.getNames().get(0));
    // alpha-num-hypen
    value = "( " + oid + " " + required + " NAME 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' )";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", asd.getNames().get(0));
    // with parentheses
    value = "( " + oid + " " + required + " NAME ( 'a-z-0-9' ) )";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("a-z-0-9", asd.getNames().get(0));
    // with parentheses, without space
    value = "(" + oid + " " + required + " NAME('a-z-0-9'))";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("a-z-0-9", asd.getNames().get(0));
    // multi with space
    value = " ( " + oid + " " + required + " NAME ( 'test1' 'test2' ) ) ";
    asd = parser.parse(value);
    assertEquals(2, asd.getNames().size());
    assertEquals("test1", asd.getNames().get(0));
    assertEquals("test2", asd.getNames().get(1));
    // multi without space
    value = "(" + oid + " " + required + " NAME('test1''test2''test3'))";
    asd = parser.parse(value);
    assertEquals(3, asd.getNames().size());
    assertEquals("test1", asd.getNames().get(0));
    assertEquals("test2", asd.getNames().get(1));
    assertEquals("test3", asd.getNames().get(2));
    // multi with many spaces
    value = "(          " + oid + " " + required + "          NAME          (          'test1'          'test2'          'test3'          )          )";
    asd = parser.parse(value);
    assertEquals(3, asd.getNames().size());
    assertEquals("test1", asd.getNames().get(0));
    assertEquals("test2", asd.getNames().get(1));
    assertEquals("test3", asd.getNames().get(2));
    // multi with tabs, newline, comment, etc.
    value = "(\r\n" + oid + "\r" + required + "\nNAME\t(\t\t\t'test1'\t\n\t'test2'\t\r\t'test3'\t\r\n\t)\n#comment\n)";
    asd = parser.parse(value);
    assertEquals(3, asd.getNames().size());
    assertEquals("test1", asd.getNames().get(0));
    assertEquals("test2", asd.getNames().get(1));
    assertEquals("test3", asd.getNames().get(2));
    // lowercase NAME
    value = "( " + oid + " " + required + " name 'test' )";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("test", asd.getNames().get(0));
    // unquoted NAME value
    value = "( " + oid + " " + required + " NAME test )";
    asd = parser.parse(value);
    assertEquals(1, asd.getNames().size());
    assertEquals("test", asd.getNames().get(0));
    // multi unquoted NAME values
    value = " ( " + oid + " " + required + " NAME (test1 test2) ) ";
    asd = parser.parse(value);
    assertEquals(2, asd.getNames().size());
    assertEquals("test1", asd.getNames().get(0));
    assertEquals("test2", asd.getNames().get(1));
    // NAM unknown
    value = "( " + oid + " " + required + " NAM 'test' )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid token NAM");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // start with number
        value = "( " + oid + " " + required + " NAME '1test' )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NAME 1test (starts with number)");
        } catch (ParseException pe) {
        // expected
        }
        // start with hypen
        value = "( " + oid + " " + required + " NAME '-test' )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NAME -test (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
        // invalid character
        value = "( " + oid + " " + required + " NAME 'te_st' )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NAME te_st (contains invalid character)");
        } catch (ParseException pe) {
        // expected
        }
        // one valid, one invalid
        value = "( " + oid + " " + required + " NAME ( 'test' 'te_st' ) )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NAME te_st (contains invalid character)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ParseException(java.text.ParseException)

Example 27 with SchemaObject

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

the class SchemaParserTestUtils method testNumericOid.

/**
 * Test numericoid
 *
 * @throws ParseException
 */
public static void testNumericOid(AbstractSchemaParser parser, String required) throws ParseException {
    String value = null;
    SchemaObject asd = null;
    // null test
    try {
        parser.parse(value);
        fail("Exception expected, null");
    } catch (ParseException pe) {
    // expected
    }
    // no oid
    value = "( )";
    try {
        parser.parse(value);
        fail("Exception expected, no NUMERICOID");
    } catch (ParseException pe) {
    // expected
    }
    // simple
    value = "( 0.1.2.3.4.5.6.7.8.9 " + required + " )";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // simple
    value = "( 123.4567.890 " + required + ")";
    asd = parser.parse(value);
    assertEquals("123.4567.890", asd.getOid());
    // simple with multiple spaces
    value = "(          0.1.2.3.4.5.6.7.8.9         " + required + " )";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // simple w/o spaces
    value = "(0.1.2.3.4.5.6.7.8.9 " + required + ")";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // simple with tabs, newline, comment.
    value = "(\t0.1.2.3.4.5.6.7.8.9\n#comment\n" + required + "\r\n)\r";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // quoted OID
    value = "( '0.1.2.3.4.5.6.7.8.9' " + required + " )";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // quoted OID in parentheses
    value = "( ('0.1.2.3.4.5.6.7.8.9') " + required + " )";
    asd = parser.parse(value);
    assertEquals("0.1.2.3.4.5.6.7.8.9", asd.getOid());
    // too short
    value = "( 1 " + required + " )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid NUMERICOID 1");
    } catch (ParseException pe) {
    // expected
    }
    // dot only
    value = "( . " + required + " )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid NUMERICOID .");
    } catch (ParseException pe) {
    // expected
    }
    // ends with dot
    value = "( 1.1. " + required + " )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid NUMERICOID 1.1.");
    } catch (ParseException pe) {
    // expected
    }
    // multiple not allowed
    value = "( ( 1.2.3 4.5.6 ) " + required + " )";
    try {
        parser.parse(value);
        fail("Exception expected, invalid multiple OIDs not allowed.)");
    } catch (ParseException pe) {
    // excpected
    }
    if (!parser.isQuirksMode()) {
        // non-numeric not allowed
        value = "( test " + required + " )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NUMERICOID test");
        } catch (ParseException pe) {
        // expected
        }
        // leading 0 not allowed
        value = "( 01.1 " + required + " )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NUMERICOID 01.1 (leading zero)");
        } catch (ParseException pe) {
        // expected
        }
        // alpha not allowed
        value = "( 1.2.a.4 " + required + " )";
        try {
            parser.parse(value);
            fail("Exception expected, invalid NUMERICOID 1.2.a.4 (alpha not allowed)");
        } catch (ParseException pe) {
        // excpected
        }
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ParseException(java.text.ParseException)

Example 28 with SchemaObject

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

the class ApiLdapModelOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    // uses FastDnParser
    new Dn("dc=example,dc=com");
    // uses ComplexDnparser (antlr based)
    new Dn("cn=a+sn=b,dc=example,dc=com");
    new Value("foo");
    new DefaultAttribute("cn");
    new DefaultEntry();
    AttributeUtils.toJndiAttribute(new DefaultAttribute("cn"));
    new BindRequestImpl();
    new EqualityNode<String>("cn", "foo");
    new LdapUrl("ldap://ldap.example.com:10389/dc=example,dc=com?objectclass");
    new ObjectClassDescriptionSchemaParser().parse("( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )");
    SchemaObject schemaObject = new LdapSyntax("1.2.3");
    new Registries().getGlobalOidRegistry().register(schemaObject);
    new Registries().getLoadedSchemas();
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ObjectClassDescriptionSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 29 with SchemaObject

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

the class DefaultSchemaLoader method loadDitStructureRules.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitStructureRules(Schema... schemas) throws LdapException, IOException {
    List<Entry> ditStructureRuleEntries = new ArrayList<>();
    if (schemas == null) {
        return ditStructureRuleEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof DitStructureRule) {
                DitStructureRule ditStructureRule = (DitStructureRule) schemaObject;
                Entry ditStructureRuleEntry = factory.convert(ditStructureRule, schema, null);
                ditStructureRuleEntries.add(ditStructureRuleEntry);
            }
        }
    }
    return ditStructureRuleEntries;
}
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) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) 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 30 with SchemaObject

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

the class DefaultSchemaLoader method loadNormalizers.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadNormalizers(Schema... schemas) throws LdapException, IOException {
    List<Entry> normalizerEntries = new ArrayList<>();
    if (schemas == null) {
        return normalizerEntries;
    }
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof NormalizerDescription) {
                NormalizerDescription normalizerDescription = (NormalizerDescription) schemaObject;
                Entry normalizerEntry = getEntry(normalizerDescription);
                normalizerEntries.add(normalizerEntry);
            }
        }
    }
    return normalizerEntries;
}
Also used : NormalizerDescription(org.apache.directory.api.ldap.model.schema.parsers.NormalizerDescription) 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) 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)

Aggregations

SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)37 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)14 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)13 ArrayList (java.util.ArrayList)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)12 Entry (org.apache.directory.api.ldap.model.entry.Entry)11 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)11 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)10 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 ParseException (java.text.ParseException)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)4 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)4 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)4 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)3 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)3