You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Yi-Xiong Zhou <yz...@arcturusag.com> on 2001/07/07 00:45:22 UTC

container managed authentication

How do I perform additional process in struts at the time of authentication
if container managed authentication is used?

For example, after the user has just logged on, I want to initialize some
attributes in the session by loading in some data from the database. One way
to do that is to add a new method in Action to do such a process whenever a
new logon is detected. Then call that method at each implementation of
perform() method. Is there a better way to handle this task? 

Yi-Xiong Zhou

Re: container managed authentication

Posted by Levi Cook <le...@papajo.com>.
If you're working with a Servlet 2.3 implementation, and your container
automatically creates sessions for each user, then you could simply
implement and register a javax.servlet.http.HttpSessionListener. From there
your container would auto-magically notify your listener when new sessions
are created.

In reality, you're probably working with a Servlet 2.2 implementation, so
you're options are a bit more limited. One technique I would consider is
implementing a common ancestor for all of your actions which provides a
method like this:

protected void initSessionIfNecessary() {
  // check for the presence of a session attribute
  // if its not there, load session attributes
  // you'd like to prepopulate using the
  // user's credentials
}

The main penalty of this approach is ensuring all your actions call this in
their perform method. Personally, its one I can accept, because I know the
2.3 spec. will be here soon enough.

- Levi


----- Original Message -----
From: "Yi-Xiong Zhou" <yz...@arcturusag.com>
To: <st...@jakarta.apache.org>
Sent: Friday, July 06, 2001 3:45 PM
Subject: container managed authentication


> How do I perform additional process in struts at the time of
authentication
> if container managed authentication is used?
>
> For example, after the user has just logged on, I want to initialize some
> attributes in the session by loading in some data from the database. One
way
> to do that is to add a new method in Action to do such a process whenever
a
> new logon is detected. Then call that method at each implementation of
> perform() method. Is there a better way to handle this task?
>
> Yi-Xiong Zhou
>