Hi,
[EMAIL PROTECTED] wrote:
Question
Is there a bean I can wire into
src/main/resources/applicationContext-dao.xml that provide access to the
following properties for a request: logged-in username, IP address the
request originated from ??
I am thinking the ACEGI framework (or an appfuse class that implements and
ACEGI interface) should provide this. Ideally the bean could be extended to
also return the object id (primary key) of the username record - but I'll
settle for just getting the username back for now.
The username and the ip address are both available from the request, via
getRemoteUser() and getRemoteAddr() respectively. You can inject the
ServletContext into your bean (which will give you the request) via a
javax.servlet.ServletContext attribute - note, your bean will have to
implement the ServletContextAware interface. You can of course use the
userName to look up all the other user attributes.
If you have to look up user attributes from the DB, you might want to
improve performance by caching the result in the session. I believe
that Acegi puts some kind of User object into the session but I'm not
sure how accessible it is or how you'd get at it, or what attributes it
provides. I'm sure others on this forum would know more about that and
an examination of the source code for
org.appfuse.webapp.action.UserAction may also be helpful here.
If you're going to cache the user, an alternative method might be to
intercept a SuccessfulLoginEvent (via a bean that implements
ApplicationListener and checks for instanceof (SuccessfulLoginEvent) in
its onApplicationEvent (ApplicationEvent) method and then lookup and
cache the user details at that point. Ideally, you could cache them
somewhere that's accessible to the whole application without individual
classes having to have access to the Servlet Context, but I don't know
if that's possible. I seem to recall people talking about ThreadLocal in
that context, but a quick Google for j2ee and ThreadLocal turned up an
alarming list of "don't do that" types of message.
HTH,
Rob Hills
Waikiki, Western Australia
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]