0

我有以下 Spring Security 配置:

  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: ${issuer-uri-of-identity}
      client:
        registration:
          some-app:
            client-id: ${qwerty.server.client.client-id}
            client-secret: ${qwerty.server.client.client-secret}
            scope: ${qwerty.server.client.some-app-scope}
            authorization-grant-type: client_credentials
            provider: qwerty

qwerty:
  server:
    max-clock-skew: 60
    url: ....
    scope: my-scope
    client:
      client-id: ...
      client-secret: ....
      some-app-scope: my-ticket-scope

并使用以下配置:

    private static final Authentication ANONYMOUS_AUTHENTICATION = new AnonymousAuthenticationToken(
            "anonymous", "anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
    ...
    @Bean("someAppRestTemplate")
    @Autowired
    public RestTemplate buildRestTemplateForSomeApp(RestTemplateBuilder builder) {
        return builder
                .messageConverters(converter)
                .additionalInterceptors(Arrays.asList(contentTypeInterceptor(), oauthInterceptor("some-app")))
                .build();
    }
   ...
   private ClientHttpRequestInterceptor oauthInterceptor(String id) {
        return (r, b, e) -> {
            OAuth2AuthorizedClient client = manager.authorize(
                    OAuth2AuthorizeRequest
                            .withClientRegistrationId(id)
                            .principal(ANONYMOUS_AUTHENTICATION)
                            .build()
            );
            Assert.notNull(client, "Can not access File Storage Service");
            r.getHeaders().setBearerAuth(client.getAccessToken().getTokenValue());
            return e.execute(r, b);
        };
    }

现在我需要进行模拟(https://datatracker.ietf.org/doc/html/rfc8693)。所以我需要假装成某个用户。由于某些应用程序应用程序中的“当前用户”逻辑,我需要它。

我怎样才能重新配置来实现它?

PS我试图谷歌它,但我没有找到任何相关的东西。

4

1 回答 1

0

RFC 8693 令牌交换于 2020 年 1 月发布,涵盖了此功能。Spring security 目前尚不支持此功能,但应该很快就会发布。

您可以在此处关注 Spring Security 中的未解决问题:

为客户端提供对 OAuth 2.0 Token Exchange 的支持

您可以代表 flow阅读更多关于一般流程的信息

于 2021-12-27T10:02:02.107 回答