Session in Spring Loading Application

My project is a springboot application with basic crud functionality with a login page using only HTML and CSS. How to add a session to login and logout

+3


source to share


5 answers


Like others have suggested, you can use Spring security. Or, if you don't want to deal with the intricacies of Spring Security, you can get the object HttpSession

in the arguments of the controller handler methods. You can set values ​​or objects in this session using HttpSession.setAttribute("name you want to refer to", actual value or object)

after user login. And when the user clicks on logout, you can use HttpSession.invalidate();

to log out.



+3


source


The best solution for this would be using Spring Security. Take a look at this: https://spring.io/guides/gs/securing-web/ .



+2


source


simple spring web security tutorial see link here and here

+1


source


It is recommended to use Spring Security.

You can find many examples if you are looking for "spring security tutorial" on google.

For example, this is the official tutorial with angular js (1.x) https://spring.io/guides/tutorials/spring-security-and-angular-js/

If you don't want to use Spring security, you need to create an http session and store the logged in user data in the http session.

In Spring, you can inject HttpSession to your bean and you can add session attributes, or you can create a session bean application.

+1


source


Spring Security is the best option for authentication and authorization. To log in, if a new user has registered, you need to save the session for a specific user before logging out. You can use Spring Security Session Management.

http://www.baeldung.com/spring-security-session

You can set the UserDetails object to http.setAttribute ("USER_DETAILS", userDetails);

(userDetails is a UserDetails object that is in the constructed class)

You can use this httpSession object, for example httpSession.getAttribute ("USER_DETAILS"); for further manipulation. To log out, use can use the httpSession.invalidate () method.

0


source







All Articles