Class LdifAnonymizer
java.lang.Object
org.apache.directory.ldap.client.api.LdifAnonymizer
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
- 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
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidaddAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType) Add an attributeType that has to be anonymizedvoidaddAnonAttributeType(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.voidAdd a new NamingContextAnonymize a LDIFvoidanonymizeFile(String ldifFile, Writer writer) Anonymize a LDIFGet the list of configured anonymizersGet the map containing the latest anonymised bytesGet the map containing the latest anonymised StringsMap<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value> Get the map of stored valuesstatic voidThe entry point, when used as a standalone application.voidremoveAnonAttributeType(org.apache.directory.api.ldap.model.schema.AttributeType attributeType) Remove an attributeType that has to be anonymizedvoidsetAttributeLatestValueMap(org.apache.directory.api.ldap.model.schema.AttributeType attributeType, Map<Integer, ?> latestValueMap) Set the latest value map to a defined anonymizer - if it exists -.voidsetLatestBytesMap(Map<Integer, byte[]> latestBytesMap) Set the map containing the latest anonymised bytesvoidsetLatestStringMap(Map<Integer, String> latestStringMap) Set the map containing the latest anonymised StringsvoidsetOut(PrintStream out) Set the PrintStream to use to print information about the processingvoidsetValueMap(Map<org.apache.directory.api.ldap.model.entry.Value, org.apache.directory.api.ldap.model.entry.Value> valueMap) Set the map of stored values
-
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
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 targettinglatestValueMap- 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 anonymizedanonymizer- 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
-
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 anonymizewriter- The Writer to use to write the result- Throws:
org.apache.directory.api.ldap.model.exception.LdapException- If we got some LDAP related exceptionIOException- 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 exceptionIOException- 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
-
setLatestStringMap
-
getLatestBytesMap
-
setLatestBytesMap
-
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 resultorg.apache.directory.api.ldap.model.exception.LdapException- If we had some issue while processing the LDAP data
-