Implement Session using spring security

Опубликовано: 22 Август 2022
на канале: Programming Tutorial
10,209
like

#springsecurity #springsession #implementsessionusingspring #sessionspringboot #sessionspring
Implement Session In Spring boot
Prerequisite
1. You have Spring boot project
2. Your project already implement UserdetailServices and Spring security

Flow session
When user login
App create session
and save session into database
when user acces different resource bring session id and server compare session(if valid user acces resource)


Let's jump right in
1. add spring-session-jdbc to pom.xml (used for save session after user succeed login)
2. config application.properties(set place to store session and set session timeout)
spring-session-jdbc added and applicatio.properties already set(when first time app running this table automatic created SPRING_SESSION + SPRING_SESSION_ATTRIBUTES)
3. Open spring configuration class
create session
set url when session invalid(when session invalid app use this url for redirect to spesific page)
set maximum session (only single user can login into app in same time/concurrent)
second login will cause the first to be invalidated
delete cookies and invalidate session when logout

4. Try to run app



Scenario test
1. delete session from database after user login(test passed, when user automatically log out)
2. User log out(test passed, when user try to access different resource not allowed)
3. only single user can login into app in same time(test passed, when in other browser app automatically log out)/ this scenario applied to an internet banking application

Suuceed, Happy learning and happy sharing!!!


Смотрите видео Implement Session using spring security онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Programming Tutorial 22 Август 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 10,209 раз и оно понравилось like людям.