Skip to content
Merged
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 @@ -37,7 +37,8 @@
*
*/
public class DigestAuthSupplier implements HttpAuthSupplier {
private static final SecureRandom CNONCE_GENERATOR = new SecureRandom();
private static volatile SecureRandom cnonceGenerator;
private static final Object CNONCE_GENERATOR_LOCK = new Object();

Map<URI, DigestInfo> authInfo = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -117,7 +118,20 @@ private static String getAuthURI(URI currentURI) {
*/
public String createCnonce() {
byte[] bytes = new byte[16];
CNONCE_GENERATOR.nextBytes(bytes);

SecureRandom cg;
// CHECKSTYLE:OFF
// May the Gods of Code Style forgive us these three inner assignments
if ((cg = cnonceGenerator) == null) {
synchronized (CNONCE_GENERATOR_LOCK) {
if ((cg = cnonceGenerator) == null) {
cg = cnonceGenerator = new SecureRandom();
}
}
}
// CHECKSTYLE:ON

cg.nextBytes(bytes);
return StringUtils.toHexString(bytes);
}

Expand Down
Loading