《Spring Security》第十八章 Anonymous Authentication - 匿名身份认证

第十八章 Anonymous Authentication - 匿名身份认证

Spring Security 3.0后,会自动提供匿名身份验证支持,并且可以使用匿名元素进行定制。

一、Configuration

AnonymousAuthenticationToken 实现了 Authentication,并且关联了 GrantedAuthority。通过 AnonymousAuthenticationProvider,连接到 ProviderManager 中。并最终由 AnonymousAuthenticationFilter 向 SecurityContextHolder 中添加一个匿名的Authentication。

二、AuthenticationTrustResolver

AuthenticationTrustResolver 接口提供了一个 isAnonymous(Authentication) 方法,用来校验 Authentication 是否是匿名身份。其实现为 AuthenticationTrustResolverImpl。

在 ExceptionTranslationFilter 访问接口,并抛出 AccessDeniedException 异常,且当前身份验证为匿名类型,则不会抛出 403(FORBIDDEN) 响应,而是由过滤器转向 AuthenticationEntryPoint。以便主体能够重新进行身份验证。

这个区别是必须的,否则的话,用户将永远无法使用form、basic、digest等其他正常身份验证机制来登录。

文章作者: koral
文章链接: http://luokaiii.github.io/2019/07/23/读书笔记/《SpringSecurity》/18.AnonymousAuth/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自