Spring Security学习<3>异常处理

  • 认证异常
    匿名用户在认证过程中 所涉及的异常行为有很多,常见的有:

    1. 账号/密码错误 (用户不存在)
    2. 账号状态异常 (被锁定、过期)
    3. 凭证无效/过期

    Spring security 统一以AuthenticationException抛出. 由AuthenticationEntryPoint处理

Spring security 官方文档
8.2.1. AuthenticationEntryPoint
AuthenticationEntryPoint会被调用, 在用户请求一个安全HTTP资源,但是他们还没有被认证。一个对应的 AuthenticationException或 AccessDeniedException会被抛出, 由一个安全监听器在下面的调用栈中,触发入口点的 commence方法。这执行展示对应的响应给用户, 这样认证可以开始。我们这里使用的是 LoginUrlAuthenticationEntryPoint,它会把请求 重定向到另一个不同的URL(一般是一个登陆页面)。实际的使用使用会依赖 你希望使用到的认证机制。

异常异常类描述
账号状态异常AccountStatusException
账号锁定状态LockedException
账号禁用状态DisabledException
账户过期状态AccountExpiredException
证书过期状态CredentialsExpiredException
凭证无效BadCredentialsException
用户不存在UsernameNotFoundException
认证信息不足InsufficientAuthenticationException
需要AccessTokenAccessTokenRequiredException
UnapprovedClientAuthenticationException
认证服务端异常AuthenticationServiceException
InternalAuthenticationServiceException
记住我错误RememberMeAuthenticationException
CookieTheftException
Cookie无效InvalidCookieException
其他SessionAuthenticationException
PreAuthenticatedCredentialsNotFoundException
Provider未查找到ProviderNotFoundException
AuthenticationCredentialsNotFoundException
Nonce已经过期/超时NonceExpiredException
  • 鉴权异常
    认证用户访问无权限资源时的异常为AccessDeniedException, 可以自定义AccessDeniedHandler进行处理
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值