-
Notifications
You must be signed in to change notification settings - Fork 2
계정(user)관련 기능 리팩토링 + 테스트 코드 추가 #113
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4cf4e1e
refactor: test code 간편화를 위한 UserEntityBuilder 클래스 작성
rodom1018 0d70b0c
feat: admin 페이지 ip 검사 로직 추가(필터 추가)
rodom1018 193069a
feat: 소셜 로그인 단위 테스트 작성 및 try catch 문 삭제하고 @RestControllerService 사용
rodom1018 e0a833e
Merge branch 'develop' into refactor-account
rodom1018 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,20 @@ | ||
| package com.woozuda.backend.account.dto; | ||
|
|
||
|
|
||
| import com.woozuda.backend.account.entity.AiType; | ||
| import com.woozuda.backend.account.entity.UserEntity; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| public class JoinDTO { | ||
| String username; | ||
| String password; | ||
|
|
||
| public static JoinDTO transDTO(UserEntity userEntity){ | ||
| return new JoinDTO(userEntity.getUsername(), userEntity.getPassword()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/woozuda/backend/exception/account/AccountExceptionHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.woozuda.backend.exception.account; | ||
|
|
||
|
|
||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.ErrorResponse; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @RestControllerAdvice | ||
| public class AccountExceptionHandler { | ||
|
|
||
| @ExceptionHandler(InvalidEmailException.class) | ||
| public ResponseEntity<Void> handleInvalidEmailException(InvalidEmailException e) { | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); | ||
| } | ||
|
|
||
| @ExceptionHandler(UsernameAlreadyExistsException.class) | ||
| public ResponseEntity<Void> handleUsernameAlreadyExistsException(UsernameAlreadyExistsException e) { | ||
| return ResponseEntity.status(HttpStatus.CONFLICT).build(); | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
...kend/exception/InvalidEmailException.java → ...eption/account/InvalidEmailException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ption/UsernameAlreadyExistsException.java → ...count/UsernameAlreadyExistsException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/woozuda/backend/security/jwt/IPCheckFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.woozuda.backend.security.jwt; | ||
|
|
||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class IPCheckFilter extends OncePerRequestFilter { | ||
|
|
||
| private final List<String> adminIps; | ||
|
|
||
| @Override | ||
| protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
|
|
||
| String remoteAddr = getClientIpAddr(request); | ||
|
|
||
| if (!adminIps.contains(remoteAddr)) { | ||
| response.sendError(HttpServletResponse.SC_FORBIDDEN, "IP not allowed"); | ||
| return; | ||
| } | ||
|
|
||
| filterChain.doFilter(request, response); | ||
| } | ||
|
|
||
| public static String getClientIpAddr(HttpServletRequest request) { | ||
| String ip = request.getHeader("X-Forwarded-For"); | ||
| if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | ||
| ip = request.getHeader("Proxy-Client-IP"); | ||
| } | ||
| if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | ||
| ip = request.getHeader("WL-Proxy-Client-IP"); | ||
| } | ||
| if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | ||
| ip = request.getHeader("HTTP_CLIENT_IP"); | ||
| } | ||
| if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | ||
| ip = request.getHeader("HTTP_X_FORWARDED_FOR"); | ||
| } | ||
| if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { | ||
| ip = request.getRemoteAddr(); | ||
| } | ||
| return ip; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,5 +93,8 @@ management: | |
| prometheus: | ||
| enabled: true #default | ||
|
|
||
| allow-ips: "${allow_ips}" | ||
|
|
||
| aes: | ||
| password: "${aes-password}" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
if문 조건이 전부다 동일한 것 같은데 이 부분 로직이 정확히 어떻게 되는 건가요?
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.
프록시 같은게 있을 때 client ip 가 바로 나오지 않는다고 하네요
아직 배포는 안해봐서 겪어보지는 못한 이슈입니다
Nginx가 프록시니까 넣어두었어요
참고 : https://stackoverflow.com/questions/4678797/how-do-i-get-the-remote-address-of-a-client-in-servlet