Question

We are using SocialAuth for authentication with Spring 3 and having issue with sessions between redirects.

When we do return "redirect:myURL"; in controller (after authentication) redirection happening properly but, very frequently redirect creating new session instance instead of using my current session which results in NullPointerException when I look for certain variables I have stored in session.

I have added few System.out statements to prove that new session is being created.

Session id is before authentication...E7557680F892C6776F36691E9DF93CF5
session ID after authentication and redirct....     726C2EE5C240BDE4D217CBFDB9C47A0F

How can I store current session in Spring application context before redirect and use it after redirect based on session ID? Is there any other way we can work around this in Spring?

Was it helpful?

Solution

Have a look at RedirectAttributes Interface in Spring, it' is built for the same purpose you are trying to implement. This basically preserve values between redirects and hence will eliminate your need of putting attributes in session and then getting them.

Here's the link

http://docs.spring.io/spring/docs/3.1.x/javadoc-api/org/springframework/web/servlet/mvc/support/RedirectAttributes.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top