Package org.forgerock.openig.util
Class Randoms
java.lang.Object
org.forgerock.openig.util.Randoms
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)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Generates a random value (cryptographically secure) that can be used in a query parameter value. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
generateSecureRandomBase64UrlEncoded
(int byteLength) Generates a Base64 URL encoded cryptographically secure random value for use as a query parameter value.static String
Returns a cryptographically-secure random value (nevernull
).static String
Returns a cryptographically-secure random value usable as session identifier.
-
Method Details
-
generateSecureRandomValue
Returns a cryptographically-secure random value (nevernull
).The generated value is URL query parameter friendly (base 36: [0-9] + [a-z]).
- Returns:
- a cryptographically-secure random value (never
null
).
-
generateSessionId
Returns a cryptographically-secure random value usable as session identifier. (nevernull
).The generated value is base64 encoded.
- Returns:
- a cryptographically-secure random value (never
null
). - See Also:
-
generateSecureRandomBase64UrlEncoded
Generates a Base64 URL encoded cryptographically secure random value for use as a query parameter value. The ratio of returned length to byte length is approximately 1:1.333 so a byte length of 96 will result in a String that is 128 characters long.- Parameters:
byteLength
- the length of the random bytes used to generate the Base64 URL encoded value.- Returns:
- a Base64 URL encoded cryptographically secure random value.
-