首页
学习
活动
专区
工具
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,
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • Spring Security 初始化流程梳理

    前面我们对 Spring Security 源码的讲解都比较零散,今天松哥试着来和大家捋一遍 Spring Security初始化流程,顺便将前面的源码解析文章串起来。...在 Spring Boot 中,Spring Security初始化,我们就从自动化配置开始分析吧!...WebSecurityEnablerConfiguration:这个配置是 Spring Security 的核心配置,也将是我们分析的重点。...SecurityDataConfiguration:提供了 Spring Security 整合 Spring Data 的支持,由于国内使用 MyBatis 较多,所以这个配置发光发热的场景有限。...4.小结 这便是 Spring Security 的一个大致的初始化流程。大部分的源码在前面的文章中都讲过了,本文主要是是一个梳理,如果小伙伴们还没看前面的文章,建议看过了再来学习本文哦。

    1.4K30

    spring security运行时配置ignore url

    序 以前用shiro的比较多,不过spring boot倒是挺推崇自家的spring security的,有默认的starter,于是也就拿来用了。...security,这个需要了解一下spring security的运行机制: Spring Security 的底层是通过一系列的 Filter 来管理的,每个 Filter 都有其自身的功能,它们的顺序也是非常重要的...spring security会根据FilterChainProxy中的filter chain的顺序去挨个匹配当前请求的url,然后执行对应的filter逻辑,在前面的优先匹配。...思路 要在运行时增加免登陆url的话,就需要运行时去修改FilterChainProxy中的filterChains,不过源码里头返回了不可变的集合 4.1.4.RELEASE/spring-security-web...doc 初识 Spring Security Spring Security系列四 自定义决策管理器(动态权限码)

    3.9K10

    spring security filter获取请求的urlpattern

    序 本文主要讲一下如何spring security filter里头获取请求的HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE BEST_MATCHING_PATTERN_ATTRIBUTE...spring mvc支持在url配置变量,这个比较容易满足rest风格的api设计,但是也给鉴权、监控统计等带来一些麻烦,那就是原来光靠uri来进行判断已经不行了,必须改造使用url pattern来判断...BEST_MATCHING_PATTERN_ATTRIBUTE的设置是在spring mvc的dispatch servlet里头,但是spring security的filter执行顺序在mvc之前,...因而在spring security里头的filter无法获取BEST_MATCHING_PATTERN_ATTRIBUTE 那么在这种情况下,如何自己获取呢 RequestMappingHandlerMapping...doc Actuator metrics: Path vars not recognized e.g. if spring security check fails - number of metrics

    1.4K10

    Spring Security 实战干货:AuthenticationManager的初始化细节

    虽然在Spring Security 实战干货:图解认证管理器 AuthenticationManager一文中对AuthenticationManager的流程进行了分析,但是还是不够深入,以至于出现了问题...; } // 否则就去 Spring IoC 中获取其构建类 AuthenticationManagerBuilder authBuilder = this.applicationContext.getBean...AuthenticationManagerBuilder ❝第一个问题是AuthenticationManagerBuilder是如何注入Spring IoC的?...真相大白 到此为什么在认证的时候找不到原因终于找到了,原来我在使用 Spring Security 默认配置时(注意这个前提),向Spring IoC注入了多个UserDetailsService导致DaoAuthenticationProvider...总结 这一篇对于需要多种认证方式并存的Spring Security配置非常重要,如果你在配置中不注意,很容易引发No Provider ……的异常。所以有很有必要学习一下。

    2.1K31

    如何使用 Go 语言获取 URL

    在 Web 开发和网络爬虫等领域,经常需要获取和处理 URL(统一资源定位符)。Go 语言提供了丰富的标准库来处理 URL,使得获取和解析 URL 变得简单而高效。...本文将介绍如何使用 Go 语言获取 URL 的详细步骤,并提供一些实用的示例。图片一、URL 的基本概念在开始之前,我们先来了解 URL 的基本概念。...我们可以使用该包中的函数来获取 URL 中的各个部分,或者构建新的 URL。...然后,我们可以通过调用 Get 方法来获取指定参数的值。三、实际示例:使用 Go 获取网页内容现在,我们将结合实际示例来演示如何使用 Go 语言获取网页内容。...总结本文介绍了如何使用 Go 语言获取 URL。我们学习了如何解析和构建 URL,以及如何获取 URL 中的各个部分和查询参数。此外,我们还提供了一个实际示例,展示了如何使用 Go 语言获取网页内容。

    70430

    spring security实现动态配置url权限的两种方法

    缘起 标准的RABC, 权限需要支持动态配置,spring security默认是在代码里约定好权限,真实的业务场景通常需要可以支持动态配置角色访问权限,即在运行时去配置url对应的访问角色。...基于spring security如何实现这个需求呢?...最简单的方法就是自定义一个Filter去完成权限判断,但这脱离了spring security框架,如何基于spring security优雅的实现呢?...spring security 授权回顾 spring security 通过FilterChainProxy作为注册到web的filter,FilterChainProxy里面一次包含了内置的多个过滤器...,我们首先需要了解spring security内置的各种filter: Alias Filter Class Namespace Element or Attribute CHANNEL_FILTER

    2.4K00

    Spring Security 和 Shiro 该如何选择?

    要知道Shiro和Spring Security如何选择,首先要看看两者的区别和对比 Shiro Apache Shiro是一个强大且易用的Java安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密...Spring Security Spring Security 主要实现了Authentication(认证,解决who are you?...Spring Security在架构上将认证与授权分离,并提供了扩展点。它是一个轻量级的安全框架,它确保基于Spring的应用程序提供身份验证和授权支持。...特点 shiro能实现的,Spring Security 基本都能实现,依赖于Spring体系,但是好处是Spring全家桶的亲儿子,集成上更加契合,在使用上,比shiro略负责。...两者对比 Shiro比Spring Security更容易使用,也就是实现上简单一些,同时基本的授权认证Shiro也基本够用 Spring Security社区支持度更高,Spring社区的亲儿子,支持力度和更新维护上有优势

    69530

    Spring Security 和 Shiro 该如何选择?

    来源 | https://blog.csdn.net/weixin_38405253/article/details/115301113 要知道Shiro和Spring Security如何选择,首先要看看两者的区别和对比...Spring Security在架构上将认证与授权分离,并提供了扩展点。它是一个轻量级的安全框架,它确保基于Spring的应用程序提供身份验证和授权支持。...特点 shiro能实现的,Spring Security 基本都能实现,依赖于Spring体系,但是好处是Spring全家桶的亲儿子,集成上更加契合,在使用上,比shiro略负责。...两者对比 Shiro比Spring Security更容易使用,也就是实现上简单一些,同时基本的授权认证Shiro也基本够用 Spring Security社区支持度更高,Spring社区的亲儿子,支持力度和更新维护上有优势...Spring这一套,用Spring Security我觉得更合适一些,他们本身就是一套东西,顺畅,可能略微复杂一些,但是学会了就是自己的。

    46820

    Spring Security 和 Shiro 该如何选择?

    要知道Shiro和Spring Security如何选择,首先要看看两者的区别和对比 Shiro Apache Shiro是一个强大且易用的Java安全框架,能够非常清晰的处理认证、授权、管理会话以及密码加密...Spring Security Spring Security 主要实现了Authentication(认证,解决who are you?...Spring Security在架构上将认证与授权分离,并提供了扩展点。它是一个轻量级的安全框架,它确保基于Spring的应用程序提供身份验证和授权支持。...特点 shiro能实现的,Spring Security 基本都能实现,依赖于Spring体系,但是好处是Spring全家桶的亲儿子,集成上更加契合,在使用上,比shiro略负责。...两者对比 Shiro比Spring Security更容易使用,也就是实现上简单一些,同时基本的授权认证Shiro也基本够用 Spring Security社区支持度更高,Spring社区的亲儿子,支持力度和更新维护上有优势

    79330

    Spring Security - 02 从 SecurityContextHolder 中获取用户信息

    @toc 环境 操作系统: Windows 10 x64 集成开发环境: Spring Tool Suite 4 Version: 4.12.1.RELEASE Build Id: 202110260750...浏览器(客户端): Google Chrome 版本 97.0.4692.71(正式版本) (64 位) 项目结构 参考:Spring Security - 01 新建项目 [在这里插入图片描述]...新建 HelloController 控制器类,我们可以通过 SecurityContextHolder 获取用户信息(第 17 ~ 19 行): package com.mk.controller;...import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContext...Security 会先要求我们登录,登录成功之后就可以看到服务器返回用户的信息: [在这里插入图片描述] 参考 Spring Security - 01 新建项目 Spring Security /

    2K20

    spring security oauth2.x迁移到spring security5.x 资源服务器启用url参数传递token

    现象 opaque token模式使用url参数access_token传递token访问资源服务器时报错401未授权 原因 spring security 5.x默认的bear token解析器没有启用从请求参数中获取...token 解决 在资源服务器安全配置中自行配置bearerTokenResolver,启用从请求参数中获取token protected void configure(HttpSecurity http...DefaultBearerTokenResolver(); } } return this.bearerTokenResolver; } 默认token解析器 org.springframework.security.oauth2...server.resource.web.DefaultBearerTokenResolver // 默认关闭表单参数(用于POST请求) private boolean allowFormEncodedBodyParameter = false; // 默认关闭url...isParameterTokenSupportedForRequest(request)) { return parameterToken; } return null; } // 判断是否允许从表单/url

    87820
    领券