You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2009/09/16 22:26:32 UTC

Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alberto,

Please post to the list, rather than writing to me directly.

On 9/16/2009 1:19 PM, atroiano@infomedica.it wrote:
> i' am lookng for a way to resume Tomcat timed-out sessions after a re-logon.
> 
> So i found this interesting thread where you wrote:
> 
> "If you want users to be able to resume their sessions after a
>  session timeout, you need to provide enough information in the request
>  to either restore the session state or ..."
> 
> That is exactly what i am looking for.
> 
> Please may you explain me what information i have to provide in the
> request? Or (better) may you send me a sample code or an url where i can
> found more documentation about this?

This is a question that you will have to answer: what information is
absolutely necessary for you to resume a user interaction in-progress?
Whatever that is, you'll need to include that information in every
single link that a user can click on (or in every form they can submit).

There is no tutorial for how to do this, because it's dead simple: just
determine what information is required to continue (after a re-login)
and ensure that information is available to every request.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqxSfgACgkQ9CaO5/Lv0PDZCACgldPOfYnvnbI38FtQzMKelkUG
dOcAn2bD3HjmpGxcLj2EH1YSPES2UzOF
=TmrC
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alberto,

On 9/18/2009 7:42 AM, atroiano wrote:
> But seems to me that the old session non more exists at this point of the
> request flow. Is this true?

Correct: by the time you can detect a new session, the old session is
totally gone.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqzrf8ACgkQ9CaO5/Lv0PChdQCdHk7dNF384dqp13cwf75+eua1
PWQAni9LlasXWE0byaviZjrZnPeGaj9t
=zpcv
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

Posted by atroiano <at...@infomedica.it>.

Thanks to Mark and Chris for all suggestions.
I thing that a will follow th Chris suggestion to re-architect my session.

I was attracted by this piece of code in

Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem
lynckmeister
Wed, 11 Feb 2009 06:32:43 -0800

public class SessionTimeoutFilter implements Filter {

        private final Log logger = 
LogFactory.getLog(SessionTimeoutFilter.class);

        private String timeoutPage = "timeout.html";

        public void init(FilterConfig filterConfig) throws ServletException
{
        }

        public void doFilter(ServletRequest request, ServletResponse
response,
                        FilterChain filterChain) throws IOException, 
ServletException {

                if ((request instanceof HttpServletRequest)
                                && (response instanceof
HttpServletResponse)) {
                        HttpServletRequest httpServletRequest = 
(HttpServletRequest) request;
                        HttpServletResponse httpServletResponse = 
(HttpServletResponse) response;
                        
                        
                        // is session expired control required for this
request?
                        if 
(isSessionControlRequiredForThisResource(httpServletRequest)) {
                                String requestedID = 
httpServletRequest.getRequestedSessionId();
                                
                                // is session invalid?
                                HttpSession session = 
httpServletRequest.getSession();
                                String sID = session.getId();
                                String nochmalID = 
httpServletRequest.getQueryString();
                                
                                // ok this is allways false , means the
session 
is allways valid. sure
it is, but its a new one ! 
                                boolean isSessionInValid = (requestedID != 
null)&&
!httpServletRequest.isRequestedSessionIdValid();
                                Object testObject = 
session.getAttribute("ISVALID");
                                
                                // here I tried some things... the 
isSessionInValid flag doesnt help b/c
the session is allways valid
                                // the testObject is allways null b/c if the 
user comes from the
loginpage the user is not set in the first time
                                // with the code like this, we're allways 
redirected in an constant
loop.
                                // besides that I think redirection is not
the 
right way to handle , I
mean, 
                                // i feel the right solution would recognize 
that the session is not in
a proper state and than 
                                // delete the request wich allways causes in 
that crash. but how? and
wich restored information exactly is the wrong one ?
                                if (testObject == null /*&&
isSessionInValid*/ 
) {
                                        String timeoutUrl = 
httpServletRequest.getContextPath()
                                                        + "/" + 
getTimeoutPage();
                                        logger
                                                        .info("session is 
invalid! redirecting to timeoutpage : "
                                                                        + 
timeoutUrl);


and in particular:

                String requestedID =
httpServletRequest.getRequestedSessionId();
                                
                HttpSession session = httpServletRequest.getSession();
                String sID = session.getId();

so i thought that was possible to 'trigger' a re-logon after timeout plus
the reference of both expired session (requestedID) and new session (sID);
if there was a way to copy some attributes from the old session to the new
one i solved my problem.

But seems to me that the old session non more exists at this point of the
request flow. Is this true?

Alberto.

 

-- 
View this message in context: http://www.nabble.com/Re%3A-Tomcat-Realm-Auto-Relogin-after-Session-Timeout-Problem-tp25479941p25507329.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mark,

On 9/17/2009 4:56 AM, Mark Thomas wrote:
> atroiano wrote:
>>
>> Is it possible?
> 
> The way you describe? No.

+1

> If you want this then you have a couple of options:
> a) Do what Chris said and pass state back and forth in the request/response

More specifically, architect your session such that a few pieces of
information can re-create the session state, rather than having to
encode /all/ session state in the URL (otherwise, you'd never need the
session, now, would you?).

Here is a concrete example: we deliver questionnaires on-line to
respondents. If their session times out in the middle of taking a
questionnaire, we want them to be able to resume right where they were.
We put the "id" of the questionnaire they are taking right into the URLs
of any links, and into any forms they can submit (answering a question
submits a form, so usually we're talking about POST parameters here).

If the session times out, the next request (after successful
authentication, that is) will have nothing available but the
questionnaire id. The code that manages the questionnaire will look for
the session objects, and, not finding them, will take the id from the
request, reconstruct everything in the session necessary to continue the
questionnaire in-progress (because the state of the /questionnaire/, not
the session itself, is stored in our database), and then resume the
questionnaire.

So, although we have a bunch of information stored in the session in
order to deliver the questionnaire quickly, the disappearance of the
data in the session is tolerable: we simply recover by re-building the
session information given that one special request parameter.

Of course, you have to architect your application to work this way.
There is no special configuration option for Tomcat (nor any other app
server for that matter) that can simple recover your session for you
after it expires.

> b) Buy more memory and have longer session expiration times
> c) Look into using the persistent session manager

There's another option if you want drop-in session recovery. It's a
giant hack, won't work except under the best of circumstances, and
probably counts as bad design (it IS a giant hack), but you could:

1. Make sure everything in your session is Serializable
   (always a good thing)
2. Make sure every URL you use is run through response.encodeURL()
   (including form actions!)
3. Write a filter that does the following:

   a. Wraps the response in a special subclass of
      HttpServletResponseWrapper (see below)
   b. Checks for the presence of a session, then checks the session
      for a magic attribute (say, "SESSION_CONFIGURED" or whatever)
   c. If the magic attribute does not exist, recovers the session
      (see below)
   d. Calls the next filter in the chain

4. Write an HttpServletResponseWrapper that overrides encodeURL
   and encodeRedirectURL to do the following:

   a. Serialize all session attributes to a GzipOutputStream,
      then encrypt them using some decent encryption algorithm
      (such as 3DES, Blowfish, etc.), then add this data to the
      URL in a unique parameter like SESSION or whatever.

Session recovery is simple: just decrypt the SESSION request parameter,
deserialize the data, and shove it into the session. Instant session
recovery.

Here are some potential problems:

* See #1 and #2 above
* If you have a lot of session data, you may exceed the URL length limit
* Performance will suffer due to all that encryption being done for
  every URL you generate

But, if you have small session data, this might work.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkqyZVcACgkQ9CaO5/Lv0PB8QgCfVfRlAYQfmq/OTwXrF5JNdCOA
Rv0AnRHcv6bA6B+A+bGl8/Dpb2RDmepr
=xUe9
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

Posted by Mark Thomas <ma...@apache.org>.
atroiano wrote:
> 
> Christopher Schultz-2 wrote:
>>
>> This is a question that you will have to answer: what information is
>> absolutely necessary for you to resume a user interaction in-progress?
>> Whatever that is, you'll need to include that information in every
>> single link that a user can click on (or in every form they can submit).
>>
> 
> 
> The problem is that to resume a user interaction in-progress  after a
> re-login
> I need informations binded as attributes in the expired session.
> After a re-login I would like to 'resume' old session instead of to use e
> new empty one.
> 
> Is it possible?

The way you describe? No.

If you want this then you have a couple of options:
a) Do what Chris said and pass state back and forth in the request/repsonse
b) Buy more memory and have longer session expiration times
c) Look into using the persistent session manager

Mark




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Tomcat Realm Auto-Relogin after Session-Timeout Problem

Posted by atroiano <at...@infomedica.it>.

Christopher Schultz-2 wrote:
> 
> 
> This is a question that you will have to answer: what information is
> absolutely necessary for you to resume a user interaction in-progress?
> Whatever that is, you'll need to include that information in every
> single link that a user can click on (or in every form they can submit).
> 


The problem is that to resume a user interaction in-progress  after a
re-login
I need informations binded as attributes in the expired session.
After a re-login I would like to 'resume' old session instead of to use e
new empty one.

Is it possible?

Alberto
-- 
View this message in context: http://www.nabble.com/Re%3A-Tomcat-Realm-Auto-Relogin-after-Session-Timeout-Problem-tp25479941p25487080.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org