spring-security-oauth验证?

在配置security时,看到网上的demo在配置security的时候用了两个不同的注解,分别是EnableWebSecurity和EnableGlobalAuthentication这两个注解分别是什么含义,有什么区别?希望能给与有效的答复,如果是网上摘下来的(已经看蒙了)还请别误导我了,我是新手,还望指点。

阅读 2.7k
1 个回答

以下内容全部来自spring的官方文档 ,所有你完全不必担心我误导你,哈哈
https://docs.spring.io/spring...
https://spring.io/search?q=En...


EnableWebSecurity: By using @EnableWebSecurity you will automatically
have this added to your Spring MVC configuration.

EnableWebSecurity这个注解很好理解,就是把你的项目标记成一个spring Security 的项目,会自动帮你加入一些基本的配置。


The EnableGlobalAuthentication annotation signals that the annotated
class canbe used to configure a global instance of
AuthenticationManagerBuilder.

EnableGlobalAuthentication 这个注解说实话 我也没用过,但是我在spring security文档中搜了一下,也没搜到,然后我在我自己的项目中搜了一下,发现他在spring security的子包 spring security config下面。
所以他有可能和spring security配置相关,再看下他的代码呢

@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(value = { java.lang.annotation.ElementType.TYPE })
@Documented
@Import(AuthenticationConfiguration.class)
@Configuration
public @interface EnableGlobalAuthentication {
}

看到上面有个 @Configuration 和 @Import(AuthenticationConfiguration.class) ,这下放心了,一定是个用于配置类的注解,因为Configuration 本身就是修饰配置类的,然后又使用Import导入了AuthenticationConfiguration配置类
再看他类上面的注释,就是这段

The EnableGlobalAuthentication annotation signals that the annotated
class canbe used to configure a global instance of
AuthenticationManagerBuilder.

大概意思是说

使用EnableGlobalAuthentication 这个注解 注释一个类,可以用于配置一个AuthenticationManagerBuilder的全局实例,

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题