Spring-Security

essionManagementFilter & ConcurrentSessionFilter

neal89 2025. 5. 29. 12:05

 

✅ SessionManagementFilter

📌 언제 작동되나요?

  • 인증이 성공한 직후에 작동합니다.
  • 보통 UsernamePasswordAuthenticationFilter 다음에 위치합니다.

📌 어떤 역할을 하나요?

  1. 현재 인증된 사용자에게 세션이 필요한지 확인
  2. 세션이 존재하지 않으면 생성 (정책에 따라 다름)
  3. 세션 고정 공격 방지 처리
    • 기본은 changeSessionId()
  4. 세션 관련 전략 수행
    • SessionAuthenticationStrategy를 실행

📌 내부 프로세스 요약

1. 인증 성공
2. SessionManagementFilter 실행
3. SessionAuthenticationStrategy 실행
   └ 예: ConcurrentSessionControlAuthenticationStrategy
   └ 예: ChangeSessionIdAuthenticationStrategy
4. 세션 생성, 갱신, 또는 예외 처리

✅ ConcurrentSessionFilter

📌 언제 작동되나요?

  • 모든 요청이 들어올 때마다 작동합니다.
  • SessionManagementFilter보다 나중에 실행됩니다.
  • 세션이 이미 존재하는지 확인하고, 만료되었는지 검사합니다.

📌 어떤 역할을 하나요?

  1. 현재 세션 ID로 조회된 세션이 만료되었는지 확인
  2. 만료된 세션이면 사용자에게 지정된 처리 수행
    • 기본은 리다이렉트 (expiredUrl)
    • 또는 커스텀 전략 실행 (ExpiredSessionStrategy)

📌 내부 프로세스 요약

1. 매 요청 시 ConcurrentSessionFilter 실행
2. 세션 ID 로 조회된 세션 유효성 검사
3. 세션이 만료되었으면 logout 처리 + expired strategy 실행

🔄 둘의 관계

 

항목  SessionManagementFilter  ConcurrentSessionFilter
작동 시점 로그인 성공 시 매 요청 시
주요 기능 세션 생성, 고정 방지, 인증 전략 실행 세션 만료 여부 검사 및 처리
대표 전략 SessionAuthenticationStrategy ExpiredSessionStrategy

✅ 예제 흐름

  1. 사용자가 로그인
  2. UsernamePasswordAuthenticationFilter → 인증 성공
  3. SessionManagementFilter → 세션 생성, 고정 방지 등 처리
  4. 이후 요청마다 ConcurrentSessionFilter가 세션 만료 여부 확인