Class RandomIdentifierGenerationStrategy

java.lang.Object
net.shibboleth.shared.security.impl.RandomIdentifierGenerationStrategy
All Implemented Interfaces:
IdentifierGenerationStrategy
Direct Known Subclasses:
SecureRandomIdentifierGenerationStrategy

@ThreadSafe 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, or hex-encoding by default.
  • Field Details

    • random

      @Nonnull private final RandomGenerator random
      Random number generator.
    • sizeOfIdentifier

      private final int sizeOfIdentifier
      Number of random bytes in the identifier.
    • encoder

      @Nullable private final org.apache.commons.codec.BinaryEncoder encoder
      Encoder used to convert the random bytes in to a string.
  • Constructor Details

  • Method Details

    • generateIdentifier

      @Nonnull @NotEmpty public String generateIdentifier()
      Generates an identifier guaranteed to be XML ID safe.
      Specified by:
      generateIdentifier in interface IdentifierGenerationStrategy
      Returns:
      the identifier
    • generateIdentifier

      @Nonnull @NotEmpty public String generateIdentifier(boolean xmlSafe)
      Generates an identifier.
      Specified by:
      generateIdentifier in interface IdentifierGenerationStrategy
      Parameters:
      xmlSafe - true iff the result must be XML ID safe
      Returns:
      the identifier
    • encode

      @Nonnull private String encode(@Nonnull byte[] data)
      Perform the specified encoding, or default to hex.
      Parameters:
      data - data to encode
      Returns:
      the encoded string