Java Spring5OAuth2-如何在我的资源服务器中提供检查令牌URL?

Java Spring5OAuth2-如何在我的资源服务器中提供检查令牌URL?,java,spring,spring-security,oauth-2.0,spring-security-oauth2,Java,Spring,Spring Security,Oauth 2.0,Spring Security Oauth2,我需要一些帮助 我使用Spring-security-oauth2中的@EnableAuthorizationServer为授权类型“客户端凭据”设置了一个授权服务器。能够创建,检查代币和一切好用这个 /oauth/令牌 /oauth/checkToken 跟随 我有一个单独的项目,需要保护REST API。我不能使用@EnableResourceServer,因为该项目使用Spring 5.2.8,而Spring-security-oauth2 2.5在通过Weblogic部署时会导致冲突(因

我需要一些帮助

我使用Spring-security-oauth2中的
@EnableAuthorizationServer
为授权类型“客户端凭据”设置了一个
授权服务器。能够创建,检查代币和一切好用这个

/oauth/令牌
/oauth/checkToken

跟随

我有一个单独的项目,需要保护REST API。我不能使用
@EnableResourceServer
,因为该项目使用Spring 5.2.8,而Spring-security-oauth2 2.5在通过Weblogic部署时会导致冲突(因为它使用4.x Spring JAR,排除它们会导致更多问题),所以

现在在这个示例中,我如何只提供一个CheckTokenURL。此示例需要JWT json类型的文件,但我没有。我只想保持简单,并使用我创建的授权服务器的checktoken url,类似于
@EnableResourceServer
的工作方式。(除了没有
@EnableResourceServer


我在哪里提供?非常感谢您的即时帮助。

以ResourceServer为例,这对我很有用:

@EnableWebSecurity
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Value("${security.oauth2.resource.tokenInfoUri}") String tokenInfoUri;
    @Value("${security.oauth2.client.clientId}") String clientId;
    @Value("${security.oauth2.client.clientSecret}") String clientSecret;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        http
                .authorizeRequests((authorizeRequests) ->
                        authorizeRequests
                                .antMatchers(HttpMethod.GET, "/message/**").hasAuthority("SCOPE_message:read")
                                .antMatchers(HttpMethod.POST, "/message/**").hasAuthority("SCOPE_message:write")
                                .anyRequest().authenticated()
                )
                .oauth2ResourceServer(OAuth2ResourceServerConfigurer::opaqueToken);
        // @formatter:on
    }

    @Bean
    OpaqueTokenIntrospector opaqueTokenIntrospector() {
        return new NimbusOpaqueTokenIntrospector(tokenInfoUri,clientId,clientSecret);
    }
}
我使用了以下spring安全依赖项:

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-jose</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>oauth2-oidc-sdk</artifactId>
            <version>8.22</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-oauth2-resource-server</artifactId>
            <version>5.3.4.RELEASE</version>
        </dependency>

org.springframework.security
spring安全配置
5.3.4.1发布
org.springframework.security
spring-security-oauth2-jose
5.3.4.1发布
com.usds
oauth2 oidc sdk
8.22
运行时
org.springframework.security
spring-security-oauth2-resource-server
5.3.4.1发布

将您的checkToken Uri、client和clientSecret放入您的application.properties中。

我最终使用了Spring提供的JWT示例,该示例获取JWT公钥,以便在资源服务器上进行验证。 遵循Spring源代码示例项目中提供的身份验证和资源服务器


在我们迁移到更好的IDM解决方案之前,目前为止效果良好

谢谢@Jan Seidel,但我不希望在我的资源服务器中提供客户机Id和密码,已经在呼叫我的客户机将使用他们的客户机Id和密码呼叫我的授权服务器(/oauth/token)并且只使用承载令牌调用我的RESTAPI,这样我就不能访问他们的客户机ID和secret,我想要一种在资源服务器中使用承载令牌作为param调用/oauth/checktoken的方法。我们如何做到这一点?正如我所理解的OAuth2协议,您的资源服务器是您的创作本身的客户机。它将有自己的客户端id和密码。用于请求令牌和检查令牌的客户端ID不必匹配。这就是我配置OAuth2环境的方式。谢谢@jan_tm,但问题是在我的情况下,客户端首先使用/oauth/token post调用调用授权服务器,然后获取令牌,并在标头中仅提供承载令牌来调用我的rest服务。我的资源服务器所要做的就是调用授权服务器并验证该承载令牌。这与他们提供的JWT令牌示例非常配合,但我不想要JWT令牌。