FileDocCategorySizeDatePackage
SessionUtils.javaAPI DocApache Axis 1.43390Sat Apr 22 18:57:28 BST 2006org.apache.axis.utils

SessionUtils

public class SessionUtils extends Object
Code borrowed from AuthenticatorBase.java for generating a secure id's.

Fields Summary
protected static Log
log
Field log
protected static final int
SESSION_ID_BYTES
The number of random bytes to include when generating a session identifier.
protected static Random
random
A random number generator to use when generating session identifiers.
protected static String
randomClass
The Java class name of the random number generator class to be used when generating session identifiers.
private static String
thisHost
Host name/ip.
Constructors Summary
Methods Summary
public static synchronized java.lang.LonggenerateSession()
Generate and return a new session identifier.

return
a new session.

        return new Long(getRandom().nextLong());
    
public static synchronized java.lang.StringgenerateSessionId()
Generate and return a new session identifier.

return
a new session id


                     
         
        // Generate a byte array containing a session identifier
        byte bytes[] = new byte[SESSION_ID_BYTES];

        getRandom().nextBytes(bytes);

        // Render the result as a String of hexadecimal digits
        StringBuffer result = new StringBuffer();

        for (int i = 0; i < bytes.length; i++) {
            byte b1 = (byte) ((bytes[i] & 0xf0) >> 4);
            byte b2 = (byte) (bytes[i] & 0x0f);

            if (b1 < 10) {
                result.append((char) ('0" + b1));
            } else {
                result.append((char) ('A" + (b1 - 10)));
            }
            if (b2 < 10) {
                result.append((char) ('0" + b2));
            } else {
                result.append((char) ('A" + (b2 - 10)));
            }
        }
        return (result.toString());
    
private static synchronized java.util.RandomgetRandom()
Return the random number generator instance we should use for generating session identifiers. If there is no such generator currently defined, construct and seed a new one.

return
Random object

        if (random == null) {
            try {
                Class clazz = Class.forName(randomClass);
                random = (Random) clazz.newInstance();
            } catch (Exception e) {
                random = new java.util.Random();
            }
        }
        return (random);