Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

스프링 스큐리티 스켈레톤 #63

Open
ecsimsw opened this issue Jan 28, 2025 · 0 comments
Open

스프링 스큐리티 스켈레톤 #63

ecsimsw opened this issue Jan 28, 2025 · 0 comments

Comments

@ecsimsw
Copy link
Owner

ecsimsw commented Jan 28, 2025

연휴 동안 만들어보기
내 코드를 기준으로!

1. 사용자가 로그인 요청을 보냄
2. AuthController
 - 로그인 요청에 username, password
 - UsernamePasswordAuthenticationToken 생성
 - 아직 인증되지 않은 상태(authenticated=false)
 - AuthenticationManager가 AuthenticationProvider에게 인증 요청
3. AuthenticationManager
 - 이때 AuthenticationManager는 CustomAuthenticationProvider를 갖고 있고, 얘가 처리
 - AuthenticationManager.authenticate(), 인증 시도
 - AuthenticationProvider에게 실제 인증 작업을 위임
 - AuthenticationProvider가 loadUserByUsername(username)
 - UserDetailsService는 DB에서 사용자 정보를 읽어서 사용자 정보(UserDetails)를 가져옴
 - 전달된 UserDetail 정보로 AuthenticationProvider가 비밀번호 검증
4. UsernamePasswordAuthenticationToken
 - 인증에 성공하면 UsernamePasswordAuthenticationToken을 authenticated=true로 변경
 - SecurityContextHolder에 인증 정보 저장
5. TokenService
 - JWT 토큰 생성 및 반환
1. 사용자가 권한이 필요한 요청을 보냄
2. OncePerRequestFilter
 - Header에서 Jwt 꺼내서 Claim의 사용자 정보 파악 (유저네임, 활성 상태, 권한, 어드민 여부)
 - 이를 UserDetail로 만들어 SecurityContextHolder에 인증 정보 저장
3. UserController 
 - Spring security는 이 정보를 바탕으로 PreAuthorize, 인가 처리
 - 인증된 사용자 정보는 SecurityContextHolder에서 가져와서 활용 가능
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant