【问题标题】:What is the import path for @EnableAuthorizationServer annotation@EnableAuthorizationServer 注解的导入路径是什么
【发布时间】:2022-01-05 02:59:15
【问题描述】:

我正在尝试理解 Spring Authorization Server。

按照各种教程和原始文档,几乎是配置依赖项后的第一步 -

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.security:spring-security-oauth2-authorization-server:0.2.1'
//  other db/test stuff
}

——就是在主类中添加@EnableAuthorizationServer注解。

除了我的 IDE (NetBeans) 没有任何线索,从导入中,它指的是什么。

那么:@EnableAuthorizationServer 的导入路径应该是什么? (而且,从逻辑上讲,是否需要其他一些依赖项才能识别它?)

【问题讨论】:

标签: java spring spring-security oauth


【解决方案1】:

在新的 Spring Authorization Server 中,您不需要 @EnableAuthorizationServer。这个注解来自旧的spring-security-oauth 模块,它是is deprecated。

关键是SecurityFilterChain,应该有更高的优先级,像这样:

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
    OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
    return http.formLogin(Customizer.withDefaults()).build();
}

我建议你看看官方仓库中的the samples。

【讨论】:

  • 如果只有样本可以访问……(在 IDE 中)
  • 什么意思?您可以克隆存储库并对其进行测试。 Spring Security Samples 存储库中还有另一个示例:github.com/spring-projects/spring-security-samples/tree/main/…
  • 我可以下载。我无法测试它,因为基本上没有什么可运行的;我只能通过“文件”视图访问其内容;在 Projects 中,它显示了三个构建脚本和一个空的 Sub Projects 文件夹。通过文件访问,导入语句未正确解析,我认为是因为它没有被视为一个项目,所以不知道在哪里查找引用的文件。
  • 您应该运行main 方法。您应该克隆整个 repo 而不仅仅是示例以使其工作
  • 我做到了。我描述了我在 Netbeans 中打开整个项目(spring-authorization-server-main)得到的结果。没有可运行的东西。
猜你喜欢
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多