[A late followup - where did those reply notifications go...? ;-)]
wglass wrote:
Code:
// no session? assume this is being run for testing purposes and there is no
// simultaneous sessions
if (getRequest() == null)
return Boolean.TRUE;
else {
HttpSession session = getRequest().getSession();
Do you mean to use the "testing purposes" branch when there is no request or no session? (The comment and code are sort of contradictory.)
If it is for the case of no request all is fine as this branch would never trigger during normal webapp runtime. But if you actually mean to test for no session, then you have a Denial of Service vulnerability in this code as this branch would trigger for all requests from new clients that haven't yet had a session created for them.
The Denial of Service problem is that those clients will all be synchronized on the same object (the shared constant object Boolean.TRUE) and only one of them can execute at a time. If one of the clients for some reason stops communicating with your server (there are bugs in IE that can cause this) while holding the lock, all other new clients will have to wait for your server to timeout the hanging connection. Depending on your server, this timeout may be set to anything between 30 secs and infinite.
Also, be aware that the call
HttpSession session = getRequest().getSession();
will create the session if it doesn't exist. If this is what you want all is fine, but if you have code paths in your server that do not rely on the session, and you don't want to create unnecessary sessions, consider using getSession(false) instead.
BTW: I like the dual-check thingie. It's nice to wait with acquiring the container-wide lock until it's absolutely necessary!