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

[Docs] week7 & [Feat] Security & JWT 구현 #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[Docs] week7 & [Feat] Security & JWT 구현 #64

wants to merge 1 commit into from

Conversation

jiyunio
Copy link
Contributor

@jiyunio jiyunio commented May 27, 2024

📋 이슈 내용

close #60
close #61

✅ 체크리스트

  • week7
  • security & jwt 구현

📚 레퍼런스

@jiyunio jiyunio requested review from NARUBROWN and Juser0 May 27, 2024 06:59
@jiyunio jiyunio self-assigned this May 27, 2024
Copy link
Member

@Juser0 Juser0 left a comment

Choose a reason for hiding this comment

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

수고했어!

private final JwtProvider jwtProvider;
@Bean
public static BCryptPasswordEncoder bCryptPasswordEncoder() {
public static BCryptPasswordEncoder passwordEncoder() {
Copy link
Member

Choose a reason for hiding this comment

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

여기서 static class로 빈을 등록한 이유는?
그럴거면 따로 클래스를 만들어도 되지 않아?

.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class);
return http.build();
}


@Bean
public AuthenticationProvider authenticationProvider(){
Copy link
Member

Choose a reason for hiding this comment

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

이거는 언제 쓰는 거야?
이것도 따로 클래스로 빼도 괜찮지 않을까?

return new BCryptPasswordEncoder();
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.httpBasic(AbstractHttpConfigurer::disable)
.csrf(AbstractHttpConfigurer::disable)

//접근 제어
Copy link
Member

Choose a reason for hiding this comment

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

접근 제어를 다루는 부분이 100개면 100개의 requestMatchers를 적어줘야 할까?

@Override
public UserDetails loadUserByUsername(String userId) throws CustomException {
return memberRepository.findByUserId(userId)
.orElseThrow(()-> new CustomException(HttpStatus.UNAUTHORIZED, ErrorCode.NO_AUTHENTICATION_MEMBER));
Member member = memberRepository.findByUserId(userId)
Copy link
Member

Choose a reason for hiding this comment

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

해당 메서드는 결국 member의 정보를 가져오는 건데 리턴을 할 때는 왜 user.builder로 인스턴스화 해서 보내주는거야?

@@ -28,25 +36,37 @@ public SecretKey getSecretKey() {
return Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey));
}

public JwtDTO createToken(String userId) {
public JwtDTO createToken(Authentication authentication) {
log.info("createToken 메소드 들어옴");
Date now = new Date();
Copy link
Member

Choose a reason for hiding this comment

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

Date 타입은 Java 8부터 Deprecated 됐는데 해당 타입을 사용한 이유가 있을까?

@@ -28,25 +36,37 @@ public SecretKey getSecretKey() {
return Keys.hmacShaKeyFor(Decoders.BASE64.decode(secretKey));
}

public JwtDTO createToken(String userId) {
public JwtDTO createToken(Authentication authentication) {
Copy link
Member

Choose a reason for hiding this comment

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

토큰을 만들 때 authentication 객체를 담는 이유가 뭐야?

Copy link
Member

Choose a reason for hiding this comment

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

해당 클래스는 네 코드에서 어떻게 동작하는거야?

@@ -7,11 +7,13 @@
@Getter
@Setter
public class JwtDTO {
private String grantType;
Copy link
Member

Choose a reason for hiding this comment

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

여기서의 grantType이 의미하는 바가 뭐야?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] Security & JWT 구현 [Docs] week7
2 participants