-
Spring Security 다이어그램으로 flow 정리하기프레임워크/Spring Boot 2024. 5. 7. 02:15
이번에는 충분한 시간가지고 학습할 수 있는 상황이기 때문에 구현에 급급하기 보다는 이해를 하면서 가는 방향을 선택해봅니다 ㅎㅎ
디버거로 열심히 따라다니면서 그려보았습니다. 덕분에 흐름이 머릿 속에 잡힌 것 같아 만족스럽습니다 ㅎㅎ
1. ID/PW를 사용해서 로그인
유저의 입력을 기반으로 Authentication을 구현하는 객체를 만들어서 사용합니다.
서버 측의 유저 정보를 UserDetails 형태로 준비합니다.
둘을 비교하여 적절한 id / pw를 유저가 입력했는지 확인합니다.
노란색으로 표시된 클래스는 커스터마이징이 된 클래스입니다.
DaoAuthenticationProvider에서 유저가 입력한 id/pw 와 서버 측의 유저 정보를 비교합니다.
2. Oauth를 사용하는 로그인
기본적으로 Authorization Code Grant 방식을 기반으로 하고 있습니다.
아래의 플로우는 머릿 속에 들어있었지만, 추상화가 너무 되어있다보니 클래스 찾아다니는 것에 어려움이 있었습니다.
OAuth2LoginAuthenticationFilter에 오기전에 이미 code를 받아오는 요청을 한 상태로 진입하는 것으로 보입니다.
OAuth2LoginAuthenticationFilter에서는 가지고 있는 데이터를 파싱해서 code를 추출하는 코드가 있습니다.
id/pw 와 달리 커스텀 클래스들을 사용하지 않은 상태입니다.
UserService를 적절하게 커스텀해서 구글의 유저 정보를 서버 측 유저정보와 잘 매핑해줘야할 것 같습니다.
아직 구현 중에 있지만 과정이 끝난다면 successHandler를 통해서 프론트 측에 리다이렉트를 시켜줄 수 있습니다.
setDefaultTargetUrl에 리다이렉트 될 주소를 넣어줍니다.
스프링 시큐리티가 적당히 구현이 다 되어있어서 편한듯 하면서 복잡하다는 단점이 있다고 느껴집니다.
아직 익숙하지 않아서 그럴수도 있겠지만 직접 구현하는 옵션도 나쁘지 않겠다 싶기도 합니다..
감사합니다.
참고
'프레임워크 > Spring Boot' 카테고리의 다른 글
ServletInputStream은 1번만 읽을 수 있다 (0) 2024.05.08 필터에서 발생하는 예외 처리하기 (0) 2024.05.07 SecurityFilterChain을 여러개 쓰고자 한다면 securityMatcher! (0) 2024.05.03 RestTemplate는 응답 객체를 LinkedHashMap으로 파싱한다 (0) 2024.05.02 RestTemplate은 4xx를 예외로 처리한다. (0) 2024.05.02