-
Notifications
You must be signed in to change notification settings - Fork 16
[김찬호] Sprint9 #129
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
Open
cheis11
wants to merge
32
commits into
codeit-bootcamp-spring:김찬호
Choose a base branch
from
cheis11:sprint9
base: 김찬호
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[김찬호] Sprint9 #129
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
요구사항
기본
Spring Security 환경설정
Security 설정 클래스를 생성하세요.
패키지명: com.sprint.mission.discodeit.config
클래스명: SecurityConfig
SecurityFilterChain Bean을 선언하세요.
개발 환경에서 Spring Security 모듈의 로깅 레벨을 trace로 설정하세요.
각 요청마다 통과하는 필터 목록을 확인할 수 있습니다.
CSRF 보호 설정하기
CsrfTokenRepository 구현체를 CookieCsrfTokenRepository로 설정하세요.
디폴트 구현체는 HttpSessionCsrfTokenRepository입니다.
CsrfTokenRequestHandler 컴포넌트를 대체하세요.
디폴트 구현체는 XorCsrfTokenRequestAttributeHandler입니다.
Spring 공식문서에서 권장하는 CSR+SPA(Single Page Application) 환경에 적합한 구현체를 정의하세요.
CSRF 토큰을 발급하는 API를 구현하세요.
API 스펙
회원가입
인증 - 로그인
이번 미션에서는 보라색 음영 처리된 5가지 컴포넌트를 대체합니다.
각 컴포넌트의 기본 구현체가 무엇인지 디버깅해보세요.
UserDetailsService 컴포넌트를 대체하세요.
디폴트 구현체는 InMemoryUserDetailsManager입니다.
DiscodeitUserDetailsService를 정의하세요.
UserDetails 컴포넌트를 대체하세요.
디폴트 구현체는 org.springframework.security.core.userdetails.User입니다.
DiscodeitUserDetails를 정의하세요.
앞서 정의한 DiscodeitUserDetailsService에서 DiscodeitUserDetails를 생성 후 반환하세요.
AuthenticationSuccessHandler 컴포넌트를 대체하세요.
디폴트 구현체는 SavedRequestAwareAuthenticationSuccessHandler입니다.
LoginSuccessHandler를 정의하고 대체하세요.
AuthenticiationFailureHandler 컴포넌트를 대체하세요.
디폴트 구현체는 SimpleUrlAuthenticationFailureHandler입니다.
LoginFailureHandler를 정의하고 대체하세요.
이제 로그인 처리는 SecurityFilterChain에서 모두 처리되기 때문에 기존에 구현했던 로그인 관련 코드는 제거하세요.
AuthApi.login, AuthController.login
AuthService.login
LoginRequest
인증 - 세션을 활용한 현재 사용자 정보 조회
인증 - 로그아웃
Spring Security의 logout 흐름은 그대로 유지하면서 필요한 부분만 대체합니다.
이번 미션에서는 2가지 요소를 대체합니다.
LogoutSuccessHandler 컴포넌트를 대체하세요.
디폴트 구현체는 SimpleUrlLogoutSuccessHandler입니다.
HttpStatusReturningLogoutSuccessHandler로 대체하세요.
인가 - 권한 정의
사용자 권한을 수정하는 API를 구현하세요.
API 스펙
애플리케이션 실행 시 ADMIN 권한을 가진 어드민 계정이 초기화되도록 구현하세요.
어드민 계정이 없는 경우에만 초기화하세요.
인가 - 권한 적용
Service의 메소드 별로 아래의 조건에 맞게 권한을 수정하세요.
퍼블릭 채널 생성, 수정, 삭제는 CHANNEL_MANAGER 권한을 가져야합니다.
사용자 권한 수정은 ADMIN 권한을 가져야합니다.
적절한 권한이 없는 경우 403 응답을 반환하세요.
SecurityFilterChain
GlobalExceptionHandler
RoleHierarchy를 활용해 권한의 계층 구조를 정의하세요.
관리자 > 채널 매니저 > 일반 사용자
심화
세션 관리 고도화
동일한 계정으로 동시 로그인할 수 없도록 설정하세요.
sessionConcurrency 설정을 활용하세요.
권한이 변경된 사용자가 로그인 상태라면 세션을 무효화하세요.
sessionRegistry를 활용하세요.
UserStatus 엔티티 대신 SessionRegistry를 활용해 사용자의 로그인 여부를 판단하도록 리팩토링하세요.
UserStatus 엔티티와 관련된 코드는 모두 삭제하세요.
(로그아웃처럼) HttpSession 만료 시 SessionRegistry의 SessionInformation도 자동으로 만료 처리할 수 있도록 HttpSessionEventPublisher를 Bean으로 등록합니다.
로그인 고도화 - RememberMe
로그인 요청 파라미터(remember-me)가 true인 경우 세션이 무효화되어도 자동으로 다시 로그인되도록 하세요.
remeberMe
설정을 활용하세요.권한 적용 고도화
주요 변경사항
스크린샷
멘토에게