sunlabs.brazil.handler

Class SimpleSessionHandler

public class SimpleSessionHandler extends Object implements Handler

Handler for creating browser sessions based on information found in the http request. This handler provides a single session-id that may be used by other handlers.

The following server properties are used:

prefix, suffix, glob, match
Specify the URL that triggers this handler (See {@link MatchString}).
session
The name of the request property that the Session ID will be stored in, to be passed to downstream handlers. The default value is "SessionID". If the property already exists, and is not empty, no session will be defined (unless force=true).
extract
If specified, a string to use as the session-id. ${...} values will be searched for first in the HTTP header values, and then in the request properties.

In addition to the actual HTTP headers, the pseudo http headers ipaddress, url, method, and query are made available for ${...} substitutions.

re
If specified, a regular expression that the extracted data must match. if it doesn't match, no session id is installed. The default is ".", which matches any non-empty string. If the first character is "!" then the sense of the match is inverted, But only for determining whether a match "succeeded" or not. no sub-matches may be used in computing the key value in this case.
value
The value of the session ID. May contain & or \n (n=0,1,2...) constructs to substitute matched sub-expressions of re. The default is "&" , which uses the entire string "extract" as the session id. ${...} are substituted (but not \'s) for value before looking for '\n' sequences that are part of the regular expression matches.
digest
If set, the "value" is replaced by the base64 encoding of the MD5 checksum of value.
force
If set (to anything), a session ID is set even if one already exists.
If no options are provided, the client's IP address is used as the session ID.

Examples:

Pick the session based on the browser
 [prefix].extract=${user-agent}
 [prefix].re=.*(Netscape|Lynx|MSIE).*
 [prefix].value=\\1
 
This is similar to the "old" behavior.
 [prefix].extract=${user-agent}${ipaddress}
 [prefix].digest=true
 
Look for a special authorization token, and set a request property to the value
 [prefix].extract=${Authorization}
 [prefix].re=code:([0-9]+)
 [prefix].value=id\\1
 

Version: @(#)SimpleSessionHandler.java 2.5

Author: Stephen Uhler

Field Summary
Regexpregexp
StringvalueTemplate
Method Summary
booleaninit(Server server, String prefix)
booleanrespond(Request request)

Field Detail

regexp

public Regexp regexp

valueTemplate

public String valueTemplate

Method Detail

init

public boolean init(Server server, String prefix)

respond

public boolean respond(Request request)