Search in sources :

Example 21 with LdapSyntax

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

the class LdifAnonymizer method addAnonAttributeType.

/**
 * Add an attributeType that has to be anonymized
 *
 * @param attributeType the AttributeType that has to be anonymized
 * @throws LdapException If the attributeType cannot be added
 */
public void addAnonAttributeType(AttributeType attributeType) throws LdapException {
    schemaManager.add(attributeType);
    LdapSyntax syntax = attributeType.getSyntax();
    if (syntax.isHumanReadable()) {
        if (syntax.getOid().equals(SchemaConstants.INTEGER_SYNTAX)) {
            attributeAnonymizers.put(attributeType.getOid(), new IntegerAnonymizer());
        } else if (syntax.getOid().equals(SchemaConstants.DIRECTORY_STRING_SYNTAX)) {
            attributeAnonymizers.put(attributeType.getOid(), new StringAnonymizer());
        } else if (syntax.getOid().equals(SchemaConstants.TELEPHONE_NUMBER_SYNTAX)) {
            attributeAnonymizers.put(attributeType.getOid(), new TelephoneNumberAnonymizer());
        }
    } else {
        attributeAnonymizers.put(attributeType.getOid(), new BinaryAnonymizer());
    }
}
Also used : IntegerAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.IntegerAnonymizer) StringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.StringAnonymizer) CaseSensitiveStringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.CaseSensitiveStringAnonymizer) BinaryAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.BinaryAnonymizer) TelephoneNumberAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.TelephoneNumberAnonymizer) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax)

Example 22 with LdapSyntax

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

the class TestEntryUtils method syntaxFactory.

/**
 * A local Syntax class used for the tests
 */
public static LdapSyntax syntaxFactory(String oid, boolean humanReadable) {
    LdapSyntax ldapSyntax = new LdapSyntax(oid);
    ldapSyntax.setHumanReadable(humanReadable);
    return ldapSyntax;
}
Also used : LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax)

Example 23 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax 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 24 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax 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)

Example 25 with LdapSyntax

use of org.apache.directory.api.ldap.model.schema.LdapSyntax 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();
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ObjectClassDescriptionSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Aggregations

LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)34 Test (org.junit.Test)12 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)10 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)9 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)9 SyntaxChecker (org.apache.directory.api.ldap.model.schema.SyntaxChecker)9 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 Normalizer (org.apache.directory.api.ldap.model.schema.Normalizer)5 PrepareString (org.apache.directory.api.ldap.model.schema.PrepareString)5 DeepTrimToLowerNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.DeepTrimToLowerNormalizer)5 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)4 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)4 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)4 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)4 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)3 NoOpNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NoOpNormalizer)3 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Value (org.apache.directory.api.ldap.model.entry.Value)2