Class RandomIdentifierGenerationStrategy
java.lang.Object
net.shibboleth.utilities.java.support.security.impl.RandomIdentifierGenerationStrategy
- All Implemented Interfaces:
IdentifierGenerationStrategy
- Direct Known Subclasses:
SecureRandomIdentifierGenerationStrategy
public class RandomIdentifierGenerationStrategy
extends Object
implements IdentifierGenerationStrategy
Generates a random number of bytes via a
Random
source and encodes them into a string using a
BinaryEncoder
(Hex
by default).-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.commons.codec.BinaryEncoder
Encoder used to convert the random bytes in to a string.private final Random
Random number generator.private final int
Number of random bytes in the identifier. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.RandomIdentifierGenerationStrategy
(int identifierSize) Constructor.RandomIdentifierGenerationStrategy
(Random source, int identifierSize, org.apache.commons.codec.BinaryEncoder identifierEncoder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionGenerates an identifier guaranteed to be XML ID safe.generateIdentifier
(boolean xmlSafe) Generates an identifier.
-
Field Details
-
random
Random number generator. -
sizeOfIdentifier
private final int sizeOfIdentifierNumber of random bytes in the identifier. -
encoder
private final org.apache.commons.codec.BinaryEncoder encoderEncoder used to convert the random bytes in to a string.
-
-
Constructor Details
-
RandomIdentifierGenerationStrategy
public RandomIdentifierGenerationStrategy()Constructor. Initializes the random number source to a newSecureRandom
, size of identifier is set to 16 bytes, and the encoder is set to aHex
. -
RandomIdentifierGenerationStrategy
public RandomIdentifierGenerationStrategy(int identifierSize) Constructor. Initializes the random number source to a newSecureRandom
and the encoder is set to aHex
.- Parameters:
identifierSize
- number of random bytes in identifier
-
RandomIdentifierGenerationStrategy
public RandomIdentifierGenerationStrategy(@Nonnull Random source, int identifierSize, @Nonnull org.apache.commons.codec.BinaryEncoder identifierEncoder) Constructor.- Parameters:
source
- source of random bytesidentifierSize
- number of random bytes in the identifieridentifierEncoder
- encoder used to convert random bytes to string identifier
-
-
Method Details
-
generateIdentifier
Generates an identifier guaranteed to be XML ID safe.- Specified by:
generateIdentifier
in interfaceIdentifierGenerationStrategy
- Returns:
- the identifier
-
generateIdentifier
Generates an identifier.- Specified by:
generateIdentifier
in interfaceIdentifierGenerationStrategy
- Parameters:
xmlSafe
- true iff the result must be XML ID safe- Returns:
- the identifier
-