Search in sources :

Example 96 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class LdifAnonymizer method anonymizeChangeAdd.

/**
 * Anonymize a Add change
 */
private LdifEntry anonymizeChangeAdd(LdifEntry ldifEntry) throws LdapException {
    Dn entryDn = ldifEntry.getDn();
    LdifEntry newLdifEntry = new LdifEntry(schemaManager);
    newLdifEntry.setChangeType(ChangeType.Add);
    // Process the DN first
    Dn anonymizedDn = anonymizeDn(entryDn);
    newLdifEntry.setDn(anonymizedDn);
    // Now, process the entry's attributes
    for (Attribute attribute : ldifEntry) {
        AttributeType attributeType = attribute.getAttributeType();
        Attribute anonymizedAttribute = new DefaultAttribute(attributeType);
        if (attributeType.getSyntax().getSyntaxChecker() instanceof DnSyntaxChecker) {
            for (Value dnValue : attribute) {
                Dn dn = new Dn(schemaManager, dnValue.getValue());
                Dn newdDn = anonymizeDn(dn);
                anonymizedAttribute.add(newdDn.toString());
            }
            newLdifEntry.addAttribute(attribute);
        } else {
            Anonymizer anonymizer = attributeAnonymizers.get(attribute.getAttributeType().getOid());
            if (anonymizer == null) {
                newLdifEntry.addAttribute(attribute);
            } else {
                anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
                if (anonymizedAttribute != null) {
                    newLdifEntry.addAttribute(anonymizedAttribute);
                }
            }
        }
    }
    return newLdifEntry;
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) TelephoneNumberAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.TelephoneNumberAnonymizer) StringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.StringAnonymizer) BinaryAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.BinaryAnonymizer) IntegerAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.IntegerAnonymizer) CaseSensitiveStringAnonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.CaseSensitiveStringAnonymizer) Anonymizer(org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer) Value(org.apache.directory.api.ldap.model.entry.Value) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DnSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.DnSyntaxChecker) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry)

Example 97 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareAttributeSerializationTest method testEntryAttributeOneBinaryValueSerialization.

@Test
public void testEntryAttributeOneBinaryValueSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute(userCertificate, data1);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    attribute1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Attribute attribute2 = new DefaultAttribute(userCertificate);
    attribute2.readExternal(in);
    attribute2.apply(userCertificate);
    assertEquals(attribute1, attribute2);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 98 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareAttributeSerializationTest method testEntryAttributeOneValueSerialization.

@Test
public void testEntryAttributeOneValueSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute("CommonName", cn, "test");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    attribute1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Attribute attribute2 = new DefaultAttribute(cn);
    attribute2.readExternal(in);
    attribute2.apply(cn);
    assertEquals(attribute1, attribute2);
    assertEquals("CommonName", attribute2.getUpId());
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 99 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareAttributeSerializationTest method testEntryAttributeManyValuesSerialization.

@Test
public void testEntryAttributeManyValuesSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute("CN", cn, "test1", "test2", "test3");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    attribute1.writeExternal(out);
    ObjectInputStream in = null;
    byte[] data = baos.toByteArray();
    in = new ObjectInputStream(new ByteArrayInputStream(data));
    Attribute attribute2 = new DefaultAttribute(cn);
    attribute2.readExternal(in);
    attribute2.apply(cn);
    assertEquals(attribute1, attribute2);
    assertEquals("CN", attribute2.getUpId());
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 100 with DefaultAttribute

use of org.apache.directory.api.ldap.model.entry.DefaultAttribute in project directory-ldap-api by apache.

the class SchemaAwareAttributeTest method testClone.

/**
 * Test method testClone()
 */
@Test
public void testClone() throws LdapException {
    Attribute attr = new DefaultAttribute(atDC);
    Attribute clone = attr.clone();
    assertEquals(attr, clone);
    attr.setUpId("DomainComponent");
    assertEquals("0.9.2342.19200300.100.1.25", clone.getId());
    attr.add("a", (String) null, "b");
    clone = attr.clone();
    assertEquals(attr, clone);
    attr.remove("a");
    assertNotSame(attr, clone);
    clone = attr.clone();
    assertEquals(attr, clone);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Test(org.junit.Test)

Aggregations

DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)159 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)131 Test (org.junit.Test)106 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)41 Modification (org.apache.directory.api.ldap.model.entry.Modification)40 Entry (org.apache.directory.api.ldap.model.entry.Entry)36 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)35 Value (org.apache.directory.api.ldap.model.entry.Value)20 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ObjectOutputStream (java.io.ObjectOutputStream)12 Dn (org.apache.directory.api.ldap.model.name.Dn)12 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)11 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)11 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)8 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)7 ModifyRequestImpl (org.apache.directory.api.ldap.model.message.ModifyRequestImpl)7 ModifyResponse (org.apache.directory.api.ldap.model.message.ModifyResponse)7 HashSet (java.util.HashSet)6