-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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.
수고했어!
private final JwtProvider jwtProvider; | ||
@Bean | ||
public static BCryptPasswordEncoder bCryptPasswordEncoder() { | ||
public static BCryptPasswordEncoder passwordEncoder() { |
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.
여기서 static class로 빈을 등록한 이유는?
그럴거면 따로 클래스를 만들어도 되지 않아?
.sessionManagement(session -> session | ||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) | ||
.addFilterBefore(new JwtAuthenticationFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class); | ||
return http.build(); | ||
} | ||
|
||
|
||
@Bean | ||
public AuthenticationProvider authenticationProvider(){ |
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.
이거는 언제 쓰는 거야?
이것도 따로 클래스로 빼도 괜찮지 않을까?
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Bean | ||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
http | ||
.httpBasic(AbstractHttpConfigurer::disable) | ||
.csrf(AbstractHttpConfigurer::disable) | ||
|
||
//접근 제어 |
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.
접근 제어를 다루는 부분이 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) |
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.
해당 메서드는 결국 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(); |
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.
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) { |
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.
토큰을 만들 때 authentication 객체를 담는 이유가 뭐야?
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.
해당 클래스는 네 코드에서 어떻게 동작하는거야?
@@ -7,11 +7,13 @@ | |||
@Getter | |||
@Setter | |||
public class JwtDTO { | |||
private String grantType; |
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.
여기서의 grantType이 의미하는 바가 뭐야?
📋 이슈 내용
close #60
close #61
✅ 체크리스트
📚 레퍼런스