-
Notifications
You must be signed in to change notification settings - Fork 0
[Chanyeol] Week8 미션 #87
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
coconutcococode
wants to merge
6
commits into
main
Choose a base branch
from
Chanyeol-week8
base: main
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1e2a17d
docs:8주차 핵심 키워드
coconutcococode c3f2697
remove: .env 파일 삭제
coconutcococode 2f9612a
feat: Spring Security 의존성 추가
coconutcococode 384c5e0
feat: Spring Security 적용
coconutcococode 9accf86
feat: 회원가입 API 구현
coconutcococode 5f029fe
feat: 7주차 피드백 반영 - 상태 코드 관련
coconutcococode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| - Spring Security가 무엇인가? | ||
|
|
||
| ## 스프링 기반의 애플리케이션의 보안을 담당하는 프레임워크 | ||
|
|
||
| Spring Security는 필터 기반으로 동작한다. | ||
|
|
||
| ❗️필터: 요청이 Dispatcher Servlet으로 가기 전에 위치해있으며, 클라이언트와 자원 사이에서 요청과 응답 정보를 이용해 다양한 처리를 하는 컴포넌트 | ||
|
|
||
| ### 동작흐름 | ||
|
|
||
| HTTP 요청 | ||
| ↓ | ||
| Filter Chain (여러 보안 필터 순차 실행) | ||
| ↓ | ||
| 인증 처리 (AuthenticationManager) | ||
| ↓ | ||
| 인가 처리 (AccessDecisionManager) | ||
| ↓ | ||
| 컨트롤러 도달 (or 403/401 반환) | ||
|
|
||
| Spring Security는 `SecurityFilterChain`을 통해 요청마다 보안 처리를 수행한다. | ||
|
|
||
|  | ||
|
|
||
| SecurityFilterChain | ||
|
|
||
|  | ||
|
|
||
| Spring Security 인증 처리 과정 | ||
|
|
||
| ### 주요 특징 | ||
|
|
||
| | 특징 | 설명 | | ||
| | --- | --- | | ||
| | **다양한 인증 방식** | Form 로그인, HTTP Basic, JWT, OAuth2/OIDC, SAML 등 | | ||
| | **CSRF 보호** | Cross-Site Request Forgery 공격 방어 | | ||
| | **세션 관리** | 세션 고정 공격 방지, 동시 세션 제어 | | ||
| | **비밀번호 암호화** | BCrypt, Argon2 등 강력한 해시 알고리즘 | | ||
| | **Spring 통합** | Spring MVC, Spring Boot와 완벽하게 통합 | | ||
|
|
||
| ### 자주 사용되는 시나리오 | ||
|
|
||
| - **JWT 기반 인증** — REST API + 모바일/SPA 앱 | ||
| - **OAuth2 소셜 로그인** — 카카오, 구글, 네이버 로그인 | ||
| - **세션 기반 인증** — 전통적인 MVC 웹 앱 | ||
| - **메서드 레벨 보안** — `@PreAuthorize`, `@Secured` 어노테이션 | ||
| - 인증(Authentication)vs 인가(Authorization) | ||
|
|
||
|  | ||
|
|
||
| - 인증(Authentication) : 본인이누구인지확인 (로그인) | ||
| - 승인(Authorization) : 특정 리소스에권한이 있는지확인 (등급 권한) | ||
|
|
||
| | | 인증(Authentication) | 인가(Authorization) | | ||
| | --- | --- | --- | | ||
| | 기능 | 자격 증명 확인 | 권한 허기/거부 | | ||
| | 진행 방식 | 비밀번호, 생체인식, 일회용 핀 또는 앱 | 보안 팀에서 관리하는 설정 사용 | | ||
| | 사용자 확인 가능 여부 | 가능 | 불가능 | | ||
| | 사용자 변경 가능 여부 | 부분적 가능 | 불가능 | | ||
| | 데이터 전송 | ID 토큰 사용 | 액세스 토큰 사용 | | ||
| - Stateful vs Stateless | ||
| - Stateful: ****서버가 클라이언트 상태를 **기억** | ||
| - Stateless**:** 서버가 클라이언트 상태를 **기억하지 않음** | ||
|
|
||
| Stateful → 서버가 기억 → 세션/쿠키 → 전통적 웹 | ||
| Stateless → 서버가 무상태 → JWT 토큰 → REST API / 모바일 | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,11 +13,13 @@ | |
| import com.example.umc10thweek4.domain.member.repository.MemberNoticeSettingRepository; | ||
| import com.example.umc10thweek4.domain.member.repository.MemberRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.format.DateTimeParseException; | ||
| import java.util.List; | ||
|
|
||
| @Service | ||
|
|
@@ -28,6 +30,7 @@ public class MemberService { | |
| private final MemberRepository memberRepository; | ||
| private final MemberNoticeSettingRepository noticeSettingRepository; | ||
| private final MemberFoodPreferenceRepository foodPreferenceRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
|
|
||
| /** | ||
| * 회원가입 | ||
|
|
@@ -43,15 +46,17 @@ public MemberResDTO.SignUp signUp(MemberReqDTO.SignUp request) { | |
| throw new MemberException(MemberErrorCode.DUPLICATE_NICKNAME); | ||
| } | ||
|
|
||
| LocalDate birthday = parseBirthday(request.birthday()); | ||
| Gender gender = parseGender(request.gender()); | ||
|
|
||
| Member member = memberRepository.save( | ||
| Member.builder() | ||
| .name(request.name()) | ||
| .nickname(request.nickname()) | ||
| .email(request.email()) | ||
| .password(request.password()) // TODO: 비밀번호 암호화 | ||
| .birth(LocalDate.parse(request.birthday(), | ||
| DateTimeFormatter.ofPattern("yyyy-MM-dd"))) | ||
| .gender(Gender.valueOf(request.gender().toUpperCase())) | ||
| .password(passwordEncoder.encode(request.password())) | ||
| .birth(birthday) | ||
| .gender(gender) | ||
| .phoneNumber(request.phoneNum()) | ||
| .build() | ||
| ); | ||
|
|
@@ -80,6 +85,22 @@ public MemberResDTO.SignUp signUp(MemberReqDTO.SignUp request) { | |
| return MemberConverter.toSignUpRes(member); | ||
| } | ||
|
|
||
| private LocalDate parseBirthday(String birthday) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생년월일·성별 형식 검증을 Service에서 보완한 점은 좋습니다. 다음 단계에서는 |
||
| try { | ||
| return LocalDate.parse(birthday, DateTimeFormatter.ofPattern("yyyy-MM-dd")); | ||
| } catch (DateTimeParseException e) { | ||
| throw new MemberException(MemberErrorCode.INVALID_BIRTHDAY); | ||
| } | ||
| } | ||
|
|
||
| private Gender parseGender(String gender) { | ||
| try { | ||
| return Gender.valueOf(gender.toUpperCase()); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new MemberException(MemberErrorCode.INVALID_GENDER); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 마이페이지 조회 | ||
| */ | ||
|
|
@@ -93,4 +114,4 @@ public MemberResDTO.GetInfo getMyPage(Long userId) { | |
|
|
||
| return MemberConverter.toGetInfoRes(member, ns); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Authorization은 일반적으로 ‘승인’보다 ‘인가’로 번역하는 것이 적절합니다. 인증은 사용자가 누구인지 확인하는 과정이고, 인가는 인증된 사용자가 특정 리소스나 행위를 수행할 권한이 있는지 확인하는 과정으로 구분해 정리하는 것을 권장합니다.