Spring Security OAuth2在30秒后无法通过发行者验证

时间:2018-10-29 16:43:41

标签: java spring-security oauth-2.0 azure-active-directory spring-webflux

在反应式spring webflux服务中,我将端点配置为受OAuth2资源服务器保护。当我第一次启动服务器时,它会正确验证Bearer令牌,但是大约30秒后,完全相同的请求开始失败,并显示以下错误:

error="invalid_token"
error_description="This iss claim is not equal to the configured issuer"
error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"

我已验证令牌有效,并且iss声明与spring.security.oauth2.resourceserver.jwt.issuer-uri中配置的声明相同。如果配置不正确,那么我将没有有效的请求。

经过仔细检查,我发现错误是由于URL声明与预期URL的iss比较引起的,因为前30秒InetAddress.getAddress()匹配,但是不匹配。这使用的是Azure AD提供程序终结点https://sts.windows.net/{{tenantId}}/,并且我已验证URL 字符串是否匹配,只是内部地址不匹配。可能是什么原因造成的?在最初的30秒后,如何与有效的发行者一起验证令牌?谢谢。

作为参考,这是我的SecurityWebFilterChain

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
    return http
            .csrf().disable()
            .authorizeExchange().anyExchange().authenticated()
            .and().oauth2ResourceServer().jwt().and()
            .and().build();
}

包括的分级实现:

org.springframework.boot:spring-boot-starter-security:2.1.0.RC1
org.springframework.boot:spring-boot-starter-webflux:2.1.0.RC1
org.springframework.security:spring-security-oauth2-resource-server:5.1.1.RELEASE
org.springframework.security:spring-security-oauth2-jose:5.1.1.RELEASE

1 个答案:

答案 0 :(得分:3)

类似这样的内容在spring-security中作为问题#6073输入,并在c70b65c中得到解决。目前计划在5.1.2.RELEASE或5.2.0.M1中解决该问题。

提交的解决方案将URL更改为字符串,这使得除删除阻塞的DNS查找调用之外,相等性检查更加可靠。