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;
}
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);
}
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());
}
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());
}
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);
}
Aggregations