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