Access Token 从 JdbcTokenStore 查询

Access Token's query from JdbcTokenStore

我是 Spring Boot 和 Oauth 的新手,我正在我的系统上实施 Oauth 安全性,我对 JdbcTokenStore 查询有疑问.

我在 JdbcTokenStore 代码中看到了 DEFAULT_ACCESS_TOKEN_SELECT_STATEMENT = "select token_id, token from oauth_access_token where token_id =?"

我尝试使用 client_id1 从 oauth/token 获取令牌并使用 client_id2 检查令牌,最后我收到了成功的响应,因为它只是过滤 token_id .

我期待像 "token not found" 或类似的错误。

这个查询应该有这个行为吗?

更新

我有一个 AuthorizationServer 和一个 ResourceServer 分开,在我的 AuthorizationServer 我是从数据库获取 ClientDetails,我有两个条目:

client_details_entries

在我的 Web 应用程序中,我使用第一个 ClientDetails 来获取有效令牌:

$ curl seiafiscalizacao:seiafiscalizacao123@localhost:8080/seia-auth-server/oauth/token -d grant_type=password -d username=username -d password=pwd

在 oauth_access_token 上,我得到了一个将 token_id 与 client_id 相关联的新条目:

access_token_entry

在我的 ResourceServer 上,我有一个具有这些配置的 RemoteTokenServices(第二个 ClientDetails):

@Bean
@Primary
public RemoteTokenServices tokenService() {

    RemoteTokenServices tokenService = new RemoteTokenServices();
    tokenService.setCheckTokenEndpointUrl("http://localhost:8080/seia-auth-server/oauth/check_token");
    tokenService.setClientId("seiafiscalizacao2");
    tokenService.setClientSecret("seiafiscalizacao123");
    return tokenService;
}

最后,当我尝试从我的 ResourceServer 获取任何资源时,即使使用不同的 client_id:

我也得到了成功响应

success_from_resourceserver_?

当我打开来自 org.springframework.security.oauth2.provider.token.storeJdbcTokenStore 代码时,我看到了 private static final String DEFAULT_ACCESS_TOKEN_SELECT_STATEMENT = "select token_id, token from oauth_access_token where token_id = ?";,我明白了为什么我成功了。

我没有收到任何错误或异常,但我想知道如何使用不同的 client_id 检查我的令牌并获得成功。

正如我之前所说,我是 Oauth 的新手,我不知道这是否符合预期。

为了访问 ResourceServer,我使用 Firefox 的 RESTClient

我的Spring引导版本是1.5.10.RELEASE

我的应用服务器是Wildfly 10.1

到目前为止,我的项目非常复杂,无法共享,但如果您需要,我可以在后面做一些新的。

OAuth2 规范没有对此进行定义,请参阅 RFC 6749:

10.3. Access Tokens

[...]

This specification does not provide any methods for the resource server to ensure that an access token presented to it by a given client was issued to that client by the authorization server.

因此,Spring Security OAuth2 不会检查它。

此外,RemoteTokenServices 是一项 Spring 安全 OAuth2 功能,根本不在 OAuth2 规范中,请参阅 OAuth 2 Developers Guide

An alternative is the RemoteTokenServices which is a Spring OAuth features (not part of the spec) allowing Resource Servers to decode tokens through an HTTP resource on the Authorization Server (/oauth/check_token).