use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class DefaultSchemaManagerTest method testSyntaxCheckersDoNotThrowException.
/**
* Verifies that all syntax checkers are properly initialized
* when loading the default schema.
*/
@Test
public void testSyntaxCheckersDoNotThrowException() throws Exception {
DefaultSchemaManager schemaManager = new DefaultSchemaManager();
schemaManager.loadAllEnabled();
for (SyntaxChecker sc : schemaManager.getSyntaxCheckerRegistry()) {
sc.isValidSyntax("foo");
}
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker in project directory-ldap-api by apache.
the class TestEntryUtils 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") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
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()) {
/**
* The mandatory serialVersionUID field
*/
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") {
/**
* The mandatory serialVersionUID field
*/
public static final long serialVersionUID = 1L;
public String normalize(String value) throws LdapException {
return normalize(value, 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.SyntaxChecker in project directory-ldap-api by apache.
the class EntryUtils method getIA5StringAttributeType.
/* no protection*/
static AttributeType getIA5StringAttributeType() {
MutableAttributeType attributeType = new MutableAttributeType("1.1");
attributeType.addName("1.1");
LdapSyntax syntax = new LdapSyntax("1.1.1", "", true);
syntax.setSyntaxChecker(new SyntaxChecker("1.1.2") {
public static final long serialVersionUID = 1L;
public boolean isValidSyntax(Object value) {
String strValue = Strings.deepTrim((String) value);
return (strValue == null) || (strValue.length() < 7);
}
});
MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2");
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)));
}
});
matchingRule.setNormalizer(new DeepTrimToLowerNormalizer(matchingRule.getOid()));
attributeType.setEquality(matchingRule);
attributeType.setSyntax(syntax);
return attributeType;
}
use of org.apache.directory.api.ldap.model.schema.SyntaxChecker 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.SyntaxChecker in project directory-ldap-api by apache.
the class LdapSyntaxHelper method addToRegistries.
/**
* Inject the LdapSyntax into the registries, updating the references to
* other SchemaObject
*
* @param ldapSyntax The LdapSyntax to add to the Registries
* @param errors The errors we got while adding the LdapSyntax to the Registries
* @param registries The Registries
* @throws LdapException If the addition failed
*/
public static void addToRegistries(LdapSyntax ldapSyntax, List<Throwable> errors, Registries registries) throws LdapException {
if (registries != null) {
try {
ldapSyntax.unlock();
SyntaxChecker syntaxChecker = null;
try {
// Gets the associated SyntaxChecker
syntaxChecker = registries.getSyntaxCheckerRegistry().lookup(ldapSyntax.getOid());
} catch (LdapException ne) {
// No SyntaxChecker ? Associate the Syntax to a catch all SyntaxChecker
syntaxChecker = OctetStringSyntaxChecker.builder().setOid(ldapSyntax.getOid()).build();
}
// S -> SC
if (syntaxChecker != null) {
registries.addReference(ldapSyntax, syntaxChecker);
ldapSyntax.setSyntaxChecker(syntaxChecker);
}
} finally {
ldapSyntax.lock();
}
}
}
Aggregations