ReactiveOAuth2ClientAutoConfiguration backs off for servlet env

Fixes gh-14463
pull/14471/head
Madhura Bhave 6 years ago
parent d4b11c8fa6
commit 1113c356dc

@ -25,6 +25,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.NoneNestedConditions;
import org.springframework.boot.autoconfigure.security.oauth2.client.ClientsConfiguredCondition;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientPropertiesRegistrationAdapter;
@ -52,6 +54,7 @@ import org.springframework.security.oauth2.client.web.server.ServerOAuth2Authori
@Configuration
@AutoConfigureBefore(ReactiveSecurityAutoConfiguration.class)
@EnableConfigurationProperties(OAuth2ClientProperties.class)
@Conditional(ReactiveOAuth2ClientAutoConfiguration.NonServletApplicationCondition.class)
@ConditionalOnClass({ Flux.class, EnableWebFluxSecurity.class, ClientRegistration.class })
public class ReactiveOAuth2ClientAutoConfiguration {
@ -89,4 +92,17 @@ public class ReactiveOAuth2ClientAutoConfiguration {
authorizedClientService);
}
static class NonServletApplicationCondition extends NoneNestedConditions {
NonServletApplicationCondition() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
static class ServletApplicationCondition {
}
}
}

@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@ -53,6 +54,15 @@ public class ReactiveOAuth2ClientAutoConfigurationTests {
private static final String REGISTRATION_PREFIX = "spring.security.oauth2.client.registration.login";
@Test
public void autoConfigurationShouldBackOffForServletEnvironments() {
WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations
.of(ReactiveOAuth2ClientAutoConfiguration.class));
contextRunner.run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveOAuth2ClientAutoConfiguration.class));
}
@Test
public void clientRegistrationRepositoryBeanShouldNotBeCreatedWhenPropertiesAbsent() {
this.contextRunner.run((context) -> assertThat(context)

Loading…
Cancel
Save