Skip to content

Conversation

@sin-hyunjin
Copy link
Contributor

@sin-hyunjin sin-hyunjin commented Mar 27, 2024

Issues 번호 :

Closes #31

변경, 추가된 코드(설명 등)

User , Tree TreeItem + jwt-version #28 에 추가

  • backend server에서 Swagger를 이용한 API 명세서 확인 및 테스트 가능
  • 서버 실행 후 http://{서버 주소}/swagger-ui/index.html 로 접속가능

Swagger-ui 접속

image
  • Authorize에 Token 값 입력

회원가입 테스트

image

오류

h2 로그인시 오류

image image

오류해결
https://stackoverflow.com/questions/65894268/how-does-headers-frameoptions-disable-work

.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))

h2 요소를 사용 비활성화시킴

  - TreeRequestDto 추가 및 @Valid검사
- TreeList
  - TreeListResponseDto추가
  - List데이터가 변경될수 있기때문에 TreeList 추가
- deleteTree
  - @PathVariable treeId값으로 트리삭제
   - TreeDetailResponseDto 추가 (treeitem 필드 필요)
- 상세정보를 위한 modelMapper 추가
   - TreeDetailResponseDto 추가 (treeitem 필드 필요)
- 상세정보를 위한 modelMapper 추가
Tree, TreeItem entity - id값을 String으로 변경에 따른 service, controller 수정
Tree
  Controller
  - createTree, treeDetail, treeModify 반환값을 TreeDetailResponseDto 로수정
  - treeDetail로 트리 상세정보 가져올 때 트리아이템 목록 가져올수 있도록 만듬

 TreeItem
 - treeItem 생성메서드 만듬
트리아이템(리스트) Get "api/treeItem"
트라아이템(상세정보) Get "api/treeItem/{treeItemId}"
트리아이템 수정 PUT "api/treeItem/{treeItemId}"
트리아이템 삭제 DELETE "api/treeItem/{treeItemId}"
```
{
    "resultCode": "SUCCESS",
    "data": {
        "result": "SUCCESS",
        "email": "blackduvet52@gmail.com",
        "userId": 1,
        "token": {
            "accessToken": "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiYXV0aCI6IlJPTEVfVVNFUiIsInVzZXJJZCI6MSwiaWF0IjoxNzEwNjg1NDE2LCJleHAiOjE3MTA2ODcyMTZ9.qnFvAG-tffdzkcAxwSY-QnBcHNzI612-GkUqY24sS5M"
        }
    },
    ```
### TREE
- userId를 CustomUserDetails에서 가져오게 수정
- service부분 modelmapper 대신 toentity로 수정
TreeItem 수정 부분 뺴고 ModelMapper -> ToEntity()로 수정
@github-actions
Copy link

github-actions bot commented Mar 27, 2024

Image description CodeRabbit

개요:

의존성 변경과 새로운 라이브러리 추가가 주요 변경 사항으로 나타났습니다. 또한 보안 설정 및 JWT 토큰 관련 설정이 업데이트되었으며, 사용자 정보 클래스 및 메서드 시그니처에 변화가 있었습니다.

상세 정보:

파일 경로 변경 내용
build.gradle PostgreSQL JDBC 드라이버 및 h2 라이브러리 주석 처리, modelmapper 및 swagger3 라이브러리 추가
AppConfig.java ModelMapper 빈 설정 코드 추가
SecurityConfig.java @requiredargsconstructor 어노테이션 추가, rest api 설정 변경, 인증 및 인가 설정 수정
SwaggerConfig.java JWT 토큰값 확인을 위한 설정 추가
JwtAuthenticationFilter.java 패키지명 변경, 주석 처리 코드 제거
CustomUser.java 삭제
CustomUserDetails.java getAuthorities() 및 getUsername() 메서드 추가
TokenDto.java accessTokenExpiresIn 필드 변경
Token.java atExpiration 및 rtExpiration 필드 추가, 생성자 및 updateValues 메서드 시그니처 변경
TreeType.java 새로운 TreeType 열거형 추가
TokenRepository.java getAccessToken 메서드 주석 처리
CustomUserDetailsService.java CustomUser 대신 CustomUserDetails 사용으로 createUserDetails 메서드 변경
TreeRepository.java findAllTrees() 메서드 추가
TreeService.java 새로운 메서드 추가

Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If 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.

@sin-hyunjin sin-hyunjin self-assigned this Mar 27, 2024
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 384453f and 326509e commits.
Files selected (38)
  • 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/SwaggerConfig.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/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 (3)
  • screenshots/Oauth2.png
  • src/main/resources/application.yaml
  • swagger.yaml
Files skipped from review due to trivial changes (5)
  • src/main/java/com/chukapoka/server/common/dto/CustomUser.java
  • src/main/java/com/chukapoka/server/tree/dto/TreeListResponseDto.java
  • src/main/java/com/chukapoka/server/treeItem/repository/TreeItemRepository.java
  • src/main/java/com/chukapoka/server/user/controller/HealthController.java
  • src/main/java/com/chukapoka/server/user/dto/UserResponseDto.java
Review comments generated (30)
  • Review: 23
  • LGTM: 7

Tips

Chat with Image description 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 @coderabbitai in 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: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines 25 to 29

public static final String AUTHORIZATION_HEADER = "Authorization";
public static final String BEARER_PREFIX = "Bearer";

private final JwtTokenProvider jwtTokenProvider;
private final TokenRepository tokenRepository;

Choose a reason for hiding this comment

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

Image description CodeRabbit

The import statement and package declaration seem to be incorrect. Please ensure that the package structure matches the directory structure.

- package com.chukapoka.server.common.authority;
+ package com.chukapoka.server.common.authority.jwt;

- import com.chukapoka.server.common.entity.Token;
+ import com.chukapoka.server.common.authority.jwt.JwtTokenProvider;

Comment on lines 35 to 40
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// 1. Request Header 에서 토큰을 꺼냄
String accessToken = resolveToken((HttpServletRequest) request);
// String data = tokenRepository.getAccessToken(token);
// System.out.println("data = " + data);
// 2. validateToken 으로 토큰 유효성 검사
// 정상 토큰이면 해당 토큰으로 Authentication 을 가져와서 SecurityContext 에 저장
if (StringUtils.hasText(accessToken)) {

Choose a reason for hiding this comment

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

Image description CodeRabbit

It seems that there are commented-out lines related to accessing data from the token repository. Make sure these lines are removed if they are no longer needed.

-//        String data = tokenRepository.getAccessToken(token);
-//        System.out.println("data = " + data);

build.gradle Outdated
Comment on lines 38 to 40
runtimeOnly 'org.postgresql:postgresql'
// h2
runtimeOnly 'com.h2database:h2'
// runtimeOnly 'com.h2database:h2'

Choose a reason for hiding this comment

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

Image description CodeRabbit

org.postgresql:postgresql 의존성이 주석 처리되고 com.h2database:h2 의존성이 추가되었습니다. 변경 사항을 확인해야 합니다.

- //	runtimeOnly 'org.postgresql:postgresql'
+ 	runtimeOnly 'org.postgresql:postgresql'
- //	runtimeOnly 'com.h2database:h2'
+ 	//	runtimeOnly 'com.h2database:h2'

Comment on lines +58 to +62
// modelmapper
implementation 'org.modelmapper:modelmapper:2.4.4'

// swagger3
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

Choose a reason for hiding this comment

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

Image description CodeRabbit

modelmapperswagger3 라이브러리가 추가되었습니다. 새로운 의존성을 확인해야 합니다.

+ 	// modelmapper
+ 	implementation 'org.modelmapper:modelmapper:2.4.4'
+ 
+ 	// swagger3
+ 	implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'

Comment on lines +16 to +17
private String atExpiration;
private String rtExpiration;

Choose a reason for hiding this comment

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

Image description CodeRabbit

The field names atExpiration and rtExpiration have been added in place of accessTokenExpiresIn. This change seems appropriate for specifying the expiration times for access tokens and refresh tokens.

-    private Long accessTokenExpiresIn;
+    private String atExpiration;
+    private String rtExpiration;

Comment on lines 59 to 65
/** 토큰 재발급(refresh token 유효한 상태) */
@PostMapping("/reissue")
public BaseResponse<TokenResponseDto> reissue() {
long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
TokenResponseDto tokenDto = userService.reissue(userId);
return new BaseResponse<>(ResultType.SUCCESS, tokenDto);
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-22]

The casting from SecurityContextHolder.getContext().getAuthentication().getPrincipal() to CustomUserDetails seems incorrect. Please verify if this casting is necessary and ensure it aligns with the correct user details class.

-     long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
+     long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();

---end_change_section---

---new_hunk---

71:         long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();

---old_hunk---

        long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();

Comment on lines 59 to 65
/** 토큰 재발급(refresh token 유효한 상태) */
@PostMapping("/reissue")
public BaseResponse<TokenResponseDto> reissue() {
long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
TokenResponseDto tokenDto = userService.reissue(userId);
return new BaseResponse<>(ResultType.SUCCESS, tokenDto);
}

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [31-31]

The casting from SecurityContextHolder.getContext().getAuthentication().getPrincipal() to CustomUserDetails appears to be inconsistent with the previous change. Please ensure consistency in the casting approach.

-     long userId = ((CustomUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();
+     long userId = ((CustomUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUserId();

---end_change_section---

Comment on lines 2 to 9



import com.chukapoka.server.common.authority.JwtTokenProvider;

import com.chukapoka.server.common.dto.CustomUser;
import com.chukapoka.server.common.authority.jwt.JwtTokenProvider;
import com.chukapoka.server.common.dto.CustomUserDetails;
import com.chukapoka.server.common.dto.TokenDto;
import com.chukapoka.server.common.dto.TokenResponseDto;
import com.chukapoka.server.common.entity.Token;

Choose a reason for hiding this comment

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

Image description CodeRabbit

Note: This review was outside of the patch, but no patch was found that overlapped with it. Original lines [22-22]

There seems to be a missing import statement for com.chukapoka.server.common.dto.CustomUserDetails.

+ import com.chukapoka.server.common.dto.CustomUserDetails;

Comment on lines +154 to 156
new CustomUserDetails(user),
null,
List.of(

Choose a reason for hiding this comment

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

Image description CodeRabbit

The code snippet has been updated to use CustomUserDetails instead of CustomUser. This change seems appropriate.

-                new CustomUser(
-                        user.getId(),
-                        user.getPassword(),
-                        List.of(
-                                new SimpleGrantedAuthority("ROLE" + Authority.USER.getAuthority()))
-                ),
+                 new CustomUserDetails(user),

Comment on lines +170 to +171
.atExpiration(jwtToken.getAtExpiration())
.rtExpiration(jwtToken.getRtExpiration())

Choose a reason for hiding this comment

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

Image description CodeRabbit

New fields atExpiration and rtExpiration are being set in the TokenDto object. This change appears to be necessary for handling token expiration.

+                 .atExpiration(jwtToken.getAtExpiration())
+                 .rtExpiration(jwtToken.getRtExpiration())

@sin-hyunjin sin-hyunjin changed the title 추가 + swagger3.0 version #28 + swagger3.0 version Mar 27, 2024
@sin-hyunjin sin-hyunjin changed the title #28 + swagger3.0 version #28 추가 + swagger3.0 version Mar 27, 2024
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.

SpringBoot-Swagger3.0 적용 테스트

2 participants