Results 1 to 3 of 3

Thread: Setting a cookie upon login in Spring Security 3.0

  1. #1
    Join Date
    Feb 2008
    Posts
    169

    Question Setting a cookie upon login in Spring Security 3.0

    I need to set a cookie when someone logs in and the JSP page that comes up needs to be able to read that cookie in Javascript and perform an action based on it. The part I'm stuck on is setting a cookie upon login. I'm using Spring and Spring Security 3.0.

    I've registered a LoginListener:
    Code:
    public class LoginListener implements ApplicationListener {
        public void onApplicationEvent(ApplicationEvent event) {
            if (event instanceof AuthenticationSuccessEvent) {
                somehowGetResponseObject.addCookie(new Cookie(name, value));
            }
        }
    }
    Ideally I can also get the request object so I can find the contextPath and set that as the cookie path. I'm fine with adding the cookie to a ThreadLocal object and then reading that later when I do have access to a response object, but is there a later time when I would have that access? I'm not so enthusiastic about adding the cookie to a Session and then reading that in the resulting JSP page, but I'll do that if I have to. Can I get access to the HttpSession?

  2. #2
    Join Date
    Jan 2008
    Posts
    1,826

    Default

    Did you try writing an AuthenticationSuccessHandler to do this?
    Rob Winch - @rob_winch
    Spring Security Lead
    Pivotal

  3. #3
    Join Date
    Feb 2008
    Posts
    169

    Default

    Quote Originally Posted by rwinch View Post
    Did you try writing an AuthenticationSuccessHandler to do this?
    Exactly what I was looking for!! Thanks!

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
  •