Skip to content

[케이] Chapter 9. Spring Security - JWT, OAuth#143

Open
harim789 wants to merge 1 commit into
kei/mainfrom
kei/#132
Open

[케이] Chapter 9. Spring Security - JWT, OAuth#143
harim789 wants to merge 1 commit into
kei/mainfrom
kei/#132

Conversation

@harim789
Copy link
Copy Markdown

@harim789 harim789 commented May 31, 2026

✏️ 작업 내용

JWT 기반 인증 구현

  • JwtUtil, JwtAuthFilter 추가 및 SecurityConfig를 STATELESS로 전환
  • 회원가입(BCrypt 해싱) / 로그인(JWT 발급) API 구현
  • 마이페이지 API를 @AuthenticationPrincipal 기반으로 리팩토링
image image image image image

#️⃣ 연관된 이슈

closes #132


💡 함께 공유하고 싶은 부분

해당 주차를 공부하면서 함께 이야기하고 싶은 주제를 남겨주세요.

(어려웠던 부분과 해결 과정, 핵심 코드, 참고한 자료 등)


🤔 질문

해당 주차 워크북을 공부하면서 궁금했던 질문들을 남겨주세요.


✅ 워크북 체크리스트

  • 모든 핵심 키워드 정리를 마쳤나요?
  • 핵심 키워드에 대해 완벽히 이해하셨나요?
  • 이론 학습 이후 직접 실습을 해보는 시간을 가졌나요?
  • 미션을 수행하셨나요?
  • 미션을 기록하셨나요?

✅ 컨벤션 체크리스트

  • 디렉토리 구조 컨벤션을 잘 지켰나요?
  • pr 제목을 컨벤션에 맞게 작성하였나요?
  • pr에 해당되는 이슈를 연결하였나요?
  • 적절한 라벨을 설정하였나요?
  • 스터디원들에게 code review를 요청하기 위해 reviewer를 등록하였나요?
  • 닉네임/main 브랜치의 최신 상태를 반영하고 있는지 확인했나요?

📌 주안점

@harim789 harim789 requested a review from Copilot May 31, 2026 16:58
@harim789 harim789 self-assigned this May 31, 2026
@harim789 harim789 requested a review from a team May 31, 2026 16:58
@harim789 harim789 added the 🚀Week 9 9주차 워크북 미션 label May 31, 2026
@harim789 harim789 linked an issue May 31, 2026 that may be closed by this pull request
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

JWT 기반 인증(로그인/회원가입)과 Security 설정을 토큰 기반(STATELESS)으로 전환하고, 인증된 사용자 정보를 활용하도록 마이페이지 API를 리팩토링한 PR입니다.

Changes:

  • JJWT 기반 토큰 생성/검증 유틸(JwtUtil) 및 인증 필터(JwtAuthFilter) 추가
  • SecurityConfig를 STATELESS로 전환하고 JWT 필터 체인에 등록
  • 로그인 API/DTO/컨버터 추가 및 마이페이지를 @AuthenticationPrincipal 기반으로 변경

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/com/example/umc10th/global/security/util/JwtUtil.java JWT 생성/파싱 유틸 추가
src/main/java/com/example/umc10th/global/security/filter/JwtAuthFilter.java Authorization 헤더 기반 인증 처리 필터 추가
src/main/java/com/example/umc10th/global/config/SecurityConfig.java 세션 비활성화(STATELESS), JWT 필터 등록, permitAll 경로 조정
src/main/java/com/example/umc10th/domain/member/service/MemberService.java 로그인 로직 추가 및 마이페이지 서비스 시그니처 변경
src/main/java/com/example/umc10th/domain/member/controller/MemberController.java 마이페이지 principal 기반 변경 + 로그인 엔드포인트 추가
src/main/java/com/example/umc10th/domain/member/dto/MemberReqDTO.java 로그인 요청 DTO 추가
src/main/java/com/example/umc10th/domain/member/dto/MemberResDTO.java 로그인 응답 DTO 추가
src/main/java/com/example/umc10th/domain/member/converter/MemberConverter.java 로그인 응답 변환 추가
src/main/java/com/example/umc10th/domain/member/exception/code/MemberSuccessCode.java 로그인 성공 코드 추가(중복 코드 이슈 존재)
src/main/java/com/example/umc10th/domain/member/exception/code/MemberErrorCode.java 비밀번호 불일치 에러 코드 추가
src/main/java/com/example/umc10th/domain/member/entity/Member.java social_type 컬럼 길이 지정
build.gradle JJWT 및 configuration processor 의존성 추가
Comments suppressed due to low confidence (1)

src/main/java/com/example/umc10th/global/config/SecurityConfig.java:69

  • STATELESS + formLogin 비활성화 상태에서 logoutSuccessUrl("/login?logout")로 리다이렉트하면 /login 엔드포인트가 없어서 404가 날 수 있습니다. 토큰 기반 API라면 로그아웃을 비활성화하거나(클라이언트에서 토큰 폐기) 별도 성공 핸들러로 200을 반환하도록 맞추는 편이 일관적입니다.
                .logout(logout -> logout
                        .logoutUrl("/logout")
                        .logoutSuccessUrl("/login?logout")
                        .permitAll()
                );

Comment on lines 12 to 16
SIGN_UP(HttpStatus.OK, "MEMBER200_1", "회원가입에 성공했습니다."),
GET_HOME(HttpStatus.OK, "MEMBER200_2", "홈 화면 조회에 성공했습니다."),
GET_MY_PAGE(HttpStatus.OK, "MEMBER200_3", "성공적으로 유저를 조회했습니다.");
GET_MY_PAGE(HttpStatus.OK, "MEMBER200_3", "성공적으로 유저를 조회했습니다."),
LOGIN(HttpStatus.OK, "MEMBER200_2", "로그인에 성공했습니다.");

Comment on lines +59 to +63
// 5. 다음 필터로
filterChain.doFilter(request, response);

} catch (Exception e) {
// 토큰 파싱 실패 / 만료 / 서명 불일치 등 → 401 응답통일
Comment on lines +46 to +48
// 3. "Bearer " 떼기
token = token.replace("Bearer ", "");

Comment on lines 35 to 38
"/v3/api-docs/**",
"/auth/**",
"/api/v1/auth/**", // 회원가입 + 로그인 = 인증 없이 허용

Comment on lines +26 to +32
public JwtUtil(
@Value("${jwt.token.secretKey}") String secret,
@Value("${jwt.token.expiration.access}") Long accessExpiration
) {
this.secretKey = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8));
this.accessExpiration = Duration.ofMillis(accessExpiration);
}
Copy link
Copy Markdown

@CokaNuri CokaNuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JWT 인증 필터를 생성해 SecurityConfig에 JWT 필터를 잘 삽입하셨습니다!
마이페이지도 @AuthenticationPrincipal로 인증객체를 받아 처리하는걸로 잘 수정하셨어요!

로그인 관련해서 자주 등장하는 개념인 CORS에 대해서도 공부해보시면 좋을 것 같아요.
고생하셨습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚀Week 9 9주차 워크북 미션

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chapter 9. Spring Security - JWT, OAuth

3 participants