Package net.shibboleth.shared.security.impl

# 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` (`Hex` by default).

## Nested Class Summary

## Nested classes/interfaces inherited from interface net.shibboleth.shared.security.IdentifierGenerationStrategy

`IdentifierGenerationStrategy.ParameterSpec, IdentifierGenerationStrategy.ProviderType`

## Field Summary

Fields
Modifier and Type
Field
Description
`private final org.apache.commons.codec.BinaryEncoder`
`encoder`
Encoder used to convert the random bytes in to a string.
`private final RandomGenerator`
`random`
Random number generator.
`private final int`
`sizeOfIdentifier`
Number of random bytes in the identifier.

## Constructor Summary

Constructors
Constructor
Description
`RandomIdentifierGenerationStrategy()`
Default constructor.
`RandomIdentifierGenerationStrategy(IdentifierGenerationStrategy.ParameterSpec params)`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`String`
`generateIdentifier()`
Generates an identifier guaranteed to be XML ID safe.
`String`
`generateIdentifier(boolean xmlSafe)`
Generates an identifier.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### random

@Nonnull private final RandomGenerator random
Random number generator.

### sizeOfIdentifier

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

### encoder

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

## Constructor Details

### RandomIdentifierGenerationStrategy

public RandomIdentifierGenerationStrategy()
Default 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(@Nonnull IdentifierGenerationStrategy.ParameterSpec params) throws InvalidAlgorithmParameterException
Constructor.

Parameters:
  `params` - parameter object, must be a `RandomIdentifierParameterSpec`
Throws:
  `InvalidAlgorithmParameterException` - if the parameters are invalid

## 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