1、Spring Security异常体系
Spirng Security中的异常共有两大类:AuthenticationException(认证异常)和AccessDeniedException(权限异常)
1.1、AuthenticationException(认证异常)
AuthenticationException:认证异常的父类,抽象类
BadCredentialsException:登录凭证(密码)异常
InsufficientAuthenticationException:登陆凭证不够充分而抛出的异常
SessionAuthenticationException:会话并发管理时抛出的异常,例如会话总数超出最大限制数
UsernameNotFoundException:用户名不存在异常
PreAuthenticatedCredentialsNotFoundException:身份预认证失败异常
ProviderNotFoundException:未配置AuthenticationProvider异常
AuthenticationServiceException:由于系统问题而无法处理认证请求异常
InternalAuthenticationServiceException:由于系统问题而无法处理认证请求异常,和AuthenticationServiceException不同之处在于如果外部系统出错,不会抛出该异常
AuthenticationCredentialsNotFoundException:SecuityContext 中不存在认证主体时抛出的异常
NonceExpiredException:HTTP摘要认证时随机数过期异常
RememberMeAuthenticationException:RememberMe认证异常
CookieTheftException :RememberMe认证时Cookie被盗窃异常
InvalidCookieException:RememberMe认证时无效的Cookie异常
AccountStatusException:账户状态异常
LockedException:账户被锁定异常
DisabledException:账户被禁用异常
CredentialsExpiredException:登录凭证(密码)过期异常
AccountExpiredException:账户过期异常
1.2、AccessDeniedException(权限异常)
AccessDeniedException :权限异常的父类
AuthorizationServiceException: 由于系统问题而无法处理权限时抛出异常
CsrfException:Csrf令牌异常
MissingCsrfTokenException:Csrf令牌缺失异常
InvalidCsrfTokenException:Csrf令牌无效异常
2、ExceptionTranslationFilter源码分析
在 Spring Security 的过滤器链中,ExceptionTranslationFilter 过滤器专门用来处理异常
该过滤器主要处理AuthenticationException(认证异常)和AccessDeniedException(权限异常),其他异常则会继续抛出,交给上一层容器(Spring)处理