JHipster - Spring。 Oauth2 资源服务器配置。创建资源服务器

JHipster - Spring. Oauth2 resource server configuration. Create resource server

当在 pom.xml 中使用简单的 spring 引导配置和正常的 spring 父级时,我在配置 oauth2 资源服务器时没有问题。

然而,对于 JHipster 依赖管理,我无法配置它。 我试图通过添加

来做到这一点
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
    <version>[spring version]</version>
</dependency>

或者通过使用一些旧配置和其他依赖项,如下所示:https://docs.spring.io/spring-security-oauth2-boot/docs/2.2.x-SNAPSHOT/reference/html/boot-features-security-oauth2-resource-server.html 通常它可以工作,但是使用 JHipster 我得到 @EnableResourceServer 注释,但我在 IntelliJ spring.security.oauth2.resourceserver 属性 中没有。所以我无法配置验证令牌的服务器,而且我在 HttpSecurity http (WebSecurityConfigurerAdapter) 中没有 .oauth2ResourceServer() 方法。我不明白为什么会这样。我怎样才能得到这些属性?或者也许我可以通过自定义配置以某种方式覆盖它?

你好,我是这样做的, 1-找到你项目的.yo-rc.json文件 2-打开文件并找到标签“authenticationType”,它应该显示为“authenticationType”:“jwt”,将其更改为“authenticationType”:“oauth2” 3 - 运行 再次在您的项目中使用 jhipster 命令。

这里有一个视频:https://www.youtube.com/watch?v=YIRjgd_3sMQ

JHipster默认配置为资源服务器,所以你不需要添加任何额外的配置。

来自SecurityConfiguration.java

.oauth2ResourceServer()
    .jwt()
    .jwtAuthenticationConverter(authenticationConverter())
    .and()
.and()
    .oauth2Client();