Search in sources :

Example 76 with DefaultAttribute

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

the class StringAnonymizer 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) {
                // TODO : handle that
                }
            } 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 77 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, byte[]... 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)

Example 78 with DefaultAttribute

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

the class AddRequestImpl method addAttributeType.

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

Example 79 with DefaultAttribute

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

the class UserDAO method loadUserAdminRoles.

/**
 * Given a collection of ARBAC roles, {@link UserAdminRole}, convert to raw data format and load into ldap
 * attribute set in preparation for ldap add.
 *
 * @param list  contains List of type {@link UserAdminRole} targeted for adding to ldap.
 * @param entry collection of ldap attributes containing ARBAC role assignments in raw ldap format.
 * @throws LdapException
 */
private void loadUserAdminRoles(List<UserAdminRole> list, Entry entry) throws LdapException {
    if (list != null) {
        Attribute userAdminRoleData = new DefaultAttribute(GlobalIds.USER_ADMINROLE_DATA);
        Attribute userAdminRoleAssign = new DefaultAttribute(GlobalIds.USER_ADMINROLE_ASSIGN);
        for (UserAdminRole userRole : list) {
            userAdminRoleData.add(userRole.getRawData());
            userAdminRoleAssign.add(userRole.getName());
        }
        if (userAdminRoleData.size() != 0) {
            entry.add(userAdminRoleData);
            entry.add(userAdminRoleAssign);
        }
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) UserAdminRole(org.apache.directory.fortress.core.model.UserAdminRole) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute)

Example 80 with DefaultAttribute

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

the class UserDAO method loadUserRoles.

/**
 * Given a collection of RBAC roles, {@link UserRole}, convert to raw data format and load into ldap modification
 * set in preparation for ldap modify.
 *
 * @param list contains List of type {@link UserRole} targeted for updating into ldap.
 * @param mods contains ldap modification set containing RBAC role assignments in raw ldap format to be updated.
 * @throws LdapInvalidAttributeValueException
 */
private void loadUserRoles(List<UserRole> list, List<Modification> mods) throws LdapInvalidAttributeValueException {
    Attribute userRoleData = new DefaultAttribute(GlobalIds.USER_ROLE_DATA);
    Attribute userRoleAssign = new DefaultAttribute(GlobalIds.USER_ROLE_ASSIGN);
    if (list != null) {
        for (UserRole userRole : list) {
            userRoleData.add(userRole.getRawData());
            userRoleAssign.add(userRole.getName());
        }
        if (userRoleData.size() != 0) {
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, userRoleData));
            mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, userRoleAssign));
        }
    }
}
Also used : DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) UserRole(org.apache.directory.fortress.core.model.UserRole) 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