forked from codesquad-members-2024/be-airdnb
-
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.
fix. URI 사용하여 path 추출 fix. target url 경로 추출 fix. success handler custom fix. savedRequestAwareAuthenticationSuccessHandler사용 fix. redirect URI 경로 재수정 fix. security redirect uri 경로 수정
- Loading branch information
Showing
3 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
25 changes: 0 additions & 25 deletions
25
BE/src/main/java/team07/airbnb/config/security/CustomAuthenticationSuccessHandler.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
BE/src/main/java/team07/airbnb/config/security/CustomSuccessHandler.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,47 @@ | ||
package team07.airbnb.config.security; | ||
|
||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.savedrequest.HttpSessionRequestCache; | ||
import org.springframework.security.web.savedrequest.RequestCache; | ||
import org.springframework.security.web.savedrequest.SavedRequest; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
@Component | ||
public class CustomSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
|
||
private final RequestCache requestCache = new HttpSessionRequestCache(); | ||
|
||
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { | ||
SavedRequest savedRequest = requestCache.getRequest(request, response); | ||
|
||
if (savedRequest == null) { | ||
super.onAuthenticationSuccess(request, response, authentication); | ||
return; | ||
} | ||
|
||
String targetUrl = savedRequest.getRedirectUrl(); | ||
|
||
try { | ||
URI targetUri = new URI(targetUrl); | ||
String path = targetUri.getPath(); | ||
String query = targetUri.getQuery(); | ||
String newTargetUrl = request.getContextPath() + "/api" + path; | ||
if (query != null) { | ||
newTargetUrl += "?" + query; | ||
} | ||
|
||
getRedirectStrategy().sendRedirect(request, response, newTargetUrl); | ||
} catch (URISyntaxException e) { | ||
super.onAuthenticationSuccess(request, response, authentication); | ||
} | ||
} | ||
} |
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