[ Spring Security Official Docs ] Getting Started
[Spring Blog ] Spring security without the websecurityconfigureradapter
Spring Security 5.7.0-M2 에서 WebSecurityConfigurerAdapter deprecated 됨
로그인 기능 구현 시 참고사항(경일님 친구분 )
1. 로그인
- Spring Security를 사용하지 않고 직접 인증/인가 기능을 구현했습니다.
- 인증 (Authentication)
- WAS에 들어오는 요청을 검증하기 위한 AuthorizationInterceptor 구현했습니다.
- Http 헤더에 들어있는 엑세스 토큰(JWT) 존재 여부 확인합니다.
- 올바른 엑세스 토큰인지 검증합니다.
- 인가 (Authorization)
- 컨트롤러에 접근하기 전에 요청한 유저의 권한을 검증하기 위한 CurrentUserArgumentResolver 구현했습니다.
- Http 헤더에 들어있는 엑세스 토큰으로 유저 객체를 생성합니다.
- 유저 객체가 알맞은 권한을 갖고 있는지 검증합니다.
- OAuth 로그인 구현
- 클라이언트에서 OAuth 공급자와 인가 코드(AuthorizationCode)가 요청으로 오면 공급자에 알맞는 소셜 로그인 서버(Authorization Server)에게 엑세스 토큰을 요청합니다.
- 전달 받은 엑세스 토큰으로 소셜 로그인 서버(Resource Server)에게 유저 정보를 요청합니다.
- 전달 받은 유저 정보에서 필요한 정보를 Redis에 저장한 뒤 엑세스 토큰과 리프레쉬 토큰을 생성합니다.
- 생성한 엑세스 토큰과 리프레쉬 토큰을 클라이언트에게 반환합니다.
- 리프레쉬 토큰을 활용한 자동 로그인 구현
- 사용자가 로그인을 하면 엑세스 토큰과 리프레쉬 토큰을 발급합니다.
- 엑세스 토큰이 만료되면 리프레쉬 토큰을 사용해 엑세스 토큰을 다시 발급합니다.
- 리프레쉬 토큰의 만료기간이 24시간 미만으로 남았을 때, 기기 고유번호가 일치할 경우 리프레쉬 토큰을 다시 발급합니다.
- 엑세스 토큰, 리프레쉬 토큰 취약점 개선
- 엑세스 토큰이 탈취될 수 있는 문제
- 엑세스 토큰의 만료 시간을 3분으로 설정하여 개선했습니다.
- 리프레쉬 토큰 탈취될 수 있는 문제
- 로그인 시 기기 고유번호를 받아 Redis에 저장합니다.
- 리프레쉬 토큰으로 새로운 엑세스 토큰을 발급할 때 기기 고유번호도 받아 Redis에 저장된 값과 다르면 다시 로그인하도록 하여 개선했습니다.
인증
Spring Security Architecture & ConfigureSpring Security 핵심(ThreadLocal, SecurityContextHolder, Authentication)인증처리 (AuthenticationManager, AbstractAuthenticationProcessingFilter)PasswordEncoder로그 아웃 필터[DB에서 user정보 관리하기] UserDetail, UsetDetailsServiceCustom AuthenticationProvider 적용SAML 인증
인가
ExceptionTranslationFilterFilterSecurityInterceptor(인가 처리)Voter
필터 이해
ChannelProcessingFilter (Spring Security에 HTTPS 적용하기)RequestCacheAwareFilter AnonymousAuthenticationFilterCustom Filter 이용 ( addFilterAt )
로그인 지속 지원 필터
RemembermeAuthenticationFilter세션 처리(SecurityContextPersistenceFilter, SessionManagementFilter)그외 필터
HeaderWriterFilterCsrfFilterBasicAuthenticationFilterWebAsyncManagerIntegrationFilter
활용
Spring Session, Session ClusterMulti Filter Chain 이용 (웹, 모바일 동시 개발)Spring Security 인증 이벤트JWT 토큰API Key를 이용한 REST API 보안@AuthenticationPrincipalOAuth2인증/인가 예외 처리 (AuthenticationEntryPoint)