Search in sources :

Example 11 with DefaultAttribute

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

the class AddRequestDecorator method addAttributeType.

/**
 * Create a new attributeValue
 *
 * @param type The attribute's name (called 'type' in the grammar)
 * @throws LdapException If the value is invalid
 */
public void addAttributeType(String type) throws LdapException {
    // do not create a new attribute if we have seen this attributeType before
    if (getDecorated().getEntry().get(type) != null) {
        currentAttribute = getDecorated().getEntry().get(type);
        return;
    }
    // fix this to use AttributeImpl(type.getString().toLowerCase())
    currentAttribute = new DefaultAttribute(type);
    getDecorated().getEntry().put(currentAttribute);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 12 with DefaultAttribute

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

the class SearchResultEntryDsml method addAttribute.

/**
 * Create a new attribute
 *
 * @param type The attribute's type
 * @throws LdapException If we can't add the new attributeType
 */
public void addAttribute(String type) throws LdapException {
    currentAttribute = new DefaultAttribute(type);
    getDecorated().getEntry().put(currentAttribute);
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 13 with DefaultAttribute

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

the class ModifyRequestDsml method addAttributeTypeAndValues.

/**
 * Add a new attributeTypeAndValue
 *
 * @param type The attribute's name
 */
public void addAttributeTypeAndValues(String type) {
    currentAttribute = new DefaultAttribute(type);
    Modification modification = new DefaultModification(currentOperation, currentAttribute);
    getDecorated().addModification(modification);
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 14 with DefaultAttribute

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

the class LdifAnonymizer method anonymizeAva.

/**
 * Anonymize an AVA
 */
private Ava anonymizeAva(Ava ava) throws LdapInvalidDnException, LdapInvalidAttributeValueException {
    Value value = ava.getValue();
    AttributeType attributeType = ava.getAttributeType();
    Value anonymizedValue = valueMap.get(value);
    Ava anonymizedAva;
    if (anonymizedValue == null) {
        Attribute attribute = new DefaultAttribute(attributeType);
        attribute.add(value);
        Anonymizer anonymizer = attributeAnonymizers.get(attribute.getAttributeType().getOid());
        if (value.isHumanReadable()) {
            if (anonymizer == null) {
                anonymizedAva = new Ava(schemaManager, ava.getType(), value.getValue());
            } else {
                Attribute anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
                anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedAttribute.getString());
            }
        } else {
            if (anonymizer == null) {
                anonymizedAva = new Ava(schemaManager, ava.getType(), value.getBytes());
            } else {
                Attribute anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
                anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedAttribute.getBytes());
            }
        }
    } else {
        if (value.isHumanReadable()) {
            anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedValue.getValue());
        } else {
            anonymizedAva = new Ava(schemaManager, ava.getType(), anonymizedValue.getBytes());
        }
    }
    return anonymizedAva;
}
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) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Ava(org.apache.directory.api.ldap.model.name.Ava)

Example 15 with DefaultAttribute

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

the class SchemaAwareAttributeSerializationTest method testEntryAttributeNoBinaryValueSerialization.

@Test
public void testEntryAttributeNoBinaryValueSerialization() throws IOException, ClassNotFoundException, LdapInvalidAttributeValueException, LdapInvalidAttributeValueException {
    Attribute attribute1 = new DefaultAttribute(userCertificate);
    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)

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