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