HttpSecurity的anonymous

https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/builders/HttpSecurity.html

在HttpSecurity中,可以通过设置anonymous方法来允许特定接口的匿名访问。

httpSecurity.antMatcher("api/random/**").anonymous();

匿名用户默认会被给到一个特别的AnonymousAuthenticationToken和ROLE_ANONYMOUS角色。由是当一个用户在登录后访问这些被anonymous修饰的接口,由于其非匿名角色,就可能得到403错误。😂

于是应当使用permitAll来修饰这些接口,以允许任何角色访问。

上一篇
下一篇