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 aRandomsource and encodes them into a string using aBinaryEncoder(Hexby default).
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.commons.codec.BinaryEncoderencoderEncoder used to convert the random bytes in to a string.private RandomrandomRandom number generator.private intsizeOfIdentifierNumber of random bytes in the identifier.
-
Constructor Summary
Constructors Constructor Description RandomIdentifierGenerationStrategy()Constructor.RandomIdentifierGenerationStrategy(int identifierSize)Constructor.RandomIdentifierGenerationStrategy(Random source, int identifierSize, org.apache.commons.codec.BinaryEncoder identifierEncoder)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgenerateIdentifier()Generates an identifier guaranteed to be XML ID safe.StringgenerateIdentifier(boolean xmlSafe)Generates an identifier.
-
-
-
Field Detail
-
random
private final Random random
Random number generator.
-
sizeOfIdentifier
private final int sizeOfIdentifier
Number of random bytes in the identifier.
-
encoder
private final org.apache.commons.codec.BinaryEncoder encoder
Encoder used to convert the random bytes in to a string.
-
-
Constructor Detail
-
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 newSecureRandomand 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 Detail
-
generateIdentifier
@Nonnull @NotEmpty public String generateIdentifier()
Generates an identifier guaranteed to be XML ID safe.- Specified by:
generateIdentifierin interfaceIdentifierGenerationStrategy- Returns:
- the identifier
-
generateIdentifier
@Nonnull @NotEmpty public String generateIdentifier(boolean xmlSafe)
Generates an identifier.- Specified by:
generateIdentifierin interfaceIdentifierGenerationStrategy- Parameters:
xmlSafe- true iff the result must be XML ID safe- Returns:
- the identifier
-
-