mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	replace Random with SecureRandom (#5966)
Co-authored-by: Daan Hoogland <dahn@onecht.net>
This commit is contained in:
		
							parent
							
								
									85ced4447b
								
							
						
					
					
						commit
						3fc4ef478d
					
				| @ -17,10 +17,10 @@ | |||||||
| package com.cloud.projects; | package com.cloud.projects; | ||||||
| 
 | 
 | ||||||
| import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||||
|  | import java.security.SecureRandom; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Optional; | import java.util.Optional; | ||||||
| import java.util.Random; |  | ||||||
| import java.util.TimeZone; | import java.util.TimeZone; | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
| @ -106,6 +106,8 @@ import org.apache.commons.lang3.BooleanUtils; | |||||||
| public class ProjectManagerImpl extends ManagerBase implements ProjectManager, Configurable { | public class ProjectManagerImpl extends ManagerBase implements ProjectManager, Configurable { | ||||||
|     public static final Logger s_logger = Logger.getLogger(ProjectManagerImpl.class); |     public static final Logger s_logger = Logger.getLogger(ProjectManagerImpl.class); | ||||||
| 
 | 
 | ||||||
|  |     private static final SecureRandom secureRandom = new SecureRandom(); | ||||||
|  | 
 | ||||||
|     @Inject |     @Inject | ||||||
|     private DomainDao _domainDao; |     private DomainDao _domainDao; | ||||||
|     @Inject |     @Inject | ||||||
| @ -1349,10 +1351,9 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager, C | |||||||
| 
 | 
 | ||||||
|     public static String generateToken(int length) { |     public static String generateToken(int length) { | ||||||
|         String charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |         String charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||||||
|         Random rand = new Random(System.currentTimeMillis()); |  | ||||||
|         StringBuffer sb = new StringBuffer(); |         StringBuffer sb = new StringBuffer(); | ||||||
|         for (int i = 0; i < length; i++) { |         for (int i = 0; i < length; i++) { | ||||||
|             int pos = rand.nextInt(charset.length()); |             int pos = secureRandom.nextInt(charset.length()); | ||||||
|             sb.append(charset.charAt(pos)); |             sb.append(charset.charAt(pos)); | ||||||
|         } |         } | ||||||
|         return sb.toString(); |         return sb.toString(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user