-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: 카카오 Redirect URI 관리 개선 -> Origin 정보 추출 방식으로 개선(#65) #67
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
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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ject/studytrip/global/annotation/ClientOrigin.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,10 @@ | ||
| package com.ject.studytrip.global.annotation; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target(ElementType.PARAMETER) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface ClientOrigin {} |
22 changes: 0 additions & 22 deletions
22
src/main/java/com/ject/studytrip/global/common/constants/SwaggerUrlConstants.java
This file was deleted.
Oops, something went wrong.
37 changes: 28 additions & 9 deletions
37
src/main/java/com/ject/studytrip/global/common/constants/UrlConstants.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 |
|---|---|---|
| @@ -1,18 +1,37 @@ | ||
| package com.ject.studytrip.global.common.constants; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum UrlConstants { | ||
| DEV_API_SERVER_URL("https://dev-api-studytrip.duckdns.org"), | ||
| LOCAL_API_SERVER_URL("http://localhost:8080"), | ||
| // CORS 허용 도메인 | ||
| CORS_DOMAINS( | ||
| "http://localhost:8080", | ||
| "https://dev-api-studytrip.duckdns.org", | ||
| "http://localhost:5173", | ||
| "https://localhost:5173", | ||
| "https://ject-4-client.vercel.app"), | ||
|
|
||
| PRODUCTION_CLIENT_URL("https://ject-4-client.vercel.app"), | ||
| LOCAL_CLIENT_URL("http://localhost:5173"), | ||
| LOCAL_SECURE_CLIENT_URL("https://localhost:5173"), | ||
| ; | ||
| // 정적 리소스 경로 | ||
| STATIC_RESOURCES( | ||
| "/favicon.ico", | ||
| "/firebase-messaging-sw.js", | ||
| "/v3/api-docs/**", | ||
| "/swagger-ui/**", | ||
| "/swagger-ui.html"), | ||
|
|
||
| private final String value; | ||
| // OAuth 콜백 경로 | ||
| CALLBACK_PATHS("/auth/callback/**"), | ||
|
|
||
| // Origin 추출이 필요한 경로 | ||
| ORIGIN_EXTRACT_PATHS("/api/auth/login/kakao", "/api/auth/signup/kakao"), | ||
|
|
||
| // 인증이 필요없는 API 경로 | ||
| PERMIT_ALL_API_PATHS("/api/auth/**", "/api/trips/categories"); | ||
|
|
||
| private final String[] urls; | ||
|
|
||
| UrlConstants(String... urls) { | ||
| this.urls = urls; | ||
| } | ||
| } |
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/ject/studytrip/global/security/OriginExtractionFilter.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.ject.studytrip.global.security; | ||
|
|
||
| import static com.ject.studytrip.global.common.constants.UrlConstants.*; | ||
|
|
||
| import com.google.common.net.HttpHeaders; | ||
| import com.ject.studytrip.global.exception.error.CommonErrorCode; | ||
| import com.ject.studytrip.global.util.OriginArgumentUtil; | ||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public class OriginExtractionFilter extends OncePerRequestFilter { | ||
| private static final String ATTRIBUTE_NAME = "origin"; | ||
|
|
||
| private final SecurityResponseHandler securityResponseHandler; | ||
|
|
||
| @Override | ||
| protected void doFilterInternal( | ||
| HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
| throws ServletException, IOException { | ||
| String origin = | ||
| OriginArgumentUtil.resolveOrigin( | ||
| request.getHeader(HttpHeaders.ORIGIN), | ||
| request.getScheme(), | ||
| request.getServerName(), | ||
| request.getServerPort()); | ||
|
|
||
| // origin null 검증 | ||
| if (origin == null) { | ||
| securityResponseHandler.sendResponse(response, CommonErrorCode.INVALID_ORIGIN); | ||
| return; | ||
| } | ||
|
|
||
| // 허용된 origin 검증 | ||
| List<String> allowedOrigins = Arrays.asList(CORS_DOMAINS.getUrls()); | ||
| if (!allowedOrigins.contains(origin)) { | ||
| securityResponseHandler.sendResponse(response, CommonErrorCode.UNSUPPORTED_ORIGIN); | ||
| return; | ||
| } | ||
|
|
||
| request.setAttribute(ATTRIBUTE_NAME, origin); | ||
| filterChain.doFilter(request, response); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.