💡 로그인 사용자 세션을 1개로 고정하는 것 .maximumSessions(1) // maximunSessions : Session 허용 개수
Spring Security를 사용해서 sercurityConfig을 수정
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf().disable()
.cors().disable()
.authorizeHttpRequests(request -> request
.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
.anyRequest().authenticated()
)
.formLogin(login -> login
.loginPage("/login")
.loginProcessingUrl("/login_process")
.defaultSuccessUrl("/", true)
.permitAll()
)
.logout(withDefaults())
.sessionManagement() // session 관리
.maximumSessions(1) // maximunSessions : Session 허용 개수
.maxSessionsPreventsLogin(false);
//maxSessionPreventsLogin : true 일 경우 기존에 동일한 사용자가 로그인한 경우에는 login 이 안된다.
// false 일경우는 로그인이 되고 기존 접속된 사용자는 Session이 종료되고 로그아웃된다. false 가 기본이다.
return http.build();
}
References: https://hoonzi-text.tistory.com/139