net.shibboleth.utilities.java.support.security
Class RandomIdentifierGenerationStrategy

java.lang.Object
  extended by net.shibboleth.utilities.java.support.security.RandomIdentifierGenerationStrategy
All Implemented Interfaces:
IdentifierGenerationStrategy

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
private  org.apache.commons.codec.BinaryEncoder encoder
          Encoder used to convert the random bytes in to a string.
private  Random random
          Random number generator.
private  int sizeOfIdentifier
          Number of random bytes in the identifier.
 
Constructor Summary
RandomIdentifierGenerationStrategy()
          Constructor.
RandomIdentifierGenerationStrategy(int identifierSize)
          Constructor.
RandomIdentifierGenerationStrategy(Random source, int identifierSize, org.apache.commons.codec.BinaryEncoder identifierEncoder)
          Constructor.
 
Method Summary
 String generateIdentifier()
          Generates an identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 new SecureRandom, size of identifier is set to 16 bytes, and the encoder is set to a Hex.


RandomIdentifierGenerationStrategy

public RandomIdentifierGenerationStrategy(int identifierSize)
Constructor. Initializes the random number source to a new SecureRandom and the encoder is set to a Hex.

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 bytes
identifierSize - number of random bytes in the identifier
identifierEncoder - encoder used to convert random bytes to string identifier
Method Detail

generateIdentifier

@Nonnull
public String generateIdentifier()
Generates an identifier.

Specified by:
generateIdentifier in interface IdentifierGenerationStrategy
Returns:
the identifier


Copyright © 1999-2012. All Rights Reserved.