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