在使用 Spring Security 时,获取初始目标 URL 可以通过以下方法实现:
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);
String redirectUrl = savedRequest.getRedirectUrl();
// 获取初始目标 URL
System.out.println("初始目标 URL: " + redirectUrl);
}
}
AuthenticationSuccessHandler
接口来实现获取初始目标 URL。
@Component
public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request,
领取专属 10元无门槛券
手把手带您无忧上云