Search in sources :

Example 11 with SyntaxChecker

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

the class DefaultSyntaxCheckerRegistry method toString.

/**
 * @see Object#toString()
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(schemaObjectType).append(": ");
    boolean isFirst = true;
    for (Map.Entry<String, SyntaxChecker> entry : byName.entrySet()) {
        if (isFirst) {
            isFirst = false;
        } else {
            sb.append(", ");
        }
        SyntaxChecker syntaxChecker = entry.getValue();
        String fqcn = syntaxChecker.getFqcn();
        int lastDotPos = fqcn.lastIndexOf('.');
        sb.append('<').append(syntaxChecker.getOid()).append(", ");
        if (lastDotPos > 0) {
            sb.append(fqcn.substring(lastDotPos + 1));
        } else {
            sb.append(fqcn);
        }
        sb.append('>');
    }
    return sb.toString();
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) Map(java.util.Map)

Example 12 with SyntaxChecker

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

the class DefaultSyntaxCheckerRegistry method unregisterSchemaElements.

/**
 * {@inheritDoc}
 */
@Override
public void unregisterSchemaElements(String schemaName) throws LdapException {
    if (schemaName == null) {
        return;
    }
    // with the give schemaName
    for (SyntaxChecker syntaxChecker : this) {
        if (schemaName.equalsIgnoreCase(syntaxChecker.getSchemaName())) {
            String oid = syntaxChecker.getOid();
            SchemaObject removed = unregister(oid);
            if (DEBUG) {
                LOG.debug(I18n.msg(I18n.MSG_13702_REMOVED_FROM_REGISTRY, removed, oid));
            }
        }
    }
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker)

Example 13 with SyntaxChecker

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

the class DefaultAttribute method isValid.

/**
 * {@inheritDoc}
 */
@Override
public boolean isValid(AttributeType attributeType) throws LdapInvalidAttributeValueException {
    LdapSyntax syntax = attributeType.getSyntax();
    if (syntax == null) {
        return false;
    }
    SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();
    if (syntaxChecker == null) {
        return false;
    }
    // Check that we can have no value for this attributeType
    if (values.isEmpty()) {
        return syntaxChecker.isValidSyntax(null);
    }
    // Check that we can't have more than one value if the AT is single-value
    if ((attributeType.isSingleValued()) && (values.size() > 1)) {
        return false;
    }
    // Now check the values
    for (Value value : values) {
        try {
            if (!value.isValid(syntaxChecker)) {
                return false;
            }
        } catch (LdapException le) {
            return false;
        }
    }
    return true;
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 14 with SyntaxChecker

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

the class TestEntryUtils method getBytesAttributeType.

/* No protection */
static AttributeType getBytesAttributeType() {
    MutableAttributeType attributeType = new MutableAttributeType("1.2");
    LdapSyntax syntax = new LdapSyntax("1.2.1", "", true);
    syntax.setSyntaxChecker(new SyntaxChecker("1.2.1") {

        /**
         * The mandatory serialVersionUID field
         */
        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 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 {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    attributeType.setEquality(matchingRule);
    attributeType.setSyntax(syntax);
    return attributeType;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) AssertionType(org.apache.directory.api.ldap.model.schema.PrepareString.AssertionType) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 15 with SyntaxChecker

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

the class TestEntryUtils 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") {

        /**
         * The mandatory serialVersionUID field
         */
        public static final long serialVersionUID = 1L;

        public boolean isValidSyntax(Object value) {
            String trimmedValue = Strings.deepTrim((String) value);
            return (trimmedValue == null) || (trimmedValue.length() < 7);
        }
    });
    MutableMatchingRule matchingRule = new MutableMatchingRule("1.1.2");
    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)));
        }
    });
    matchingRule.setNormalizer(new DeepTrimToLowerNormalizer(matchingRule.getOid()));
    attributeType.setEquality(matchingRule);
    attributeType.setSyntax(syntax);
    return attributeType;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) DeepTrimToLowerNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType)

Aggregations

SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)24 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)9 Test (org.junit.Test)9 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)7 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)6 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 OctetStringSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.OctetStringSyntaxChecker)5 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)4 BooleanSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker)4 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)3 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)3 RegexSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.RegexSyntaxChecker)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2