Class ScrambleAttributeTransformation
- java.lang.Object
-
- com.unboundid.ldap.sdk.transformations.ScrambleAttributeTransformation
-
- All Implemented Interfaces:
EntryTransformation
,LDIFChangeRecordTransformation
,LDIFReaderChangeRecordTranslator
,LDIFReaderEntryTranslator
,LDIFWriterChangeRecordTranslator
,LDIFWriterEntryTranslator
@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class ScrambleAttributeTransformation extends java.lang.Object implements EntryTransformation, LDIFChangeRecordTransformation
This class provides an implementation of an entry and change record transformation that may be used to scramble the values of a specified set of attributes in a way that attempts to obscure the original values but that preserves the syntax for the values. When possible the scrambling will be performed in a repeatable manner, so that a given input value will consistently yield the same scrambled representation.
-
-
Constructor Summary
Constructors Constructor Description ScrambleAttributeTransformation(Schema schema, java.lang.Long randomSeed, boolean scrambleEntryDNs, java.util.Collection<java.lang.String> attributes, java.util.Collection<java.lang.String> jsonFields)
Creates a new scramble attribute transformation that will scramble the values of a specified set of attributes.ScrambleAttributeTransformation(Schema schema, java.lang.Long randomSeed, java.lang.String... attributes)
Creates a new scramble attribute transformation that will scramble the values of a specified set of attributes.ScrambleAttributeTransformation(java.lang.String... attributes)
Creates a new scramble attribute transformation that will scramble the values of the specified attributes.ScrambleAttributeTransformation(java.util.Collection<java.lang.String> attributes)
Creates a new scramble attribute transformation that will scramble the values of the specified attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Attribute
scrambleAttribute(Attribute a)
Creates a copy of the provided attribute with its values scrambled if appropriate.byte[]
scrambleBinaryValue(byte[] value)
Scrambles the provided value, which may contain non-ASCII characters.DN
scrambleDN(DN dn)
Creates a scrambled copy of the provided DN.java.lang.String
scrambleDN(java.lang.String dn)
Creates a scrambled copy of the provided DN.java.lang.String
scrambleEncodedPassword(java.lang.String s)
Scrambles the provided encoded password value.java.lang.String
scrambleGeneralizedTime(java.lang.String s)
Scrambles the provided generalized time value.java.lang.String
scrambleJSONObject(java.lang.String s)
Scrambles the provided JSON object value.java.lang.String
scrambleNumericValue(java.lang.String s)
Scrambles the provided value, which is expected to be largely numeric.RDN
scrambleRDN(RDN rdn)
Creates a scrambled copy of the provided RDN.java.lang.String
scrambleString(java.lang.String s)
Scrambles the provided string.LDIFChangeRecord
transformChangeRecord(LDIFChangeRecord r)
Applies an appropriate transformation to the provided LDIF change record.Entry
transformEntry(Entry e)
Applies an appropriate transformation to the provided entry.Entry
translate(Entry original, long firstLineNumber)
Applies some special transformation or filtering to the original Entry.LDIFChangeRecord
translate(LDIFChangeRecord original, long firstLineNumber)
Applies some special transformation or filtering to the original change record.LDIFChangeRecord
translateChangeRecordToWrite(LDIFChangeRecord original)
Applies some special transformation or filtering to the original change record.Entry
translateEntryToWrite(Entry original)
Applies some special transformation or filtering to the original Entry.
-
-
-
Constructor Detail
-
ScrambleAttributeTransformation
public ScrambleAttributeTransformation(@NotNull java.lang.String... attributes)
Creates a new scramble attribute transformation that will scramble the values of the specified attributes. A default standard schema will be used, entry DNs will not be scrambled, and if any of the target attributes have values that are JSON objects, the values of all of those objects' fields will be scrambled.- Parameters:
attributes
- The names or OIDs of the attributes to scramble.
-
ScrambleAttributeTransformation
public ScrambleAttributeTransformation(@NotNull java.util.Collection<java.lang.String> attributes)
Creates a new scramble attribute transformation that will scramble the values of the specified attributes. A default standard schema will be used, entry DNs will not be scrambled, and if any of the target attributes have values that are JSON objects, the values of all of those objects' fields will be scrambled.- Parameters:
attributes
- The names or OIDs of the attributes to scramble.
-
ScrambleAttributeTransformation
public ScrambleAttributeTransformation(@Nullable Schema schema, @Nullable java.lang.Long randomSeed, @NotNull java.lang.String... attributes)
Creates a new scramble attribute transformation that will scramble the values of a specified set of attributes. Entry DNs will not be scrambled, and if any of the target attributes have values that are JSON objects, the values of all of those objects' fields will be scrambled.- Parameters:
schema
- The schema to use when processing. This may benull
if a default standard schema should be used. The schema will be used to identify alternate names that may be used to reference the attributes, and to determine the expected syntax for more accurate scrambling.randomSeed
- The seed to use for the random number generator when scrambling each value. It may benull
if the random seed should be automatically selected.attributes
- The names or OIDs of the attributes to scramble.
-
ScrambleAttributeTransformation
public ScrambleAttributeTransformation(@Nullable Schema schema, @Nullable java.lang.Long randomSeed, boolean scrambleEntryDNs, @NotNull java.util.Collection<java.lang.String> attributes, @Nullable java.util.Collection<java.lang.String> jsonFields)
Creates a new scramble attribute transformation that will scramble the values of a specified set of attributes.- Parameters:
schema
- The schema to use when processing. This may benull
if a default standard schema should be used. The schema will be used to identify alternate names that may be used to reference the attributes, and to determine the expected syntax for more accurate scrambling.randomSeed
- The seed to use for the random number generator when scrambling each value. It may benull
if the random seed should be automatically selected.scrambleEntryDNs
- Indicates whether to scramble any appropriate attributes contained in entry DNs and the values of attributes with a DN syntax.attributes
- The names or OIDs of the attributes to scramble.jsonFields
- The names of the JSON fields whose values should be scrambled. If any field names are specified, then any JSON objects to be scrambled will only have those fields scrambled (with field names treated in a case-insensitive manner) and all other fields will be preserved without scrambling. If this isnull
or empty, then scrambling will be applied for all values in all fields.
-
-
Method Detail
-
transformEntry
@Nullable public Entry transformEntry(@NotNull Entry e)
Applies an appropriate transformation to the provided entry.- Specified by:
transformEntry
in interfaceEntryTransformation
- Parameters:
e
- The entry to transform.- Returns:
- A copy of the entry with any appropriate transformation applied,
the original entry if no transformations were necessary, or
null
if the entry should be suppressed.
-
transformChangeRecord
@Nullable public LDIFChangeRecord transformChangeRecord(@NotNull LDIFChangeRecord r)
Applies an appropriate transformation to the provided LDIF change record.- Specified by:
transformChangeRecord
in interfaceLDIFChangeRecordTransformation
- Parameters:
r
- The LDIF change record to transform.- Returns:
- A copy of the change record with any appropriate transformation
applied, the original change record if no transformations were
necessary, or
null
if the change record should be suppressed.
-
scrambleDN
@Nullable public java.lang.String scrambleDN(@Nullable java.lang.String dn)
Creates a scrambled copy of the provided DN. If the DN contains any components with attributes to be scrambled, then the values of those attributes will be scrambled appropriately. If the DN does not contain any components with attributes to be scrambled, then no changes will be made.- Parameters:
dn
- The DN to be scrambled.- Returns:
- A scrambled copy of the provided DN, or the original DN if no scrambling is required or the provided string cannot be parsed as a valid DN.
-
scrambleDN
@Nullable public DN scrambleDN(@Nullable DN dn)
Creates a scrambled copy of the provided DN. If the DN contains any components with attributes to be scrambled, then the values of those attributes will be scrambled appropriately. If the DN does not contain any components with attributes to be scrambled, then no changes will be made.- Parameters:
dn
- The DN to be scrambled.- Returns:
- A scrambled copy of the provided DN, or the original DN if no scrambling is required.
-
scrambleRDN
@NotNull public RDN scrambleRDN(@NotNull RDN rdn)
Creates a scrambled copy of the provided RDN. If the RDN contains any attributes to be scrambled, then the values of those attributes will be scrambled appropriately. If the RDN does not contain any attributes to be scrambled, then no changes will be made.- Parameters:
rdn
- The RDN to be scrambled. It must not benull
.- Returns:
- A scrambled copy of the provided RDN, or the original RDN if no scrambling is required.
-
scrambleAttribute
@Nullable public Attribute scrambleAttribute(@NotNull Attribute a)
Creates a copy of the provided attribute with its values scrambled if appropriate.- Parameters:
a
- The attribute to scramble.- Returns:
- A copy of the provided attribute with its values scrambled, or the original attribute if no scrambling should be performed.
-
scrambleGeneralizedTime
@Nullable public java.lang.String scrambleGeneralizedTime(@Nullable java.lang.String s)
Scrambles the provided generalized time value. If the provided value can be parsed as a valid generalized time, then the resulting value will be a generalized time in the same format but with the timestamp randomized. The randomly-selected time will adhere to the following constraints:- The range for the timestamp will be twice the size of the current time and the original timestamp. If the original timestamp is within one day of the current time, then the original range will be expanded by an additional one day.
- If the original timestamp is in the future, then the scrambled timestamp will also be in the future. Otherwise, it will be in the past.
- Parameters:
s
- The value to scramble.- Returns:
- The scrambled value.
-
scrambleNumericValue
@Nullable public java.lang.String scrambleNumericValue(@Nullable java.lang.String s)
Scrambles the provided value, which is expected to be largely numeric. Only digits will be scrambled, with all other characters left intact. The first digit will be required to be nonzero unless it is also the last character of the string.- Parameters:
s
- The value to scramble.- Returns:
- The scrambled value.
-
scrambleBinaryValue
@Nullable public byte[] scrambleBinaryValue(@Nullable byte[] value)
Scrambles the provided value, which may contain non-ASCII characters. The scrambling will be performed as follows:- Each lowercase ASCII letter will be replaced with a randomly-selected lowercase ASCII letter.
- Each uppercase ASCII letter will be replaced with a randomly-selected uppercase ASCII letter.
- Each ASCII digit will be replaced with a randomly-selected ASCII digit.
- Each ASCII symbol (all printable ASCII characters not included in one of the above categories) will be replaced with a randomly-selected ASCII symbol.
- Each ASCII control character will be replaced with a randomly-selected printable ASCII character.
- Each non-ASCII byte will be replaced with a randomly-selected non-ASCII byte.
- Parameters:
value
- The value to scramble.- Returns:
- The scrambled value.
-
scrambleEncodedPassword
@Nullable public java.lang.String scrambleEncodedPassword(@Nullable java.lang.String s)
Scrambles the provided encoded password value. It is expected that it will either start with a storage scheme name in curly braces (e.g., "{SSHA256}XrgyNdl3fid7KYdhd/Ju47KJQ5PYZqlUlyzxQ28f/QXUnNd9fupj9g==") or that it will use the authentication password syntax as described in RFC 3112 in which the scheme name is separated from the rest of the password by a dollar sign (e.g., "SHA256$QGbHtDCi1i4=$8/X7XRGaFCovC5mn7ATPDYlkVoocDD06Zy3lbD4AoO4="). In either case, the scheme name will be left unchanged but the remainder of the value will be scrambled.- Parameters:
s
- The encoded password to scramble.- Returns:
- The scrambled value.
-
scrambleJSONObject
@Nullable public java.lang.String scrambleJSONObject(@Nullable java.lang.String s)
Scrambles the provided JSON object value. If the provided value can be parsed as a valid JSON object, then the resulting value will be a JSON object with all field names preserved and some or all of the field values scrambled. If thisAttributeScrambler
was created with a set of JSON fields, then only the values of those fields will be scrambled; otherwise, all field values will be scrambled.- Parameters:
s
- The time value to scramble.- Returns:
- The scrambled value.
-
scrambleString
@Nullable public java.lang.String scrambleString(@Nullable java.lang.String s)
Scrambles the provided string. The scrambling will be performed as follows:- Each lowercase ASCII letter will be replaced with a randomly-selected lowercase ASCII letter.
- Each uppercase ASCII letter will be replaced with a randomly-selected uppercase ASCII letter.
- Each ASCII digit will be replaced with a randomly-selected ASCII digit.
- All other characters will remain unchanged.
- Parameters:
s
- The value to scramble.- Returns:
- The scrambled value.
-
translate
@Nullable public Entry translate(@NotNull Entry original, long firstLineNumber)
Applies some special transformation or filtering to the original Entry.- Specified by:
translate
in interfaceLDIFReaderEntryTranslator
- Parameters:
original
- The original Entry that was read and parsed from the input file.firstLineNumber
- The first line number of the LDIF record corresponding to the read Entry. This is most useful when throwing an LDIFException.- Returns:
- The Entry that should be returned in the call to
LDIFReader.readEntry()
. This can be the original parameter Entry, a newly constructed Entry, ornull
to signal that the provided Entry should be skipped.
-
translate
@Nullable public LDIFChangeRecord translate(@NotNull LDIFChangeRecord original, long firstLineNumber)
Applies some special transformation or filtering to the original change record.- Specified by:
translate
in interfaceLDIFReaderChangeRecordTranslator
- Parameters:
original
- The original change record that was read and parsed from the input file.firstLineNumber
- The first line number of the LDIF change record. This is most useful when throwing anLDIFException
.- Returns:
- The LDIF change record that should be returned in the call to
LDIFReader.readChangeRecord()
. This can be the original parameter change record, a newly constructed change record, ornull
to signal that the provided change record should be skipped.
-
translateEntryToWrite
@Nullable public Entry translateEntryToWrite(@NotNull Entry original)
Applies some special transformation or filtering to the original Entry.- Specified by:
translateEntryToWrite
in interfaceLDIFWriterEntryTranslator
- Parameters:
original
- The original Entry that was to be written.- Returns:
- The Entry that should be written. This can be the original
parameter Entry, a newly-constructed Entry, or
null
to signal that this Entry should not be written. Note, however, that if the original entry provided as a parameter is altered, then the change will be visible to anything that references that entry. If you are not sure about whether changes to the original entry are acceptable, it is recommended that you use theduplicate()
method to create a copy of the original and make the necessary changes to that duplicate.
-
translateChangeRecordToWrite
@Nullable public LDIFChangeRecord translateChangeRecordToWrite(@NotNull LDIFChangeRecord original)
Applies some special transformation or filtering to the original change record.- Specified by:
translateChangeRecordToWrite
in interfaceLDIFWriterChangeRecordTranslator
- Parameters:
original
- The original change record that was to be written.- Returns:
- The change record that should be written. This can be the
original parameter change record, a newly-constructed change
record, or
null
to signal that the change record should not be written. Note, however, that if the original record provided as a parameter is altered, then the change will be visible to anything that references that change record. If you are not sure about whether changes to the original change record are acceptable, it is recommended that you use theduplicate()
method to create a copy of the original and make the necessary changes to that duplicate.
-
-