Skip to content

Commit

Permalink
fix. URI 사용하여 path 추출
Browse files Browse the repository at this point in the history
  • Loading branch information
soyesenna committed Jun 5, 2024
1 parent afb03cf commit 208fade
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,36 @@


import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

@Component
public class CustomSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

private final RequestCache requestCache = new HttpSessionRequestCache();

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException, ServletException {
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().replace("http:/squadbnb.site", "");
targetUrl = "/api" + targetUrl;
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, targetUrl);
getRedirectStrategy().sendRedirect(request, response, newTargetUrl);
} catch (URISyntaxException e) {
super.onAuthenticationSuccess(request, response, authentication);
}
}
}

0 comments on commit 208fade

Please sign in to comment.