costin 00/12/26 15:26:19
Modified: src/share/org/apache/tomcat/modules/session
SimpleSessionStore.java
src/share/org/apache/tomcat/session
ServerSessionManager.java
src/share/org/apache/tomcat/util SessionIdGenerator.java
Log:
Removed dependency on system property, the server option will be used.
( if anyone prefers to use system properties, it is easy to add an
"integration" module that will set context properties based on system
properties. )
Revision Changes Path
1.5 +32 -7
jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SimpleSessionStore.java
Index: SimpleSessionStore.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/session/SimpleSessionStore.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SimpleSessionStore.java 2000/11/30 06:17:12 1.4
+++ SimpleSessionStore.java 2000/12/26 23:26:15 1.5
@@ -62,6 +62,7 @@
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
+import java.util.Random;
import org.apache.tomcat.util.*;
import org.apache.tomcat.util.threads.*;
import org.apache.tomcat.core.*;
@@ -93,7 +94,11 @@
int checkInterval = 60;
int maxActiveSessions = -1;
- String randomClass=null;
+ String randomClassName=null;
+ // creating a Random is very expensive, make sure we reuse
+ // instances ( keyed by class name - different contexts can use different
+ // random sources
+ static Hashtable randoms=new Hashtable();
public SimpleSessionStore() {
}
@@ -114,9 +119,11 @@
}
public final void setRandomClass(String randomClass) {
- this.randomClass=randomClass;
- System.getProperties().
- put(ContextManager.RANDOM_CLASS_PROPERTY, randomClass);
+ this.randomClassName=randomClass;
+ if( null == randoms.get( randomClassName) ) {
+ randoms.put( randomClassName,
+ createRandomClass( randomClassName ));
+ }
}
@@ -234,7 +241,8 @@
}
//-------------------- Tomcat context events --------------------
-
+
+
/** Init session management stuff for this context.
*/
public void contextInit(Context ctx) throws TomcatException {
@@ -244,6 +252,9 @@
if( sm == null ) {
sm=new ServerSessionManager();
ctx.getContainer().setNote( manager_note, sm );
+ if( randomClassName==null )
+ setRandomClass("java.security.SecureRandom" );
+ sm.setRandomSource( (Random)randoms.get( randomClassName ));
sm.setMaxInactiveInterval( (long)ctx.getSessionTimeOut() *
60 * 1000 );
}
@@ -279,7 +290,21 @@
private ServerSessionManager getManager( Context ctx ) {
return (ServerSessionManager)ctx.getContainer().getNote(manager_note);
}
-
-
+ private Random createRandomClass( String s ) {
+ Random randomSource=null;
+ String className = s;
+ 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();
+ return randomSource;
+ }
+
}
1.15 +6 -3
jakarta-tomcat/src/share/org/apache/tomcat/session/ServerSessionManager.java
Index: ServerSessionManager.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/session/ServerSessionManager.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ServerSessionManager.java 2000/12/07 19:52:46 1.14
+++ ServerSessionManager.java 2000/12/26 23:26:16 1.15
@@ -66,14 +66,13 @@
import org.apache.tomcat.util.collections.SimplePool;
import org.apache.tomcat.util.threads.*;
import org.apache.tomcat.helper.*;
-import org.apache.tomcat.core.*;
import org.apache.tomcat.util.log.*;
/**
*
*
*/
-public final class ServerSessionManager
+public class ServerSessionManager
{
protected Log loghelper = new Log("tc_log", this);
@@ -113,7 +112,11 @@
public Expirer getExpirer() {
return expirer;
}
-
+
+ public void setRandomSource( Random r ) {
+ randomSource=r;
+ }
+
// ------------------------------------------------------------- Properties
public int getMaxActiveSessions() {
1.7 +16 -35
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SessionIdGenerator.java 2000/11/02 00:42:57 1.6
+++ SessionIdGenerator.java 2000/12/26 23:26:18 1.7
@@ -87,7 +87,6 @@
*/
static private int session_count = 0;
static private long lastTimeVal = 0;
- static private java.util.Random globalRandomSource;
// MAX_RADIX is 36
/*
@@ -118,26 +117,8 @@
{
StringBuffer sessionId = new StringBuffer();
if( randomSource==null)
- randomSource= globalRandomSource;
+ throw new RuntimeException( "No random source " );
- 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();
-
- globalRandomSource = randomSource;
- }
-
// random value ..
long n = randomSource.nextLong();
if (n < 0) n = -n;
@@ -176,21 +157,21 @@
return sessionId.toString();
}
- static synchronized public String getIdentifier (String jsIdent)
- {
- return getIdentifier( globalRandomSource, jsIdent);
- }
+// static synchronized public String getIdentifier (String jsIdent)
+// {
+// return getIdentifier( globalRandomSource, jsIdent);
+// }
- static synchronized public String getIdentifier ()
- {
- return getIdentifier( globalRandomSource, null);
- }
+// static synchronized public String getIdentifier ()
+// {
+// return getIdentifier( globalRandomSource, null);
+// }
- public static synchronized String generateId(Random randomSource) {
- return getIdentifier(randomSource, null);
- }
-
- public static synchronized String generateId() {
- return getIdentifier(globalRandomSource, null);
- }
+// public static synchronized String generateId(Random randomSource) {
+// return getIdentifier(randomSource, null);
+// }
+
+// public static synchronized String generateId() {
+// return getIdentifier(globalRandomSource, null);
+// }
}