Polish "Register OAuth2AuthorizedClientRepository bean"
Closes gh-13870
This commit is contained in:
@@ -50,7 +50,8 @@ class OAuth2WebSecurityConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
public OAuth2AuthorizedClientRepository authorizedClientRepository(
|
||||
OAuth2AuthorizedClientService authorizedClientService) {
|
||||
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
|
||||
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(
|
||||
authorizedClientService);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.servlet.Filter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
@@ -94,16 +93,12 @@ public class OAuth2WebSecurityConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationRegistersAuthorizedRepositoryServiceBean() {
|
||||
this.contextRunner.withUserConfiguration(ClientRepositoryConfiguration.class,
|
||||
OAuth2WebSecurityConfiguration.class).run((context) -> {
|
||||
OAuth2AuthorizedClientRepository bean = context
|
||||
.getBean(OAuth2AuthorizedClientRepository.class);
|
||||
OAuth2AuthorizedClientRepository authorizedClientService = (OAuth2AuthorizedClientRepository) ReflectionTestUtils
|
||||
.getField(getAuthCodeFilters(context).get(0),
|
||||
"authorizedClientRepository");
|
||||
assertThat(authorizedClientService).isEqualTo(bean);
|
||||
});
|
||||
public void configurationRegistersAuthorizedClientRepositoryBean() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(ClientRepositoryConfiguration.class,
|
||||
OAuth2WebSecurityConfiguration.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(OAuth2AuthorizedClientRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,16 +125,12 @@ public class OAuth2WebSecurityConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void authorizedClientRepositoryBeanIsConditionalOnMissingBean() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(OAuth2AuthorizedClientServiceConfiguration.class,
|
||||
OAuth2WebSecurityConfiguration.class)
|
||||
.run((context) -> {
|
||||
OAuth2AuthorizedClientRepository bean = context
|
||||
.getBean(OAuth2AuthorizedClientRepository.class);
|
||||
OAuth2AuthorizedClientRepository authorizedClientService = (OAuth2AuthorizedClientRepository) ReflectionTestUtils
|
||||
.getField(getAuthCodeFilters(context).get(0),
|
||||
"authorizedClientRepository");
|
||||
assertThat(authorizedClientService).isEqualTo(bean);
|
||||
this.contextRunner.withUserConfiguration(
|
||||
OAuth2AuthorizedClientRepositoryConfiguration.class,
|
||||
OAuth2WebSecurityConfiguration.class).run((context) -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(OAuth2AuthorizedClientRepository.class);
|
||||
assertThat(context).hasBean("testAuthorizedClientRepository");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -241,11 +232,17 @@ public class OAuth2WebSecurityConfigurationTests {
|
||||
clientRegistrationRepository);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(ClientRepositoryConfiguration.class)
|
||||
static class OAuth2AuthorizedClientRepositoryConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public OAuth2AuthorizedClientRepository testAuthorizedClientRepository(
|
||||
OAuth2AuthorizedClientService authorizedClientService) {
|
||||
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(authorizedClientService);
|
||||
return new AuthenticatedPrincipalOAuth2AuthorizedClientRepository(
|
||||
authorizedClientService);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user