use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class SchemaManagerAddTest method testAddMatchingRuleNotExistingSyntax.
/**
* Try to inject a new MatchingRule with a not existing Syntax
*/
@Test
public void testAddMatchingRuleNotExistingSyntax() throws Exception {
SchemaManager schemaManager = loadSystem();
int mrrSize = schemaManager.getMatchingRuleRegistry().size();
int goidSize = schemaManager.getGlobalOidRegistry().size();
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.0");
matchingRule.setNames("Test");
matchingRule.setSyntaxOid("1.1.1");
// It should fail
assertFalse(schemaManager.add(matchingRule));
List<Throwable> errors = schemaManager.getErrors();
assertEquals(1, errors.size());
Throwable error = errors.get(0);
assertTrue(error instanceof LdapSchemaException);
assertEquals(mrrSize, schemaManager.getMatchingRuleRegistry().size());
assertEquals(goidSize, schemaManager.getGlobalOidRegistry().size());
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class SchemaEntityFactory method getMatchingRule.
/**
* {@inheritDoc}
* @throws LdapInvalidAttributeValueException If the MatchingRule does not exist
* @throws LdapUnwillingToPerformException If the schema is not loaded
*/
@Override
public MatchingRule getMatchingRule(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapUnwillingToPerformException, LdapInvalidAttributeValueException {
checkEntry(entry, SchemaConstants.MATCHING_RULE);
// The MatchingRule OID
String oid = getOid(entry, SchemaConstants.MATCHING_RULE, schemaManager.isStrict());
// Get the schema
if (!schemaManager.isSchemaLoaded(schemaName)) {
// The schema is not loaded. We can't create the requested MatchingRule
String msg = I18n.err(I18n.ERR_16028_CANNOT_ADD_MR, entry.getDn().getName(), schemaName);
LOG.warn(msg);
throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
}
Schema schema = getSchema(schemaName, targetRegistries);
if (schema == null) {
// The schema is disabled. We still have to update the backend
String msg = I18n.err(I18n.ERR_16029_CANNOT_ADD_MR_IN_REGISTRY, entry.getDn().getName(), schemaName);
LOG.info(msg);
schema = schemaManager.getLoadedSchema(schemaName);
}
MutableMatchingRule matchingRule = new MutableMatchingRule(oid);
// The syntax field
Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
if (mSyntax != null) {
matchingRule.setSyntaxOid(mSyntax.getString());
}
// The normalizer and comparator fields will be updated when we will
// apply the registry
// Common properties
setSchemaObjectProperties(matchingRule, entry, schema);
return matchingRule;
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class EntryUtils method getCaseIgnoringAttributeNoNumbersType.
/* no protection*/
static AttributeType getCaseIgnoringAttributeNoNumbersType() {
MutableAttributeType attributeType = new MutableAttributeType("1.1.3.1");
LdapSyntax syntax = new LdapSyntax("1.1.1.1", "", true);
syntax.setSyntaxChecker(new SyntaxChecker("1.1.2.1") {
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
if (value == null) {
return true;
}
if (!(value instanceof String)) {
return false;
}
String strval = (String) value;
for (char c : strval.toCharArray()) {
if (Character.isDigit(c)) {
return false;
}
}
return true;
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2.1");
matchingRule.setSyntax(syntax);
matchingRule.setLdapComparator(new LdapComparator<String>(matchingRule.getOid()) {
public static final long serialVersionUID = 1L;
public int compare(String o1, String o2) {
return (o1 == null ? (o2 == null ? 0 : -1) : (o2 == null ? 1 : o1.compareTo(o2)));
}
});
Normalizer normalizer = new Normalizer("1.1.1") {
public static final long serialVersionUID = 1L;
public String normalize(String value) throws LdapException {
return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
}
public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
return Strings.toLowerCaseAscii(value);
}
};
matchingRule.setNormalizer(normalizer);
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
use of org.apache.directory.api.ldap.model.schema.MutableMatchingRule in project directory-ldap-api by apache.
the class EntryUtils method getBytesAttributeType.
/* No protection */
static AttributeType getBytesAttributeType() {
MutableAttributeType attributeType = new MutableAttributeType("1.2");
LdapSyntax syntax = new LdapSyntax("1.2.1", "", false);
syntax.setSyntaxChecker(new SyntaxChecker("1.2.1") {
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
return (value == null) || (((byte[]) value).length < 5);
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.2.2");
matchingRule.setSyntax(syntax);
matchingRule.setLdapComparator(new ByteArrayComparator("1.2.2"));
matchingRule.setNormalizer(new NoOpNormalizer("1.1.1"));
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
Aggregations