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
- 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 LdifAnonymizer()
Creates a default instance of LdifAnonymizer.LdifAnonymizer(SchemaManager schemaManager)
Creates a default instance of LdifAnonymizer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAnonAttributeType(AttributeType attributeType)
Add an attributeType that has to be anonymizedvoid
addAnonAttributeType(AttributeType attributeType, Anonymizer<?> anonymizer)
Add an attributeType that has to be anonymized, with its associated anonymizer.void
addNamingContext(String dn)
Add a new NamingContextString
anonymize(String ldif)
Anonymize a LDIFvoid
anonymizeFile(String ldifFile, Writer writer)
Anonymize a LDIFMap<String,Anonymizer>
getAttributeAnonymizers()
Map<Integer,byte[]>
getLatestBytesMap()
Map<Integer,String>
getLatestStringMap()
Map<Value,Value>
getValueMap()
static void
main(String[] args)
The entry point, when used as a standalone application.void
removeAnonAttributeType(AttributeType attributeType)
Remove an attributeType that has to be anonymizedvoid
setAttributeLatestValueMap(AttributeType attributeType, Map<Integer,?> latestValueMap)
Set the latest value map to a defined anonymizer - if it exists -.void
setLatestBytesMap(Map<Integer,byte[]> latestBytesMap)
void
setLatestStringMap(Map<Integer,String> latestStringMap)
void
setOut(PrintStream out)
Set the PrintStream to use to print information about the processingvoid
setValueMap(Map<Value,Value> valueMap)
-
-
-
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 targettinglatestValueMap
- 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 anonymizedanonymizer
- 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
-
addNamingContext
public void addNamingContext(String dn) throws LdapInvalidDnException
Add a new NamingContext- Parameters:
dn
- The naming context to add- Throws:
LdapInvalidDnException
- if it's an invalid naming context
-
anonymizeFile
public void anonymizeFile(String ldifFile, Writer writer) throws LdapException, IOException
Anonymize a LDIF- Parameters:
ldifFile
- The ldif file to anonymizewriter
- The Writer to use to write the result- Throws:
LdapException
- If we got some LDAP related exceptionIOException
- 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 exceptionIOException
- 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 resultLdapException
- If we had some issue while processing the LDAP data
-
-