Ashu
Ashu

Reputation: 2266

How to manage session in Spring Boot with Spring Security?

I was following below tutorial for Spring Boot Login example with Spring Security example:

https://hellokoding.com/registration-and-login-example-with-spring-security-spring-boot-spring-data-jpa-hsql-jsp/

I am able to build the web application. Security is working fine.

Now the next part is to manage the session. I want to store user data, roles and some other details in session. How to do this ?

Upvotes: 0

Views: 12359

Answers (1)

balag3
balag3

Reputation: 665

As already stated, spring manages the session for you. It stores the user data, roles etc. for you. If you want to check that just Add the Principal as one your argument in your controller class. which is the currently logged in security user, for example:

@RequestMapping(value = {"/", "/welcome"}, method = RequestMethod.GET)
public String welcome(Model model, Principal principal) {
    System.out.println(principal.getName());
    return "welcome";
}

Altough if you want to refine this strategy and add your own logic, just follow this tutorial: http://www.baeldung.com/spring-security-session

Upvotes: 3

Related Questions