Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Replacing the use of java.util.Random with java.security.SecureRandom #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/main/java/axiom/delauth/token/TokenGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.apache.log4j.Logger;

import java.util.Random;
import java.security.SecureRandom;


public class TokenGenerator {
Expand All @@ -13,11 +13,11 @@ public class TokenGenerator {
private TokenStore tokenStore = new TokenStorePojo();

public String generateToken(String username) {
String token = Integer.toHexString(new Random().nextInt(Integer.MAX_VALUE));
String token = Integer.toHexString(new SecureRandom().nextInt(Integer.MAX_VALUE));

tokenStore.addToken(username, token);

return token;
}

}
}
4 changes: 2 additions & 2 deletions src/main/java/axiom/saml/idp/IdGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.apache.log4j.Logger;

import java.util.Random;
import java.security.SecureRandom;


/**
Expand All @@ -17,7 +17,7 @@ private IdGenerator() {
} // should not be instantiated

public static String generateId() {
String id = "_" + Integer.toHexString(new Random().nextInt(Integer.MAX_VALUE)) + "-" + Integer.toHexString(new Random().nextInt(Integer.MAX_VALUE));
String id = "_" + Integer.toHexString(new SecureRandom().nextInt(Integer.MAX_VALUE)) + "-" + Integer.toHexString(new SecureRandom().nextInt(Integer.MAX_VALUE));
logger.debug("Generated Id: " + id);
return id;
}
Expand Down