-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SAMBAD-220] 클라이언트 기반 Redirect URL 설정 기능 구현 (#85)
- Loading branch information
Showing
5 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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
49 changes: 49 additions & 0 deletions
49
src/main/java/org/depromeet/sambad/moring/auth/presentation/RedirectUrlFilter.java
This file contains 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,49 @@ | ||
package org.depromeet.sambad.moring.auth.presentation; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.depromeet.sambad.moring.auth.application.TokenInjector; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class RedirectUrlFilter extends OncePerRequestFilter { | ||
|
||
private final TokenInjector tokenInjector; | ||
|
||
public static final String REDIRECT_URL_QUERY_PARAM = "redirectUrl"; | ||
public static final String REDIRECT_URL_COOKIE_NAME = "redirect_url"; | ||
private static final List<String> REDIRECT_URL_INJECTION_PATTERNS = List.of( | ||
"/oauth2/authorization/.*" | ||
); | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain | ||
) throws ServletException, IOException { | ||
if (isRedirectRequest(request)) { | ||
tokenInjector.invalidateCookie(REDIRECT_URL_COOKIE_NAME, response); | ||
String redirectUri = request.getParameter(REDIRECT_URL_QUERY_PARAM); | ||
|
||
if (StringUtils.hasText(redirectUri)) { | ||
tokenInjector.addCookie(REDIRECT_URL_COOKIE_NAME, redirectUri, 3600, response); | ||
} | ||
} | ||
|
||
filterChain.doFilter(request, response); | ||
} | ||
|
||
private boolean isRedirectRequest(HttpServletRequest request) { | ||
return REDIRECT_URL_INJECTION_PATTERNS.stream() | ||
.anyMatch(request.getRequestURI()::matches); | ||
} | ||
} |
This file contains 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