use of org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository in project spring-security by spring-projects.
the class ServerHttpSecurityTests method shouldConfigureRequestCacheForOAuth2LoginAuthenticationEntryPointAndSuccessHandler.
@Test
public void shouldConfigureRequestCacheForOAuth2LoginAuthenticationEntryPointAndSuccessHandler() {
ServerRequestCache requestCache = spy(new WebSessionServerRequestCache());
ReactiveClientRegistrationRepository clientRegistrationRepository = mock(ReactiveClientRegistrationRepository.class);
SecurityWebFilterChain securityFilterChain = this.http.oauth2Login().clientRegistrationRepository(clientRegistrationRepository).and().authorizeExchange().anyExchange().authenticated().and().requestCache((c) -> c.requestCache(requestCache)).build();
WebTestClient client = WebTestClientBuilder.bindToWebFilters(securityFilterChain).build();
client.get().uri("/test").exchange();
ArgumentCaptor<ServerWebExchange> captor = ArgumentCaptor.forClass(ServerWebExchange.class);
verify(requestCache).saveRequest(captor.capture());
assertThat(captor.getValue().getRequest().getURI().toString()).isEqualTo("/test");
OAuth2LoginAuthenticationWebFilter authenticationWebFilter = getWebFilter(securityFilterChain, OAuth2LoginAuthenticationWebFilter.class).get();
Object handler = ReflectionTestUtils.getField(authenticationWebFilter, "authenticationSuccessHandler");
assertThat(ReflectionTestUtils.getField(handler, "requestCache")).isSameAs(requestCache);
}
use of org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository in project spring-security by spring-projects.
the class OAuth2ClientSpecTests method registeredOAuth2AuthorizedClientWhenAuthenticatedThenRedirects.
@Test
@WithMockUser
public void registeredOAuth2AuthorizedClientWhenAuthenticatedThenRedirects() {
this.spring.register(Config.class, AuthorizedClientController.class).autowire();
ReactiveClientRegistrationRepository repository = this.spring.getContext().getBean(ReactiveClientRegistrationRepository.class);
ServerOAuth2AuthorizedClientRepository authorizedClientRepository = this.spring.getContext().getBean(ServerOAuth2AuthorizedClientRepository.class);
given(repository.findByRegistrationId(any())).willReturn(Mono.just(TestClientRegistrations.clientRegistration().build()));
given(authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(Mono.empty());
// @formatter:off
this.client.get().uri("/").exchange().expectStatus().is3xxRedirection();
// @formatter:on
}
use of org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository in project spring-security by spring-projects.
the class OAuth2ClientSpecTests method registeredOAuth2AuthorizedClientWhenAnonymousThenRedirects.
@Test
public void registeredOAuth2AuthorizedClientWhenAnonymousThenRedirects() {
this.spring.register(Config.class, AuthorizedClientController.class).autowire();
ReactiveClientRegistrationRepository repository = this.spring.getContext().getBean(ReactiveClientRegistrationRepository.class);
ServerOAuth2AuthorizedClientRepository authorizedClientRepository = this.spring.getContext().getBean(ServerOAuth2AuthorizedClientRepository.class);
given(repository.findByRegistrationId(any())).willReturn(Mono.just(TestClientRegistrations.clientRegistration().build()));
given(authorizedClientRepository.loadAuthorizedClient(any(), any(), any())).willReturn(Mono.empty());
// @formatter:off
this.client.get().uri("/").exchange().expectStatus().is3xxRedirection();
// @formatter:on
}
use of org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository in project spring-security by spring-projects.
the class OidcClientInitiatedServerLogoutSuccessHandlerTests method logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults.
@Test
public void logoutWhenClientRegistrationHasNoEndSessionEndpointThenDefaults() {
ClientRegistration registration = TestClientRegistrations.clientRegistration().build();
ReactiveClientRegistrationRepository repository = new InMemoryReactiveClientRegistrationRepository(registration);
OidcClientInitiatedServerLogoutSuccessHandler handler = new OidcClientInitiatedServerLogoutSuccessHandler(repository);
OAuth2AuthenticationToken token = new OAuth2AuthenticationToken(TestOidcUsers.create(), AuthorityUtils.NO_AUTHORITIES, registration.getRegistrationId());
given(this.exchange.getPrincipal()).willReturn(Mono.just(token));
WebFilterExchange f = new WebFilterExchange(this.exchange, this.chain);
handler.setLogoutSuccessUrl(URI.create("https://default"));
handler.onLogoutSuccess(f, token).block();
assertThat(redirectedUrl(this.exchange)).isEqualTo("https://default");
}
use of org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository in project spring-boot by spring-projects.
the class ReactiveOAuth2ClientAutoConfigurationTests method clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent.
@Test
void clientRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent() {
this.contextRunner.withPropertyValues(REGISTRATION_PREFIX + ".foo.client-id=abcd", REGISTRATION_PREFIX + ".foo.client-secret=secret", REGISTRATION_PREFIX + ".foo.provider=github").run((context) -> {
ReactiveClientRegistrationRepository repository = context.getBean(ReactiveClientRegistrationRepository.class);
ClientRegistration registration = repository.findByRegistrationId("foo").block(Duration.ofSeconds(30));
assertThat(registration).isNotNull();
assertThat(registration.getClientSecret()).isEqualTo("secret");
});
}
Aggregations