Class LdifAnonymizer


  • public class LdifAnonymizer
    extends Object
    Anonymize the content of a LDIF file. We will replace the values of the defined attributes with random chars. There are a default list of attributes that are going to be anonymized :
    • userPassword
    • displayName
    • givenName
    • surName
    • homePhone
    • homePostalAddress
    • jpegPhoto
    • labeledURI
    • mail
    • manager
    • mobile
    • organizationName
    • pager
    • photo
    • secretary
    • uid
    • userCertificate
    • userPKCS12
    • userSMIMECertificate
    • x500UniqueIdentifier
    • carLicense
    • host
    • locality
    • organizationName
    • organizationalUnitName
    • seelAlso
    • homeDirectory
    • uidNumber
    • gidNumber
    • commonName
    • gecos
    • description
    • memberUid
    Author:
    Apache Directory Project
    • Constructor Detail

      • LdifAnonymizer

        public LdifAnonymizer()
        Creates a default instance of LdifAnonymizer. The list of anonymized attribute is set to a default value.
      • LdifAnonymizer

        public LdifAnonymizer​(SchemaManager schemaManager)
        Creates a default instance of LdifAnonymizer. The list of anonymized attribute is set to a default value.
        Parameters:
        schemaManager - The SchemaManager instance we will use
    • Method Detail

      • setOut

        public void setOut​(PrintStream out)
        Set the PrintStream to use to print information about the processing
        Parameters:
        out - The PrintStream to use
      • setAttributeLatestValueMap

        public void setAttributeLatestValueMap​(AttributeType attributeType,
                                               Map<Integer,​?> latestValueMap)
        Set the latest value map to a defined anonymizer - if it exists -.
        Parameters:
        attributeType - The AttributeType we are targetting
        latestValueMap - The latest value map for this attribute
      • addAnonAttributeType

        public void addAnonAttributeType​(AttributeType attributeType)
                                  throws LdapException
        Add an attributeType that has to be anonymized
        Parameters:
        attributeType - the AttributeType that has to be anonymized
        Throws:
        LdapException - If the attributeType cannot be added
      • addAnonAttributeType

        public void addAnonAttributeType​(AttributeType attributeType,
                                         Anonymizer<?> anonymizer)
                                  throws LdapException
        Add an attributeType that has to be anonymized, with its associated anonymizer.
        Parameters:
        attributeType - the AttributeType that has to be anonymized
        anonymizer - the instance of anonymizer to use with this AttributeType
        Throws:
        LdapException - If the attributeType cannot be added
      • removeAnonAttributeType

        public void removeAnonAttributeType​(AttributeType attributeType)
        Remove an attributeType that has to be anonymized
        Parameters:
        attributeType - the AttributeType that we don't want to be anonymized
      • getAttributeAnonymizers

        public Map<String,​Anonymizer> getAttributeAnonymizers()
        Returns:
        The list of configured anonymizers
      • anonymizeFile

        public void anonymizeFile​(String ldifFile,
                                  Writer writer)
                           throws LdapException,
                                  IOException
        Anonymize a LDIF
        Parameters:
        ldifFile - The ldif file to anonymize
        writer - The Writer to use to write the result
        Throws:
        LdapException - If we got some LDAP related exception
        IOException - If we had some issue during some IO operations
      • anonymize

        public String anonymize​(String ldif)
                         throws LdapException,
                                IOException
        Anonymize a LDIF
        Parameters:
        ldif - The ldif content to anonymize
        Returns:
        an anonymized version of the given ldif
        Throws:
        LdapException - If we got some LDAP related exception
        IOException - If we had some issue during some IO operations
      • getValueMap

        public Map<Value,​Value> getValueMap()
        Returns:
        the valueMap
      • setValueMap

        public void setValueMap​(Map<Value,​Value> valueMap)
        Parameters:
        valueMap - the valueMap to set
      • getLatestStringMap

        public Map<Integer,​String> getLatestStringMap()
        Returns:
        the latest String Value Map
      • setLatestStringMap

        public void setLatestStringMap​(Map<Integer,​String> latestStringMap)
        Parameters:
        latestStringMap - the latest String Value Map to set
      • getLatestBytesMap

        public Map<Integer,​byte[]> getLatestBytesMap()
        Returns:
        the latest byte[] Value Map
      • setLatestBytesMap

        public void setLatestBytesMap​(Map<Integer,​byte[]> latestBytesMap)
        Parameters:
        latestBytesMap - the latest byte[] Value Map to set
      • main

        public static void main​(String[] args)
                         throws IOException,
                                LdapException
        The entry point, when used as a standalone application.
        Parameters:
        args - Contains the arguments : the file to convert. The anonymized LDIF will be printed on stdout
        Throws:
        IOException - If we had an issue opening the file to anonymise ot writing the result
        LdapException - If we had some issue while processing the LDAP data