Reputation: 11
I am a Vaadin beginner...
Is it possible to preserve session data if the application is initialized again ?
I am asking because I tried to set something to the http session on after page refresh that was gone.
WebApplicationContext ctx = (WebApplicationContext) this.getContext();
HttpSession session = ctx.getHttpSession();
Object attribute = session.getAttribute("user"); // <- always gets flushed
I would like to use this approach for user authentication. How to accomplish this best ?
Upvotes: 1
Views: 3081
Reputation:
It is totally normal that the attribute gets flushed when the app is initialized again because when the app gets initialized again a new Context gets created. So i would suggest you to use http-cookies instead of adding the attribute to the session itself because this is (as far as i know) the default way to accomplish the "remember-me" feature on websites. Also you have the ability to set the expire date of the cookies.
As a security hint i would recommend you not to use data for user authentication across sessions, which can be easily figured out and abused.
Furthermore i found an article and an addon which deal with cookies:
Book of Vaadin - explaining how to set Cookies
Vaadin Addon which deals with Cookies
Upvotes: 3