You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ji...@locus.apache.org on 2000/08/23 22:21:50 UTC

cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util SessionIdGenerator.java

jiricka     00/08/23 13:21:50

  Modified:    src/share/org/apache/tomcat/core ContextManager.java
               src/share/org/apache/tomcat/util SessionIdGenerator.java
  Log:
  Allowing the user to specify a random class to be used for generating session ids. By default, java.security.SecureRandom is used, but other classes (e.g. java.util.Random) can be used too, which may improve startup time.
  
  Revision  Changes    Path
  1.121     +16 -0     jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
  retrieving revision 1.120
  retrieving revision 1.121
  diff -u -r1.120 -r1.121
  --- ContextManager.java	2000/08/22 06:10:39	1.120
  +++ ContextManager.java	2000/08/23 20:21:49	1.121
  @@ -302,6 +302,22 @@
   	return parentLoader;
       }
       
  +    /** Get the name of the class to be used for generating random numbers by the
  +     * session id generator. By default this is <code>java.security.SecureRandom</code>.
  +     **/
  +    public String getRandomClass() {
  +        String randomClass = System.getProperty("tomcat.sessionid.randomclass");
  +        return randomClass == null ? "java.security.SecureRandom" : randomClass;
  +    }
  +    
  +    /** Sets the name of the class used for generating random numbers by the
  +     *  session id generator. 
  +     */
  +    public void setRandomClass(String randomClass) {
  +        System.setProperty("tomcat.sessionid.randomclass", randomClass);
  +    }
  +
  +
       // -------------------- Support functions --------------------
       /** Init() is called after the context manager is set up
        *  and configured. It will init all internal components
  
  
  
  1.4       +19 -4     jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java
  
  Index: SessionIdGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SessionIdGenerator.java	2000/06/17 00:24:45	1.3
  +++ SessionIdGenerator.java	2000/08/23 20:21:49	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v 1.3 2000/06/17 00:24:45 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2000/06/17 00:24:45 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/SessionIdGenerator.java,v 1.4 2000/08/23 20:21:49 jiricka Exp $
  + * $Revision: 1.4 $
  + * $Date: 2000/08/23 20:21:49 $
    *
    * ====================================================================
    *
  @@ -89,7 +89,7 @@
        */
       static private int session_count = 0;
       static private long lastTimeVal = 0;
  -    static private java.util.Random randomSource = new java.security.SecureRandom();
  +    static private java.util.Random randomSource;
   
       // MAX_RADIX is 36
       /*
  @@ -118,6 +118,21 @@
       static synchronized public String getIdentifier (String jsIdent)
       {
           StringBuffer sessionId = new StringBuffer();
  +        
  +        if (randomSource == null) {
  +            String className = System.getProperty("tomcat.sessionid.randomclass");
  +            if (className != null) {
  +                try {
  +                    Class randomClass = Class.forName(className);
  +                    randomSource = (java.util.Random)randomClass.newInstance();
  +                }
  +                catch (Exception e) {
  +                    e.printStackTrace();
  +                }
  +            }
  +            if (randomSource == null)
  +                randomSource = new java.security.SecureRandom();
  +        }
   
           // random value ..
           long n = randomSource.nextLong();