-
Notifications
You must be signed in to change notification settings - Fork 1
OAuth2.0-version #30
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
base: feat/27-user,tree,treeITem+jwt
Are you sure you want to change the base?
OAuth2.0-version #30
Conversation
개요:의존성 변경과 보안 관련 클래스 및 설정에 대한 다양한 수정이 있었습니다. PostgreSQL JDBC 드라이버, h2 라이브러리 추가, Jakarta Validation API 제거, modelmapper 및 OAuth2 의존성 추가 등이 포함되어 있습니다. 상세 정보:
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
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.
Files selected (41)
- build.gradle (2)
- src/main/java/com/chukapoka/server/common/authority/AppConfig.java (1)
- src/main/java/com/chukapoka/server/common/authority/SecurityConfig.java (1)
- src/main/java/com/chukapoka/server/common/authority/jwt/JwtAuthenticationFilter.java (3)
- src/main/java/com/chukapoka/server/common/authority/jwt/JwtTokenProvider.java (9)
- src/main/java/com/chukapoka/server/common/authority/oauth2/dto/OAuth2Attribute.java (1)
- src/main/java/com/chukapoka/server/common/authority/oauth2/handler/CustomAuthenticationFailHandler.java (1)
- src/main/java/com/chukapoka/server/common/authority/oauth2/handler/CustomAuthenticationSuccessHandler.java (1)
- src/main/java/com/chukapoka/server/common/authority/oauth2/service/CustomOAuth2UserService.java (1)
- src/main/java/com/chukapoka/server/common/dto/CustomUser.java (1)
- src/main/java/com/chukapoka/server/common/dto/CustomUserDetails.java (1)
- src/main/java/com/chukapoka/server/common/dto/TokenDto.java (1)
- src/main/java/com/chukapoka/server/common/entity/Token.java (2)
- src/main/java/com/chukapoka/server/common/enums/TreeType.java (1)
- src/main/java/com/chukapoka/server/common/repository/TokenRepository.java (1)
- src/main/java/com/chukapoka/server/common/service/CustomUserDetailsService.java (2)
- src/main/java/com/chukapoka/server/tree/controller/TreeController.java (1)
- src/main/java/com/chukapoka/server/tree/dto/TreeCreateRequestDto.java (1)
- src/main/java/com/chukapoka/server/tree/dto/TreeDetailResponseDto.java (1)
- src/main/java/com/chukapoka/server/tree/dto/TreeList.java (1)
- src/main/java/com/chukapoka/server/tree/dto/TreeListResponseDto.java (1)
- src/main/java/com/chukapoka/server/tree/dto/TreeModifyRequestDto.java (1)
- src/main/java/com/chukapoka/server/tree/entity/Tree.java (1)
- src/main/java/com/chukapoka/server/tree/repository/TreeRepository.java (1)
- src/main/java/com/chukapoka/server/tree/service/TreeService.java (1)
- src/main/java/com/chukapoka/server/tree/service/TreeServiceImpl.java (1)
- src/main/java/com/chukapoka/server/treeItem/controller/TreeItemController.java (1)
- src/main/java/com/chukapoka/server/treeItem/dto/TreeItemCreateRequestDto.java (1)
- src/main/java/com/chukapoka/server/treeItem/dto/TreeItemDetailResponseDto.java (1)
- src/main/java/com/chukapoka/server/treeItem/dto/TreeItemListResponseDto.java (1)
- src/main/java/com/chukapoka/server/treeItem/dto/TreeItemModifyRequestDto.java (1)
- src/main/java/com/chukapoka/server/treeItem/entity/TreeItem.java (1)
- src/main/java/com/chukapoka/server/treeItem/repository/TreeItemRepository.java (1)
- src/main/java/com/chukapoka/server/treeItem/service/TreeItemService.java (1)
- src/main/java/com/chukapoka/server/treeItem/service/TreeItemServiceImpl.java (1)
- src/main/java/com/chukapoka/server/user/controller/HealthController.java (1)
- src/main/java/com/chukapoka/server/user/controller/UserController.java (2)
- src/main/java/com/chukapoka/server/user/dto/UserResponseDto.java (1)
- src/main/java/com/chukapoka/server/user/entity/User.java (1)
- src/main/java/com/chukapoka/server/user/repository/UserRepository.java (1)
- src/main/java/com/chukapoka/server/user/sevice/UserService.java (3)
Files ignored due to filter (2)
- screenshots/Oauth2.png
- src/main/resources/application.yaml
Files skipped from review due to trivial changes (10)
- src/main/java/com/chukapoka/server/common/authority/AppConfig.java
- src/main/java/com/chukapoka/server/common/dto/CustomUser.java
- src/main/java/com/chukapoka/server/common/repository/TokenRepository.java
- src/main/java/com/chukapoka/server/tree/dto/TreeList.java
- src/main/java/com/chukapoka/server/tree/dto/TreeListResponseDto.java
- src/main/java/com/chukapoka/server/treeItem/dto/TreeItemListResponseDto.java
- src/main/java/com/chukapoka/server/user/controller/HealthController.java
- src/main/java/com/chukapoka/server/user/dto/UserResponseDto.java
- src/main/java/com/chukapoka/server/user/repository/UserRepository.java
- src/main/java/com/chukapoka/server/common/authority/SecurityConfig.java (diff too large)
Review comments generated (28)
- Review: 19
- LGTM: 9
Tips
Chat with
CodeRabbit Bot (@coderabbitai)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitaiin a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignoreanywhere in the PR description to pause further reviews from the bot.
|
|
||
| public static final String AUTHORIZATION_HEADER = "Authorization"; | ||
| public static final String BEARER_PREFIX = "Bearer"; | ||
|
|
||
| private final JwtTokenProvider jwtTokenProvider; | ||
| private final TokenRepository tokenRepository; | ||
|
|
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.
| public class CustomOAuth2UserService implements OAuth2UserService<OAuth2UserRequest, OAuth2User> { | ||
| private final UserRepository userRepository; |
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.
| String registrationId = userRequest.getClientRegistration().getRegistrationId(); | ||
| String userNameAttributeName = userRequest.getClientRegistration() | ||
| .getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName(); |
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.
| OAuth2Attribute.of(registrationId, userNameAttributeName, oAuth2User.getAttributes()); | ||
|
|
||
| // 5. OAuth2Attribute의 속성값들을 Map으로 반환 받는다. | ||
| Map<String, Object> memberAttribute = oAuth2Attribute.convertToMap(); |
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.
| String email = (String) memberAttribute.get("email"); | ||
| log.debug("Email retrieved from OAuth2 attributes: {}", email); |
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.
|
|
||
| // 만료 시간을 나타내는 컬럼 추가 | ||
| @Column(name = "at_expiration") | ||
| private String atExpiration; // access token 만료 시간 | ||
|
|
||
| @Column(name = "rt_expiration") | ||
| private String rtExpiration; // refresh token 만료 시간 | ||
|
|
||
| @Builder | ||
| public Token(String key, String atValue, String rtValue) { | ||
| public Token(String key, String atValue, String rtValue, String atExpiration, String rtExpiration) { | ||
| this.key = key; | ||
| this.atValue = atValue; | ||
| this.rtValue = rtValue; | ||
| this.atExpiration = atExpiration; | ||
| this.rtExpiration = rtExpiration; | ||
| } | ||
|
|
||
| public Token updateValues(String accessToken, String refreshToken) { | ||
| this.atValue = accessToken; | ||
| this.rtValue = refreshToken; | ||
| return this; | ||
| } | ||
|
|
||
|
|
||
| public TokenResponseDto toResponseDto(){ | ||
| return new TokenResponseDto(this.atValue); | ||
| } |
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.
| package com.chukapoka.server.treeItem.dto; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public class TreeItemModifyRequestDto { | ||
|
|
||
| private String title; | ||
| private String content; | ||
| private String treeItemColor; | ||
| } |
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.
| package com.chukapoka.server.treeItem.repository; | ||
|
|
||
| import com.chukapoka.server.treeItem.entity.TreeItem; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface TreeItemRepository extends JpaRepository<TreeItem, String> { | ||
| List<TreeItem> findByTreeId(String treeId); | ||
| Optional<TreeItem> findByIdAndUpdatedBy(String treeItemId, long 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.
| @PostMapping("/reissue") | ||
| public BaseResponse<TokenResponseDto> reissue() { | ||
| long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId(); | ||
| long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId(); |
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.
The type casting from SecurityContextHolder.getContext().getAuthentication().getPrincipal() seems to have changed from CustomUser to CustomUserDetails. Please verify if this change is intentional and ensure it aligns with the rest of the codebase.
- long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
+ long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();| public BaseResponse<ResultType> logout() { | ||
| // 인증된 사용자 Id | ||
| long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId(); | ||
| long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId(); |
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.
Similar to the previous comment, there is a type casting change from CustomUser to CustomUserDetails. Verify if this change is intended and consistent with other parts of the code.
- long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
+ long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
Issues 번호 :
Closes #29
변경, 추가된 코드(설명 등)
OAUTH2.0
GOOGLE
KAKAO
NAVER
로그인 테스트 및 토큰생성 처리 확인
비밀번호 null 로직에서 -> 비밀번호를 OAuth2로 로그인시 고유한 id값으로 셋팅
코드 주의점
FRONT-END
현재 테스트 url
front - http://localhost:8080
back - http://localhost:3000
<a href="http://localhost:3000/oauth2/authorization/google?redirect_uri=http://localhost:3000&mode=login">이런식으로 접근해야하나? 좀 더 알아봐야 할 것 같다
Summary by CodeRabbit