replace Random with SecureRandom (#5966)

Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
dahn 2022-02-09 16:38:33 +01:00 committed by GitHub
parent 85ced4447b
commit 3fc4ef478d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,10 +17,10 @@
package com.cloud.projects;
import java.io.UnsupportedEncodingException;
import java.security.SecureRandom;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.Executors;
@ -106,6 +106,8 @@ import org.apache.commons.lang3.BooleanUtils;
public class ProjectManagerImpl extends ManagerBase implements ProjectManager, Configurable {
public static final Logger s_logger = Logger.getLogger(ProjectManagerImpl.class);
private static final SecureRandom secureRandom = new SecureRandom();
@Inject
private DomainDao _domainDao;
@Inject
@ -1349,10 +1351,9 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager, C
public static String generateToken(int length) {
String charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random rand = new Random(System.currentTimeMillis());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
int pos = rand.nextInt(charset.length());
int pos = secureRandom.nextInt(charset.length());
sb.append(charset.charAt(pos));
}
return sb.toString();