|
1 | 1 | /* |
2 | | - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.authentication; |
18 | 18 |
|
19 | | -import java.io.IOException; |
20 | | - |
21 | | -import jakarta.servlet.ServletException; |
22 | 19 | import jakarta.servlet.http.HttpServletRequest; |
23 | 20 | import jakarta.servlet.http.HttpServletResponse; |
24 | 21 | import org.apache.commons.logging.Log; |
25 | 22 | import org.apache.commons.logging.LogFactory; |
26 | 23 |
|
27 | | -import org.springframework.security.core.Authentication; |
28 | 24 | import org.springframework.security.web.access.ExceptionTranslationFilter; |
29 | 25 | import org.springframework.security.web.savedrequest.HttpSessionRequestCache; |
30 | 26 | import org.springframework.security.web.savedrequest.RequestCache; |
@@ -70,24 +66,21 @@ public class SavedRequestAwareAuthenticationSuccessHandler extends SimpleUrlAuth |
70 | 66 | private RequestCache requestCache = new HttpSessionRequestCache(); |
71 | 67 |
|
72 | 68 | @Override |
73 | | - public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, |
74 | | - Authentication authentication) throws ServletException, IOException { |
| 69 | + protected String determineTargetUrl(HttpServletRequest request, HttpServletResponse response) { |
75 | 70 | SavedRequest savedRequest = this.requestCache.getRequest(request, response); |
76 | 71 | if (savedRequest == null) { |
77 | | - super.onAuthenticationSuccess(request, response, authentication); |
78 | | - return; |
| 72 | + return super.determineTargetUrl(request, response); |
79 | 73 | } |
| 74 | + |
80 | 75 | String targetUrlParameter = getTargetUrlParameter(); |
81 | 76 | if (isAlwaysUseDefaultTargetUrl() |
82 | 77 | || (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) { |
83 | 78 | this.requestCache.removeRequest(request, response); |
84 | | - super.onAuthenticationSuccess(request, response, authentication); |
85 | | - return; |
| 79 | + return super.determineTargetUrl(request, response); |
86 | 80 | } |
87 | | - clearAuthenticationAttributes(request); |
| 81 | + |
88 | 82 | // Use the DefaultSavedRequest URL |
89 | | - String targetUrl = savedRequest.getRedirectUrl(); |
90 | | - getRedirectStrategy().sendRedirect(request, response, targetUrl); |
| 83 | + return savedRequest.getRedirectUrl(); |
91 | 84 | } |
92 | 85 |
|
93 | 86 | public void setRequestCache(RequestCache requestCache) { |
|
0 commit comments