org.directwebremoting.util
Class IdGenerator

java.lang.Object
  extended by org.directwebremoting.util.IdGenerator

public class IdGenerator
extends java.lang.Object

Code to generate page ids. IdGenerators are expensive to setup so it is suggested that you share instances wherever possible. This action will also enhance security. Much of this code is adapted from org.apache.catalina.session.ManagerBase. Specifically Revision 1.37 which has been unchanged in the past 18 months. I have taken out the /dev/urandom stuff and simplified things to the point where we can audit it to work out what might be broken.

Author:
Joe Walker [joe at getahead dot ltd dot uk]

Field Summary
protected  java.lang.String algorithm
          The message digest algorithm to be used when generating session identifiers.
protected static java.lang.String DEFAULT_ALGORITHM
          The default message digest algorithm to use if we cannot use the requested one.
protected  java.security.MessageDigest digest
          Return the MessageDigest implementation to be used when creating session identifiers.
protected  java.util.Random random
          A random number generator to use when generating session identifiers.
 
Constructor Summary
IdGenerator()
          Seed the random number
 
Method Summary
 java.lang.String generateId(int length)
          Generate and return a new session identifier.
 java.lang.String getAlgorithm()
           
 void setAlgorithm(java.lang.String algorithm)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ALGORITHM

protected static final java.lang.String DEFAULT_ALGORITHM
The default message digest algorithm to use if we cannot use the requested one.

See Also:
Constant Field Values

algorithm

protected java.lang.String algorithm
The message digest algorithm to be used when generating session identifiers. This must be an algorithm supported by the java.security.MessageDigest class on your platform.


random

protected java.util.Random random
A random number generator to use when generating session identifiers.


digest

protected java.security.MessageDigest digest
Return the MessageDigest implementation to be used when creating session identifiers.

Constructor Detail

IdGenerator

public IdGenerator()
Seed the random number

Method Detail

generateId

public java.lang.String generateId(int length)
Generate and return a new session identifier.

Parameters:
length - The number of bytes to generate
Returns:
A new page id string

getAlgorithm

public java.lang.String getAlgorithm()
Returns:
the algorithm

setAlgorithm

public void setAlgorithm(java.lang.String algorithm)
Parameters:
algorithm - the algorithm to set

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object