V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
exqlnet
V2EX  ›  Java

Spring Security BadCredentialsException 为什么最终没有被抛出?

  •  
  •   exqlnet · Jul 13, 2019 · 6625 views
    This topic created in 2489 days ago, the information mentioned may be changed or developed.

    我在自定义的 AuthenticationProvider 中抛出了 BadCredentialsException,它最终并没有抛出并返回 401HTTP 状态码,反而成功通过认证链( Authentication )抵达权限检验链( Authorization ),结果返回 403 状态码。请问是什么情况?具体的内容和代码可以看我在 stackoverflow 上的提问

    https://stackoverflow.com/questions/57002484/why-badcredentialsexception-can-not-be-thrown-or-handled-in-my-customized-authen?noredirect=1#

    感激不尽

    1 replies    2019-07-14 08:52:45 +08:00
    maowu
        1
    maowu  
       Jul 14, 2019   ❤️ 1
    1. Filter 抛出的异常 ControllerAdvice 不会处理,因为请求还没到达 Controller
    2. 你的问题在 TokenAuthenticationProvider 设个断点,跟着异常处理流程 debug 一下就知道了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5727 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:41 · PVG 16:41 · LAX 01:41 · JFK 04:41
    ♥ Do have faith in what you're doing.