Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
*/
public class DefaultSecureRandomSupplier implements ISecureRandomSupplier
{
private SecureRandom random;

public DefaultSecureRandomSupplier()
private static final class Holder
{
try
{
random = SecureRandom.getInstance("SHA1PRNG");
}
catch (NoSuchAlgorithmException e)
private static final SecureRandom INSTANCE;

static
{
throw new WicketRuntimeException(e);
try
{
INSTANCE = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new WicketRuntimeException(e);
}
}
}

@Override
public SecureRandom getRandom()
{
return random;
return Holder.INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class SecuritySettings
private ICryptFactory cryptFactory;

/** supplier of random data and SecureRandom */
private ISecureRandomSupplier randomSupplier = new DefaultSecureRandomSupplier();
private ISecureRandomSupplier randomSupplier;

/**
* Whether mounts should be enforced. If {@code true}, requests for a page will be
Expand Down Expand Up @@ -139,6 +139,10 @@ public synchronized ICryptFactory getCryptFactory()
*/
public ISecureRandomSupplier getRandomSupplier()
{
if (randomSupplier == null)
{
randomSupplier = new DefaultSecureRandomSupplier();
}
return randomSupplier;
}

Expand Down