Skip to content

Conversation

@joowojr
Copy link
Contributor

@joowojr joowojr commented Jan 22, 2025

📄 요약(Summary)

Spring security & jwt 관련 로직 구현 및 로그인 API 구현

✍🏼 상세(More)

PR Desciption

변경 사항 설명

  • Spring Security 관련 설정
    • Spring Security 및 JWT 검증 관련 설정을 위한 SecurityConfig, SecurityAuthConfig, SecurityFilterConfig 클래스 추가
  • Spring Security Handler 및 Filter 구현:
    • JWT 토큰 검증 및 사용자 정보 처리를 위한 JwtAuthenticationFilter와 JwtExceptionFilter 구현
  • SecurityUserDetails
    • 사용자 인증 정보를 처리하는 SecurityUserDetailsService와 SecurityUserDetails 클래스 구현
  • Redis 리프레시 토큰 adapter layer 구현
    • 리프레시 토큰을 Redis에 저장하고 관리
    • 추후 블랙리스트 로직 구현 필요함
  • 토큰 Provider 및 Claims 처리
    • 토큰을 생성하고 정보를 조회하는 Jwt Provider 구현

Requirements for Reviewer

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

@TaskFlow-CLAP/taskflow-be

  • 사용자 인증이 필요할 시에 @AuthenticationPrincipal을 통해 주입하여 사용합니다.
  • 기능에 대하여 특정 역할에 대해서 접근 권한을 설정해야할 때 @secured 애너테이션을 통해 메서드 기반 접근 제한을 해주시면 됩니다.
      @Operation(description = "단일 회원 등록 API")
      @PostMapping("/members")
      @Secured("ROLE_ADMIN")
      public void registerMember(@AuthenticationPrincipal SecurityUserDetails userInfo,
                                 @RequestBody @Valid RegisterMemberRequest request){
          registerMemberUsecase.registerMember(userInfo.getUserId(), request);
      }`
    
    
  • JwtException과 AuthException의 경우, 비즈니스 로직과 구별되는 보안적으로 중요한 예외이기 때문에 분리하였습니다.

PR Log

PR 작업하면서 고민했던 내용, 해결한 내용, 고민 중인 내용 등

새롭게 배운 것

고민 중인 사항

Security 필터

  ├── adapter
  │   ├── inbound
  │   │   ├── security
  │   │   │   ├── CustomGrantedAuthority.java
  │   │   │   ├── SecurityUserDetails.java
  │   │   │   ├── SecurityUserDetailsService.java
  │   │   │   ├── filter
  │   │   │   │   ├── JwtAuthenticationFilter.java
  │   │   │   │   ├── JwtErrorCodeUtil.java
  │   │   │   │   └── JwtExceptionFilter.java
  │   │   │   └── handler
  │   │   │       ├── JwtAccessDeniedHandler.java
  │   │   │       └── JwtAuthenticationEntryPoint.java
  • security 로직 중 웹 요청의 진입 점에 해당하는 class들을 adapter/inbound/security로 패키징

JWT 처리 클래스

│   └── outbound
  │       ├── api
  │       ├── infrastructure
  │       │   └── redis
  │       │       └── refresh
  │       │           ├── RefreshTokenAdapter.java
  │       │           ├── RefreshTokenEntity.java
  │       │           ├── RefreshTokenMapper.java
  │       │           └── RefreshTokenRepository.java
  │       ├── jwt
  │       │   ├── JwtClaims.java
  │       │   ├── access
  │       │   │   ├── AccessTokenClaim.java
  │       │   │   ├── AccessTokenClaimKeys.java
  │       │   │   └── AccessTokenProvider.java
  │       │   └── refresh
  │       │       ├── RefreshTokenClaim.java
  │       │       ├── RefreshTokenClaimKeys.java
  │       │       └── RefreshTokenProvider.java
  • JWT 처리가 보통 보안에도 관련된 부분이기 때문에, 이 로직이 Outbound로 위치하는 것에 대해서 고민을 하였습니다.
  • 일단은 JWT 라이브러리와의 상호작용을 담당하는 어댑터 역할을 하기 때문에 adapter/outbound/jwt로 패키징하였습니다.

첨부 자료

Requirements for Reviewer

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

✅ 체크리스트(Checklist)

  • PR 양식에 맞게 작성했습니다
  • 모든 테스트가 통과했습니다
  • 프로그램이 정상적으로 작동합니다
  • 적절한 PR 라벨을 설정했습니다
  • 불필요한 코드를 제거했습니다

🚪 이슈 번호(Issue numbers)

Closes #42
Closes #19

<body>
- MethodSecurityConfig: Spring Security의 메소드 보안 기능을 활성화
- SecurityAdapterConfig: HttpSecurity 설정을 통해 인증 제공자와 JWT 필터로 보안 구성
- SecurityAuthConfig: Spring Security 관련 Bean들을 정의
- SecurityConfig; 필터 체인 설정 및 경로에 대한 접근 권한 설정
- SecurityFilterConfig: JWT 인증 및 예외 처리 관련 필터 설정

<footer>
- 관련: #42
@joowojr joowojr changed the title CLAP-84 Spring security & jwt 관련 로직 구현 및 로그인 API 구 CLAP-60&84 Spring security & jwt 관련 로직 구현 및 로그인 API 구현 Jan 22, 2025
@joowojr joowojr self-assigned this Jan 22, 2025
@joowojr joowojr added ✨ feature 구현·개선 사항에 관련된 내용입니다 HIGH 우선순위 상 labels Jan 22, 2025
Copy link
Collaborator

@Sihun23 Sihun23 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!

CLAP-61 비밀번호 재설정 API 구현 및 임시 토큰 발급 로직 구현
CLAP-57 회원 등록 API 리팩토링
@joowojr joowojr merged commit 5b3a266 into develop Jan 23, 2025
1 check passed
@joowojr joowojr deleted the CLAP-84 branch January 26, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ feature 구현·개선 사항에 관련된 내용입니다 HIGH 우선순위 상

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLAP-84 Spring security 설정 및 jwt 관련 클래스 구현 CLAP-60 로그인 API 구현

4 participants