码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Spring Security之ExceptionTranslationFilter


    ExceptionTranslationFilter过滤器位于倒数第4个,详细过滤器的次序参考

    spring security中Filter的次序_kgduu的博客-CSDN博客

    其会捕获其后三个过滤器的异常。

    ExceptionTranslationFilter的处理逻辑为

    1. private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
    2. throws IOException, ServletException {
    3. try {
    4. chain.doFilter(request, response);
    5. }
    6. catch (IOException ex) {
    7. throw ex;
    8. }
    9. catch (Exception ex) {
    10. // Try to extract a SpringSecurityException from the stacktrace
    11. Throwable[] causeChain = this.throwableAnalyzer.determineCauseChain(ex);
    12. RuntimeException securityException = (AuthenticationException) this.throwableAnalyzer
    13. .getFirstThrowableOfType(AuthenticationException.class, causeChain);
    14. if (securityException == null) {
    15. securityException = (AccessDeniedException) this.throwableAnalyzer
    16. .getFirstThrowableOfType(AccessDeniedException.class, causeChain);
    17. }
    18. if (securityException == null) {
    19. rethrow(ex);
    20. }
    21. if (response.isCommitted()) {
    22. throw new ServletException("Unable to handle the Spring Security Exception "
    23. + "because the response is already committed.", ex);
    24. }
    25. handleSpringSecurityException(request, response, chain, securityException);
    26. }
    27. }

     直接调用后序链中的过滤器。发起认证流程

    1. protected void sendStartAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain,
    2. AuthenticationException reason) throws ServletException, IOException {
    3. // SEC-112: Clear the SecurityContextHolder's Authentication, as the
    4. // existing Authentication is no longer considered valid
    5. SecurityContext context = this.securityContextHolderStrategy.createEmptyContext();
    6. this.securityContextHolderStrategy.setContext(context);
    7. this.requestCache.saveRequest(request, response);
    8. this.authenticationEntryPoint.commence(request, response, reason);
    9. }

    调用AuthenticationEntryPoint的commence。

  • 相关阅读:
    mybatis学习(15):mybatis连接mysql数据库
    双软企业认证与税收优惠政策讲解(比较齐全)
    206、SpringBoot 整合 RabbitMQ 的自动配置类 和 对应的属性处理类 的知识点
    cefsharp 93.1.140 如何在js中暴露c#类
    开源FFMpeg(四)——使用SDL进行音频播放下(使用篇)
    数据结构——栈的讲解(超详细)
    基于thinkphp校园二手交易网站#毕业设计
    Banana Pi BPI-SWE1000 中大型高度智能的控制板,智能回收箱,智能垃圾箱,智能售卖系统控制板
    389.找不同
    力扣刷题-链表-设计链表
  • 原文地址:https://blog.csdn.net/wuli2496/article/details/126212390
  • 最新文章
  • 【JVM】编译执行与解释执行的区别是什么?JVM 使用哪种方式?
    用 Hashids 优雅解决 C 端自增 ID 暴露问题
    V8引擎 精品漫游指南--Ignition篇(上) 指令 栈帧 槽位 调用约定 内存布局 基础内容
    LLVM Pass快速入门(四):代码插桩
    milkup:桌面端 markdown AI续写和即时渲染
    基于项目工程构建SBOM(软件物料清单)的研究
    鸿蒙应用开发UI基础第二节:鸿蒙应用程序框架核心解析与实操
    .NET 中如何快速实现 List 集合去重?
    扣子Coze实战:从0到1打造抖音+小红书热点监控智能体
    浅谈数据访问层
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号