동시세션제어 기능에서 로그아웃하기
144
1 asked
안녕하세요
"인가 설정 실시간 반영하기" 코드에서 동시 세션 제어 기능을 추가할려고 합니다.
http.sessionManagement(session -> session
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
)
위 코드를 추가한 후 REST 방식으로 로그인후 로그아웃을 하면 SessionRegistry의 principals 객체에 있는 정보가 삭제되지 않아 다시 로그인을 시도하면 인증오류가 발생합니다.
로그아웃을 할 경우 SessionRegistry.removeSessionInformation(sessionId)가 호출되어 principals 정보가 삭제되어야 할 것 같은데 제가 잘못 이해하고 있는 지 궁금합니다.
Answer 3
1
@GetMapping(value = "/api/logout")
public String logout(HttpServletRequest request, HttpServletResponse response) {
Authentication authentication = SecurityContextHolder.getContextHolderStrategy().getContext().getAuthentication();
if (authentication != null) {
new SecurityContextLogoutHandler().logout(request, response, authentication);
}
return "logout";
}위 코드를 사용합니다.
잠시 구글링을 해보니
@Bean
public static ServletListenerRegistrationBean httpSessionEventPublisher() {
return new ServletListenerRegistrationBean(new HttpSessionEventPublisher());
}이렇게 HttpSessionEventPublisher를 등록하면 SeesionRegistry가 이벤트를 감지하여 onApplicationEvent()에서 removeSessionInformation()을 호출한다고 하여 테스트 해보니 로그아웃시 잘 동작하네요
0
다시보니 강사님께서 이미 답변하신 내용이네요 ^^
https://www.inflearn.com/community/questions/40072/동시-세션-제어-동일-브라우저에서-로그아웃이-정책-미적용
0
Rest 라면 세션을 사용하고 있지 않은가요?
보통 세션기반으로 로그아웃하면 세션이 무효화되고 그 때 세션폐기 이벤트가 발생하면서 SessionRegisry 가 세션정보를 삭제하는 것으로 압니다
Rest 로 로그아웃할 때 어떤 식으로 로그아웃이 진행되는가요?
로그아웃-logout()-2 강에서 겟방식 로그아웃 호출 후 화면이동 질문입니다.
0
27
2
단원별 소스코드
0
58
2
CustomAuthenticationProvider 추가 관련 문의
0
68
2
AOP 의존성 명칭 변경
0
62
1
빈 1개 등록 시 다른 해결 방법
0
64
1
@Bean으로 AuthenticationProvider를 등록 시 http.authenticationProvider 함수를 이용해서 추가해줘야되나요?
0
84
2
OIDC의 id token에 담긴 데이터에 대해
0
73
1
loginPage("/loginPage") 질문드립니다.
0
67
1
@EnableWebSecurity
0
146
1
트랜잭션과 롤백
0
98
1
68. 인증 이벤트 - AuthenticationEventPublisher 활용 강좌 음성 문제
0
86
2
AuthenticationManager 사용 방법
0
147
2
HttpSecurity.authorizeHttpRequests() - 2 강의 부분에 대한 질문
0
101
2
spring security 6.3에서는 HttpSecurity가 만들어지기 전 WebSecurity가 먼저 만들어지는게 맞나요??
0
189
1
init(B Builder), configure(B builder) 에 대하여 질문 드립니다.
0
104
2
메타 주석 질문
0
67
1
로그인 후, redirect 에서 error
0
138
3
Session 생성 타이밍에 대한 질문
0
83
2
강의 참고 내용을 개발 로그로 작성해도 될지 문의드립니다.
0
131
2
customAuthentication 관련
0
126
2
authenticationManagerBuilder 주입받은거 vs 만든 거
0
109
1
UserDetailsService()에서 UserDetail이 아닌 타입을 반환할 수 있나요?
0
100
1
9:28 패턴 3의 경우 마지막으로 설정한 것만 적용되는 것 같습니다.
0
157
2
Bean UserDetailsService
0
89
2

