Search in sources :

Example 1 with NameAndOptionalUIDSyntaxChecker

use of org.apache.directory.api.ldap.model.schema.syntaxCheckers.NameAndOptionalUIDSyntaxChecker in project directory-ldap-api by apache.

the class LdifAnonymizer method anonymizeEntry.

/**
 * Anonymize the full entry
 */
private Entry anonymizeEntry(LdifEntry ldifEntry) throws LdapException {
    Entry entry = ldifEntry.getEntry();
    Entry newEntry = new DefaultEntry(schemaManager);
    // Process the DN first
    Dn entryDn = entry.getDn();
    Dn anonymizedDn = anonymizeDn(entryDn);
    // Now, process the entry's attributes
    for (Attribute attribute : entry) {
        AttributeType attributeType = attribute.getAttributeType();
        // Deal with the special case of DN
        if (attributeType.getSyntax().getSyntaxChecker() instanceof DnSyntaxChecker) {
            for (Value dnValue : attribute) {
                Dn dn = new Dn(schemaManager, dnValue.getValue());
                Dn newdDn = anonymizeDn(dn);
                newEntry.add(attributeType, newdDn.toString());
            }
        } else // Deal with the special case of a NameAndOptionalUID
        if (attributeType.getSyntax().getSyntaxChecker() instanceof NameAndOptionalUIDSyntaxChecker) {
            for (Value dnValue : attribute) {
                // Get rid of the # part (UID)
                String valueStr = dnValue.getValue();
                int uidPos = valueStr.indexOf('#');
                String uid = null;
                if (uidPos != -1) {
                    uid = valueStr.substring(uidPos + 1);
                    valueStr = valueStr.substring(0, uidPos);
                }
                Dn dn = new Dn(schemaManager, valueStr);
                Dn newDn = anonymizeDn(dn);
                String newDnStr = newDn.toString();
                if (uid != null) {
                    newDnStr = newDnStr + '#' + uid;
                }
                newEntry.add(attributeType, newDnStr);
            }
        } else {
            Anonymizer anonymizer = attributeAnonymizers.get(attribute.getAttributeType().getOid());
            if (anonymizer == null) {
                newEntry.add(attribute);
            } else {
                Attribute anonymizedAttribute = anonymizer.anonymize(valueMap, valueSet, attribute);
                if (anonymizedAttribute != null) {
                    newEntry.add(anonymizedAttribute);
                }
            }
        }
    }
    newEntry.setDn(anonymizedDn);
    return newEntry;
}
Also used : DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) NameAndOptionalUIDSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.NameAndOptionalUIDSyntaxChecker) 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) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) DnSyntaxChecker(org.apache.directory.api.ldap.model.schema.syntaxCheckers.DnSyntaxChecker)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)1 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 Value (org.apache.directory.api.ldap.model.entry.Value)1 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)1 Anonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer)1 BinaryAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.BinaryAnonymizer)1 CaseSensitiveStringAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.CaseSensitiveStringAnonymizer)1 IntegerAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.IntegerAnonymizer)1 StringAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.StringAnonymizer)1 TelephoneNumberAnonymizer (org.apache.directory.api.ldap.model.ldif.anonymizer.TelephoneNumberAnonymizer)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)1 DnSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.DnSyntaxChecker)1 NameAndOptionalUIDSyntaxChecker (org.apache.directory.api.ldap.model.schema.syntaxCheckers.NameAndOptionalUIDSyntaxChecker)1