Constructor and Description |
---|
RecoveryCodeGenerator(SecureRandom secureRandom)
Generates a new CodeUtils which can be used to generate a plethora of
codes suited to fit your needs.
|
RecoveryCodeGenerator(SecureRandom secureRandom,
int retryMaximum)
Generates a new CodeUtils which can be used to generate a plethora of
codes suited to fit your needs.
|
Modifier and Type | Method and Description |
---|---|
String |
generateCode(CodeGeneratorSource alphabet,
int length)
Generates a code of the supplied length, using the provided alphabet as its
source of random characters.
|
List<String> |
generateCodes(int numCodes,
CodeGeneratorSource alphabet,
boolean allowDuplicates)
Generate a set of codes using the provided alphabet of the default length.
|
List<String> |
generateCodes(int numCodes,
CodeGeneratorSource alphabet,
int length,
boolean allowDuplicates)
Generate a set of codes using the provided alphabet of the provided length.
|
String |
generateDelimitedCode(CodeGeneratorSource alphabet,
char delimiter,
int... groups)
Generates a code of the supplied length, using the provided alphabet as its
source of random characters.
|
String[] |
generateDelimitedCodes(int numCodes,
CodeGeneratorSource alphabet,
char delimiter,
boolean allowDuplicates,
int... groups)
Generates a code of the supplied length, using the provided alphabet as its
source of random characters.
|
String[] |
generateDelimitedCodesWithSpecifics(int numCodes,
CodeGeneratorSource alphabet,
char delimiter,
Map<Integer,Character> specifics,
boolean allowDuplicates,
int... groups)
Generates a code of the supplied length, using the provided alphabet as its
source of random characters.
|
String |
generateDelimitedCodeWithSpecifics(CodeGeneratorSource alphabet,
char delimiter,
Map<Integer,Character> specifics,
int... groups)
Generates a code of the supplied length, using the provided alphabet as its
source of random characters.
|
public RecoveryCodeGenerator(SecureRandom secureRandom, int retryMaximum)
secureRandom
- The SecureRandom
instance to use when selecting
characters from an alphabet set. Must not be null.retryMaximum
- If duplicate codes are not allowed, this is the number of times
we will attempt to generate another code upon discovering a collision.@Inject public RecoveryCodeGenerator(SecureRandom secureRandom)
RecoveryCodeGenerator.DEFAULT_RETRIES
as its number of retries before failing.secureRandom
- The SecureRandom
instance to use when selecting
characters from an alphabet set. Must not be null.public String generateCode(CodeGeneratorSource alphabet, int length)
alphabet
- The alpha to use from which to pick characters. Must not be null.length
- The size of the produced codes. Must be greater than 0.public String generateDelimitedCode(CodeGeneratorSource alphabet, char delimiter, int... groups)
groups
, with a delimiter
between them.alphabet
- The alpha to use from which to pick characters. Must not be null.groups
- The groupings of characters. For example, {4, 4}
will produce two sets
of four characters with a delimiter
between them. Must not be null. Must have at least
one entry. Entries must be greater than 0.delimiter
- The character to use between each of the groups.public String generateDelimitedCodeWithSpecifics(CodeGeneratorSource alphabet, char delimiter, Map<Integer,Character> specifics, int... groups)
groups
, with a delimiter
between them.
The provided specifics map can then be used to replace individual character indexes with a
specific character.alphabet
- The alpha to use from which to pick characters. Must not be null.groups
- The groupings of characters. For example, {4, 4}
will produce two sets
of four characters with a delimiter
between them. Must not be null. Must have at least
one entry. Entries must be greater than 0.delimiter
- The character to use between each of the groups. Must not be null.specifics
- A map used to specify characters to use at a given location.public List<String> generateCodes(int numCodes, CodeGeneratorSource alphabet, boolean allowDuplicates)
numCodes
- The number of codes to generate. Must be greater than 0.alphabet
- The alphabet to use from which to select characters. Must not be null.allowDuplicates
- Whether to allow duplicates in the result set.CodeException
- if duplicate codes were produced, disallowed and the number of retries was exceeded.public List<String> generateCodes(int numCodes, CodeGeneratorSource alphabet, int length, boolean allowDuplicates)
numCodes
- Number of recovery codes to generate. Must be greater than 0.alphabet
- The alphabet to use from which to select characters. Must not be null.length
- The length of produced codes. Must be greater than 0.allowDuplicates
- Whether or not to allow duplicates in the result set.CodeException
- if duplicate codes were produced, disallowed and the number of retries was exceeded.public String[] generateDelimitedCodes(int numCodes, CodeGeneratorSource alphabet, char delimiter, boolean allowDuplicates, int... groups)
groups
, with a delimiter
between them.numCodes
- Number of recovery codes to generate. Must be greater than 0.alphabet
- The alphabet to use from which to select numbers. Must not be null.groups
- The groupings of lengths of characters. For example, {4, 4}
will produce two set
of four characters with a delimiter
between them. Must not be null. Must have at least
one entry. Entries must be greater than 0.delimiter
- The character to use between each of the groups.allowDuplicates
- Whether or not to allow duplicates in the result set.CodeException
- if duplicate codes were produced, disallowed and the number of retries was exceeded.public String[] generateDelimitedCodesWithSpecifics(int numCodes, CodeGeneratorSource alphabet, char delimiter, Map<Integer,Character> specifics, boolean allowDuplicates, int... groups)
groups
, with a delimiter
between them.
The provided specifics map can then be used to replace individual character indexes with a
specific character.numCodes
- The number of codes to generate. Must be greater than 0.alphabet
- The alphabet to use from which to pick characters. Must not be null.groups
- The groupings of lengths of characters. For example, {4, 4}
will produce two sets
of four characters with a delimiter
between them. Must not be null. Must have at least
one entry. Entries must be greater than 0.delimiter
- The character to use between each of the groups.specifics
- A map used to specify characters to use at a given location.allowDuplicates
- Whether to allow duplicate codes.CodeException
- if duplicate codes were produced, disallowed and the number of retries was exceeded.Copyright © 2010-2018, ForgeRock All Rights Reserved.