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

Feature: OidcProvider 구현 및 Spring Security 초기 설정 #8

Merged
merged 12 commits into from
May 3, 2024

Conversation

lcomment
Copy link
Collaborator

@lcomment lcomment commented May 2, 2024

Issue Number

#4

Description

  • oidc의 특성을 살려 OidcProvider를 구현하였습니다. (apple, kakao, google)
  • spring security 초기 설정을 완료했습니다.
  • JwtProvider를 구현하였습니다.

Core Code

(설명으로 대체합니다)

아직 인증 필터는 구현하지 않았으나 기본적인 Spring Security 설정을 마무리했습니다. 인증은 다음과 같은 Flow로 진행됩니다.

  1. 요청이 들어옴
  2. 인증 필터에서 요청을 받고, 헤더에서 토큰 파싱 후 JwtProvider로 전달
  3. JwtProvider의 getAuthentication 메서드에서 인증 정보 확인 후 Authentication 리턴
  4. SecurityContext에 Authentication 저장

id token을 활용하는 oidc 인증에 대한 설명은 다음과 같습니다.

  1. Service 클래스에서 OidcProvider에 id token 전달
  2. 외부 OAuth 서버로 요청을 보내 공개 키 리스트를 받음
  3. PublicKeyProvider를 통해 공개 키 리스트 중 id token과 kid, 알고리즘이 동일한 공개 키를 얻음
  4. 공개키를 통해 id token을 claim으로 파싱하여 provider id를 얻어냄

etc

해당 기능 구현은 도메인 모델과 관련이 없어 추상화와 책임 분리에만 초점을 맞추어 구현했습니다. 다른 방향성이 있다면 편하게 말씀해주시고, 테스트의 경우, Filter를 구현하면서 작성해 올리겠습니다.

다음 테스크 순서는 Filter 및 ArgumentResolver 구현애플리케이션 로직 작성API 구현 입니다.

@lcomment lcomment added chore 빌드 매니저 및 환경 설정 feature 새로운 기능 개발 labels May 2, 2024
@lcomment lcomment requested a review from YongsHub May 2, 2024 14:11
@lcomment lcomment self-assigned this May 2, 2024
Copy link
Contributor

@YongsHub YongsHub left a comment

Choose a reason for hiding this comment

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

고생하셨습니다

import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
Copy link
Contributor

Choose a reason for hiding this comment

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

Apache Shiro security, Apache Geode's Integrated Security framework 등등 모르는게 많은데 추상화가 진짜 잘 되어 있네요 ㅋㅋㅋ

private Customizer<AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry> setAuthorizePath() {
return authorizeHttpRequests -> authorizeHttpRequests
.requestMatchers("/api/v1/**").permitAll()
// .requestMatchers("/api/v1/**").hasAnyRole("USER", "MERCHANT", "ADMIN")
Copy link
Contributor

Choose a reason for hiding this comment

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

이게 User Model에 있는 role과 관련이 있는거죠??!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네, 맞습니다!

Comment on lines +24 to +25
OidcPublicKey publicKey = publicKeys.getMatchedKey(tokenHeaders.get("kid"), tokenHeaders.get("alg"));

Copy link
Contributor

Choose a reason for hiding this comment

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

kid가 정확히 뭔가요?? alg는 알고리즘이라고 설명해주셔서 알겠는데 잘 모르겠네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

토큰을 검증하는 키 식별자라고 생각하시면 될것 같아요 ! k가 key입니다.


import com.fasterxml.jackson.databind.ObjectMapper;

public abstract class OidcProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

abstract vs interface, 추상 클래스를 선택한 이유가 있나요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이전 버전의 커밋으로 리뷰가 된거 같은데, interface로 교체했습니다 ! 아시다시피 보통 추상클래스는 확장, 인터페이스는 추상화를 위해서 사용하고, 해당 경우는 추상화를 활용하는게 맞아보여 교체했습니다.

@lcomment lcomment merged commit 6705fb5 into master May 3, 2024
1 check passed
@lcomment lcomment deleted the feature/#4 branch May 3, 2024 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore 빌드 매니저 및 환경 설정 feature 새로운 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants