【发布时间】:2018-09-13 09:56:15
【问题描述】:
这两个类:
WebSecurityConfigurerAdapter
GlobalAuthenticationConfigurerAdapter
似乎对我做同样的事情。它们都提供了不同的方法configure(...) 来自定义WebSecurity,例如配置UserDetailsService。在网上找到的一些例子中,我看到这两个类都被扩展了(比如这个,http://ryanjbaxter.com/2015/01/06/securing-rest-apis-with-spring-boot/):
@Configuration
class WebSecurityConfiguration extends GlobalAuthenticationConfigurerAdapter {...}
和
@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {...}
但在某些示例中,只需要WebSecurityConfigurerAdapter(扩展)。
我不确定两者之间的区别?哪一个能做到另一个不能?或者如果它们都需要,那么它们中的哪一个用于 Spring 安全的哪个方面?
我看到的唯一区别是@EnableWebSecurity 通常被注释在扩展WebSecurityConfigurerAdapter 的类之上,而不是在扩展GlobalAuthenticationConfigurerAdapter 的类中
=============实验==================
我尝试删除扩展GlobalAuthenticationConfigurerAdapter的类,并将与UserDetailsService相关的代码携带到扩展WebSecurityConfigurerAdapter的类中(实际代码见上面的链接),它仍然有效。
【问题讨论】:
标签: java spring authentication spring-boot spring-security