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
}
}
}
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
}
}
}
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();
}
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;
}
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;
}
Aggregations