Sim*_*imo 6 java authentication spring spring-security spring-boot
这两个类:
WebSecurityConfigurerAdapter
GlobalAuthenticationConfigurerAdapter
Run Code Online (Sandbox Code Playgroud)
似乎对我做同样的事情。它们都提供了不同的方法configure(...)来自定义 WebSecurity,例如配置UserDetailsService. 在互联网上找到的一些示例中,我看到两个类都被扩展了(就像这个,http : //ryanjbaxter.com/2015/01/06/securing-rest-apis-with-spring-boot/):
@Configuration
class WebSecurityConfiguration extends GlobalAuthenticationConfigurerAdapter {...}
Run Code Online (Sandbox Code Playgroud)
和
@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {...}
Run Code Online (Sandbox Code Playgroud)
但在某些示例中,只WebSecurityConfigurerAdapter需要(扩展)。
我不确定两者之间的区别?哪一个能做而另一个不能做?或者如果它们都需要,那么它们中的哪一个用于 Spring 安全的哪个方面?
我看到的唯一区别是,@EnableWebSecurity它通常在 extends 类上方注释WebSecurityConfigurerAdapter,而不是在 extends 类中GlobalAuthenticationConfigurerAdapter
==============实验==================
我尝试删除 extends 的类GlobalAuthenticationConfigurerAdapter,并将与 UserDetailsService 相关的代码携带到扩展的类中WebSecurityConfigurerAdapter(实际代码请参见上面的链接),它仍然有效。
| 归档时间: |
|
| 查看次数: |
2365 次 |
| 最近记录: |