Class LdifAnonymizer

java.lang.Object
org.apache.directory.ldap.client.api.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 Summary

    Constructors
    Constructor
    Description
    Creates a default instance of LdifAnonymizer.
    LdifAnonymizer(org.apache.directory.api.ldap.model.schema.SchemaManager schemaManager)
    Creates a default instance of LdifAnonymizer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType)
    Add an attributeType that has to be anonymized
    void
    addAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType, org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer<?> anonymizer)
    Add an attributeType that has to be anonymized, with its associated anonymizer.
    void
    Add a new NamingContext
    Anonymize a LDIF
    void
    anonymizeFile(String ldifFile, Writer writer)
    Anonymize a LDIF
    Map<String, org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer>
    Get the list of configured anonymizers
    Map<Integer,byte[]>
    Get the map containing the latest anonymised bytes
    Get the map containing the latest anonymised Strings
    Map<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value>
    Get the map of stored values
    static void
    main(String[] args)
    The entry point, when used as a standalone application.
    void
    removeAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType)
    Remove an attributeType that has to be anonymized
    void
    setAttributeLatestValueMap(org.apache.directory.api.ldap.model.schema.AttributeType attributeType, Map<Integer,?> latestValueMap)
    Set the latest value map to a defined anonymizer - if it exists -.
    void
    setLatestBytesMap(Map<Integer,byte[]> latestBytesMap)
    Set the map containing the latest anonymised bytes
    void
    Set the map containing the latest anonymised Strings
    void
    Set the PrintStream to use to print information about the processing
    void
    setValueMap(Map<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value> valueMap)
    Set the map of stored values

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LdifAnonymizer

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

      public LdifAnonymizer(org.apache.directory.api.ldap.model.schema.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 Details

    • 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(org.apache.directory.api.ldap.model.schema.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(org.apache.directory.api.ldap.model.schema.AttributeType attributeType) throws org.apache.directory.api.ldap.model.exception.LdapException
      Add an attributeType that has to be anonymized
      Parameters:
      attributeType - the AttributeType that has to be anonymized
      Throws:
      org.apache.directory.api.ldap.model.exception.LdapException - If the attributeType cannot be added
    • addAnonAttributeType

      public void addAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType, org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer<?> anonymizer) throws org.apache.directory.api.ldap.model.exception.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:
      org.apache.directory.api.ldap.model.exception.LdapException - If the attributeType cannot be added
    • removeAnonAttributeType

      public void removeAnonAttributeType(org.apache.directory.api.ldap.model.schema.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, org.apache.directory.api.ldap.model.ldif.anonymizer.Anonymizer> getAttributeAnonymizers()
      Get the list of configured anonymizers
      Returns:
      The list of configured anonymizers
    • addNamingContext

      public void addNamingContext(String dn) throws org.apache.directory.api.ldap.model.exception.LdapInvalidDnException
      Add a new NamingContext
      Parameters:
      dn - The naming context to add
      Throws:
      org.apache.directory.api.ldap.model.exception.LdapInvalidDnException - if it's an invalid naming context
    • anonymizeFile

      public void anonymizeFile(String ldifFile, Writer writer) throws org.apache.directory.api.ldap.model.exception.LdapException, IOException
      Anonymize a LDIF
      Parameters:
      ldifFile - The ldif file to anonymize
      writer - The Writer to use to write the result
      Throws:
      org.apache.directory.api.ldap.model.exception.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 org.apache.directory.api.ldap.model.exception.LdapException, IOException
      Anonymize a LDIF
      Parameters:
      ldif - The ldif content to anonymize
      Returns:
      an anonymized version of the given ldif
      Throws:
      org.apache.directory.api.ldap.model.exception.LdapException - If we got some LDAP related exception
      IOException - If we had some issue during some IO operations
    • getValueMap

      public Map<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value> getValueMap()
      Get the map of stored values
      Returns:
      the valueMap
    • setValueMap

      public void setValueMap(Map<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value> valueMap)
      Set the map of stored values
      Parameters:
      valueMap - the valueMap to set
    • getLatestStringMap

      public Map<Integer,String> getLatestStringMap()
      Get the map containing the latest anonymised Strings
      Returns:
      the latest String Value Map
    • setLatestStringMap

      public void setLatestStringMap(Map<Integer,String> latestStringMap)
      Set the map containing the latest anonymised Strings
      Parameters:
      latestStringMap - the latest String Value Map to set
    • getLatestBytesMap

      public Map<Integer,byte[]> getLatestBytesMap()
      Get the map containing the latest anonymised bytes
      Returns:
      the latest byte[] Value Map
    • setLatestBytesMap

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

      public static void main(String[] args) throws IOException, org.apache.directory.api.ldap.model.exception.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
      org.apache.directory.api.ldap.model.exception.LdapException - If we had some issue while processing the LDAP data