Trying out Spring Cloud Gateway 2.4.0-M4 with TokenRelayGatewayFilterFactory, which will not be autoconfigured correctly due to

GatewayAutoConfiguration.TokenRelayConfiguration:
      Did not match:
         - @ConditionalOnBean (types: org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; SearchStrategy: all) did not find any beans of type org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository (OnBeanCondition)

Traced this back to autoconfiguration, where the default config actually creates a bean of the specialized type InMemoryReactiveClientRegistrationRepository, rather than ReactiveClientRegistrationRepository.

Workaround for now is to configure the bean manually via

@Component
public class ReactiveClientRegistrationRepositoryConfig {

    @Bean
    **ReactiveClientRegistrationRepository** clientRegistrationRepository(@Autowired OAuth2ClientProperties properties) {
        List<ClientRegistration> registrations = new ArrayList<>(
                OAuth2ClientPropertiesRegistrationAdapter.getClientRegistrations(properties).values());
        return new InMemoryReactiveClientRegistrationRepository(registrations);
    }
}

This PR should hopefully fix this, although I have no way of testing this really.

Comment From: pivotal-issuemaster

@dxmann73 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@dxmann73 Thank you for signing the Contributor License Agreement!

Comment From: wilkinsona

Thanks for the proposal. Unfortunately, I don't think this will fix the problem that you have observed. InMemoryReactiveClientRegistrationRepository implements ReactiveClientRegistrationRepository. This means that the auto-configured bean as currently defined can be injected anywhere that a ReactiveClientRegistrationRepository is needed. Generally speaking, the more type information that's provided in a @Bean method's signature the better, and the method declaring that it returns the most-specific type possible is recommended.

A InMemoryReactiveClientRegistrationRepository bean will also be able to satisfy the condition on GatewayAutoConfiguration.TokenRelayConfiguration, but only if it has been defined at the time when that condition is evaluated. I suspect it's this timing that's causing the problem you're seeing and that there's an auto-configuration ordering problem here. Looking at the Spring Cloud Gateway code, I can't see anything in the auto-configuration ordering on GatewayAutoConfiguration that would ensure that it runs after ReactiveOAuth2ClientAutoConfiguration. In short, this looks like a Spring Cloud Gateway bug to me.

Comment From: dxmann73

Thanks, I wasn't aware of that, although I think I should have guessed. :-)

Will try to come up with a PR for Spring Cloud Gateway :-)