首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Spring Security:如何获取初始目标URL

在使用 Spring Security 时,获取初始目标 URL 可以通过以下方法实现:

  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制
@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);
    }
}
  1. 在 Spring Security 配置类中,可以通过重写 AuthenticationSuccessHandler 接口来实现获取初始目标 URL。
代码语言:java
复制

@Component

public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

代码语言:txt
复制
@Override
代码语言:txt
复制
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
代码语言:txt
复制
                                    Authentication authentication) throws IOException, ServletException {
代码语言:txt
复制
    SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request,
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

领券