Results 1 to 7 of 7

Thread: Intercept login and logout

  1. #1
    Join Date
    Sep 2008
    Posts
    9

    Default Intercept login and logout

    Hi,

    I just started on a project that's using Spring Security and I would like to intercept successful login and logout to do some actions at those point of times.
    Any idea what's the best way to achieve that is?

    Thanks

  2. #2
    Join Date
    Sep 2008
    Posts
    9

    Smile

    Any indication as to where I need to put my plumbing code to run the logic required during those events (success login, logout) would pretty much be all I need.

  3. #3
    Join Date
    May 2005
    Location
    California, US
    Posts
    735

    Default

    Lance, what about that table on page 12 (of the pdf)? There's documentation there for inserting more filters.

  4. #4
    Luke Taylor is offline Senior Member Acegi Security System TeamSpring Team
    Join Date
    Aug 2004
    Location
    Glasgow, Scotland
    Posts
    3,449

    Default

    You can also use the events that Spring Security generates if that is sufficient (write an ApplicationEventListener).
    Spring - by Pivotal
    twitter @tekul

  5. #5
    Join Date
    Sep 2008
    Posts
    9

    Default

    Ok so I figured out the login interception business using a SecurityListener class implementing a ApplicationListener and checking the type of the ApplicationEvent passed in like this:

    Code:
    public void onApplicationEvent(ApplicationEvent event) 
    {
        if (event instanceof AuthenticationSuccessEvent) 
        {
            ...
        }
    }
    Now my next problem is that there I can't seem to find a class representing a logout event. At this point I'm starting to wonder if logging out triggers an application event that would go through my securitylistener at all?

    Any idea?

  6. #6

    Default

    I just wanted to follow up on this, did anyone find a way to run some code when a user logs out? Explicitly and implicitly (session times out)? I need to do some processing on these events as well, and would like access to the UserDetails object to facilitate it.

    Thanks,
    David
    Last edited by halcyon; Feb 10th, 2009 at 01:29 AM.

  7. #7
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default

    I have the same question: how to trigger code on logout.
    This thread http://forum.springframework.org/showthread.php?t=29115
    offers a suggestion, it that the excepted practice?
    Or has this event been incorporated into the framework in 2 years?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •