Skip to content

Commit 0e67410

Browse files
committed
WICKET-7174: DefaultSecureRandomSupplier does not work for FIPS (#1361)
1. Lazy load DefaultSecureRandomSupplier in SecuritySettings.java 2. Lazy load `SecureRandom.getInstance("SHA1PRNG")` in DefaultSecureRandomSupplier.java (cherry picked from commit 5710d7d)
1 parent ef96480 commit 0e67410

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

wicket-core/src/main/java/org/apache/wicket/core/random/DefaultSecureRandomSupplier.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@
3232
*/
3333
public class DefaultSecureRandomSupplier implements ISecureRandomSupplier
3434
{
35-
private SecureRandom random;
36-
37-
public DefaultSecureRandomSupplier()
35+
private static final class Holder
3836
{
39-
try
40-
{
41-
random = SecureRandom.getInstance("SHA1PRNG");
42-
}
43-
catch (NoSuchAlgorithmException e)
37+
private static final SecureRandom INSTANCE;
38+
39+
static
4440
{
45-
throw new WicketRuntimeException(e);
41+
try
42+
{
43+
INSTANCE = SecureRandom.getInstance("SHA1PRNG");
44+
} catch (NoSuchAlgorithmException e) {
45+
throw new WicketRuntimeException(e);
46+
}
4647
}
4748
}
4849

4950
@Override
5051
public SecureRandom getRandom()
5152
{
52-
return random;
53+
return Holder.INSTANCE;
5354
}
5455
}

wicket-core/src/main/java/org/apache/wicket/settings/SecuritySettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SecuritySettings
6666
private ICryptFactory cryptFactory;
6767

6868
/** supplier of random data and SecureRandom */
69-
private ISecureRandomSupplier randomSupplier = new DefaultSecureRandomSupplier();
69+
private ISecureRandomSupplier randomSupplier;
7070

7171
/**
7272
* Whether mounts should be enforced. If {@code true}, requests for a page will be
@@ -146,6 +146,10 @@ public synchronized ICryptFactory getCryptFactory()
146146
*/
147147
public ISecureRandomSupplier getRandomSupplier()
148148
{
149+
if (randomSupplier == null)
150+
{
151+
randomSupplier = new DefaultSecureRandomSupplier();
152+
}
149153
return randomSupplier;
150154
}
151155

0 commit comments

Comments
 (0)