Search in sources :

Example 91 with DefaultAttribute

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

the class CaseSensitiveStringAnonymizer method anonymize.

/**
 * Anonymize an attribute using pure random values (either chars of bytes, depending on the Attribute type)
 */
@Override
public Attribute anonymize(Map<Value, Value> valueMap, Set<Value> valueSet, Attribute attribute) {
    AttributeType attributeType = attribute.getAttributeType();
    Attribute result = new DefaultAttribute(attributeType);
    for (Value value : attribute) {
        if (value.isHumanReadable()) {
            Value anonymized = valueMap.get(value);
            if (anonymized != null) {
                try {
                    result.add(anonymized);
                } catch (LdapInvalidAttributeValueException e) {
                }
            } else {
                String strValue = value.getValue();
                String newValue = computeNewValue(strValue);
                try {
                    result.add(newValue);
                    Value anonValue = new Value(attribute.getAttributeType(), newValue);
                    valueMap.put((Value) value, anonValue);
                    valueSet.add(anonValue);
                } catch (LdapInvalidAttributeValueException e) {
                    throw new RuntimeException(I18n.err(I18n.ERR_13436_ERROR_ANONYMIZING_VALUE, strValue));
                }
            }
        }
    }
    return result;
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)

Example 92 with DefaultAttribute

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

the class IntegerAnonymizer method anonymize.

/**
 * Anonymize an attribute using pure random values (either chars of bytes, depending on the Attribute type)
 */
@Override
public Attribute anonymize(Map<Value, Value> valueMap, Set<Value> valueSet, Attribute attribute) {
    Attribute result = new DefaultAttribute(attribute.getAttributeType());
    for (Value value : attribute) {
        if (value.isHumanReadable()) {
            Value anonymized = valueMap.get(value);
            if (anonymized != null) {
                try {
                    result.add(anonymized);
                } catch (LdapInvalidAttributeValueException e) {
                // Handle me...
                }
            } else {
                String strValue = value.getValue();
                String newValue = computeNewIntegerValue(strValue);
                try {
                    result.add(newValue);
                    Value anonValue = new Value(attribute.getAttributeType(), newValue);
                    valueMap.put((Value) value, anonValue);
                    valueSet.add(anonValue);
                } catch (LdapInvalidAttributeValueException e) {
                // TODO : handle that
                }
            }
        }
    }
    return result;
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)

Example 93 with DefaultAttribute

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

the class AttributesFactory method injectNames.

private void injectNames(List<String> names, Entry entry, SchemaManager schemaManager) throws LdapException {
    if ((names == null) || names.isEmpty()) {
        return;
    }
    Attribute attr;
    if (schemaManager != null) {
        attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_NAME_AT));
    } else {
        attr = new DefaultAttribute(MetaSchemaConstants.M_NAME_AT);
    }
    for (String name : names) {
        attr.add(name);
    }
    entry.put(attr);
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 94 with DefaultAttribute

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

the class AttributesFactory method convert.

/**
 * Creates the attributes of an entry representing an objectClass.
 *
 * <pre>
 *  objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.2
 *      NAME 'metaObjectClass'
 *      DESC 'meta definition of the objectclass object'
 *      SUP metaTop
 *      STRUCTURAL
 *      MUST m-oid
 *      MAY ( m-name $ m-obsolete $ m-supObjectClass $ m-typeObjectClass $ m-must $
 *            m-may $ m-extensionObjectClass )
 *  )
 * </pre>
 *
 * @param objectClass the objectClass to produce a meta schema entry for
 * @param schema The schema containing this ObjectClass
 * @param schemaManager The SchemaManager
 * @return the attributes of the metaSchema entry representing the objectClass
 * @throws LdapException If the conversion failed
 */
public Entry convert(ObjectClass objectClass, Schema schema, SchemaManager schemaManager) throws LdapException {
    Entry entry = new DefaultEntry(schemaManager);
    entry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_OBJECT_CLASS_OC);
    entry.put(MetaSchemaConstants.M_TYPE_OBJECT_CLASS_AT, objectClass.getType().toString());
    entry.put(SchemaConstants.CREATORS_NAME_AT, schema.getOwner());
    entry.put(SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime());
    injectCommon(objectClass, entry, schemaManager);
    Attribute attr;
    // handle the superior objectClasses
    if ((objectClass.getSuperiorOids() != null) && !objectClass.getSuperiorOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_SUP_OBJECT_CLASS_AT);
        }
        for (String superior : objectClass.getSuperiorOids()) {
            attr.add(superior);
        }
        entry.put(attr);
    }
    // add the must list
    if ((objectClass.getMustAttributeTypeOids() != null) && !objectClass.getMustAttributeTypeOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_MUST_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_MUST_AT);
        }
        for (String mustOid : objectClass.getMustAttributeTypeOids()) {
            attr.add(mustOid);
        }
        entry.put(attr);
    }
    // add the may list
    if ((objectClass.getMayAttributeTypeOids() != null) && !objectClass.getMayAttributeTypeOids().isEmpty()) {
        if (schemaManager != null) {
            attr = new DefaultAttribute(schemaManager.getAttributeType(MetaSchemaConstants.M_MAY_AT));
        } else {
            attr = new DefaultAttribute(MetaSchemaConstants.M_MAY_AT);
        }
        for (String mayOid : objectClass.getMayAttributeTypeOids()) {
            attr.add(mayOid);
        }
        entry.put(attr);
    }
    return entry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 95 with DefaultAttribute

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

the class ModifyRequestImpl method addModification.

private void addModification(ModificationOperation modOp, String attributeName, String... attributeValue) {
    Attribute attr = new DefaultAttribute(attributeName, attributeValue);
    addModification(attr, modOp);
}
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)

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