You might try registering Spring's RequestContextListener in your
web.xml. That way, you can get the request from a ThreadLocal and get
the session from that.

http://www.springframework.org/docs/api/org/springframework/web/context/request/RequestContextListener.html

Matt

On 8/24/07, BruceLee <[EMAIL PROTECTED]> wrote:
>
> Thank Absolut a lot for sharing the helpful code.
> However when I try to getSession() in the Listener, sometimes it returns
> null. After I refresh the page serveral times, it gets normal. Any ideas?
> ---my code---
> public void onApplicationEvent(ApplicationEvent event) {
>         //   check failed event
>         if(event instanceof AuthenticationSuccessEvent)
>         {
>            ......
>                 HttpSession session =
> ServletActionContext.getRequest().getSession();
>                 userManager.saveUser(user);
>                 userLoggedinManager.saveUserLoggedin(userLoggedin);
>                 session.setAttribute("userId",user.getId());
>                 session.setAttribute("username",user.getUsername());
>            ......
>         }
> }
>
> -Mike
>
>
>
> Absolut wrote:
> >
> > Or take a look at this code sample from our app:
> >
> > public class LoginListener implements ApplicationListener
> > {
> >  protected Log log = LogFactoryImpl.getLog(getClass());
> >  private UserManager userManager;
> >
> >
> >
> >  /**
> >   * @param userManager the userManager to set
> >   */
> >  public void setUserManager(UserManager userManager) {
> >   this.userManager = userManager;
> >  }
> >
> >
> >
> >  /**
> >   * @see
> > org.springframework.context.ApplicationListener#onApplicationEvent(org.sprin
> > gframework.context.ApplicationEvent)
> >   */
> >  public void onApplicationEvent(ApplicationEvent event) {
> > //   check failed event
> >         if(event instanceof AuthenticationSuccessEvent)
> >         {
> >          AuthenticationSuccessEvent authenticationSuccessEvent =
> > (AuthenticationSuccessEvent) event;
> >          String username =
> > authenticationSuccessEvent.getAuthentication().getName();
> >          User user = userManager.getUserByUsername(username);
> >          user.setLastLogin(new Date());
> >          int loginCount = 0;
> >          if(user.getLoginCount()!= null)
> >          {
> >           loginCount = user.getLoginCount().intValue();
> >          }
> >          loginCount++;
> >          user.setLoginCount(new Integer(loginCount));
> >          try
> >          {
> >           userManager.saveUser(user);
> >          }
> >          catch (UserExistsException e)
> >          {
> >           log.error("Error during updating last login for user
> > ["+username+"]",e);
> >          }
> >         }
> >
> >  }
> >
> > }
> >
> >    _____
> >
> > Von: Michael Horwitz [mailto:[EMAIL PROTECTED]
> > Gesendet: Montag, 13. August 2007 10:01
> > An: [email protected]
> > Betreff: Re: [appfuse-user] Add new function after login
> >
> >
> > ACEGI generate Spring application events on login. You will need to create
> > a
> > listener to log the appropriate events - do a search on this list, or look
> > at Spring events on the Spring framework site for more information.
> >
> > Mike.
> >
> >
> > On 8/11/07, BruceLee <HYPERLINK "mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]>
> > wrote:
> >
> >
> > Team,
> > I want to add some function e.g. storing login date to database after
> > login.
> > What is the hook to add this? Using a filter, interceptor or override some
> > class?
> > My env: 1.9.4 WebWork
> > Thanks! -Bruce
> > --
> > View this message in context: HYPERLINK
> > "http://www.nabble.com/Add-new-function-after-login-tf4252462s2369.html#a121
> > 02596"http://www.nabble.com/Add-new-function-after-login-tf4252462s2369.html
> > #a12102596
> > Sent from the AppFuse - User mailing list archive at HYPERLINK
> > "http://Nabble.com"Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: HYPERLINK
> > "mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]
> > .java.net
> > For additional commands, e-mail: HYPERLINK
> > "mailto:[EMAIL PROTECTED]"[EMAIL PROTECTED]
> >
> >
> >
> >
> >
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
> > 12.08.2007
> > 11:03
> >
> >
> >
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
> > 12.08.2007
> > 11:03
> >
> >
> >
>
> --
> View this message in context: 
> http://www.nabble.com/Want-to-add-extra-function-like-saving-login-date-in-login-action-tf4252462s2369.html#a12323058
> Sent from the AppFuse - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
http://raibledesigns.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to