Class Randoms

java.lang.Object
org.forgerock.openig.util.Randoms

public final class Randoms extends Object
The Randoms utility class offers methods to generate random values.

It provides both implementation method(s) and functional interface(s) so that it's easy, in the code, to convey the meaning that random values with specific constraints are required.

In other words, a method can indicate it needs a random value to be used in a URL by having a dependency on Randoms.UrlFriendlyRandomStringGenerator. Example:


   private URI addNonceToUri(final URI original, final UrlFriendlyRandomStringGenerator generator) { ... }
 

From a usage perspective, a simple method reference can be used to provide the generator function:


 URI modified = addNonceToUri(uri, Randoms::generateSecureRandomValue)
 
  • Method Details

    • generateSecureRandomValue

      public static String generateSecureRandomValue()
      Returns a cryptographically-secure random value (never null).

      The generated value is URL query parameter friendly (base 36: [0-9] + [a-z]).

      Returns:
      a cryptographically-secure random value (never null).
    • generateSessionId

      public static String generateSessionId()
      Returns a cryptographically-secure random value usable as session identifier. (never null).

      The generated value is base64 encoded.

      Returns:
      a cryptographically-secure random value (never null).
      See Also: