|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
|
* Copyright 2002-2021 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -33,14 +33,17 @@ import org.springframework.context.annotation.Configuration;
@@ -33,14 +33,17 @@ import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
import org.springframework.security.authentication.ReactiveAuthenticationManager; |
|
|
|
|
import org.springframework.security.authentication.TestingAuthenticationToken; |
|
|
|
|
import org.springframework.security.authentication.UserDetailsRepositoryReactiveAuthenticationManager; |
|
|
|
|
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; |
|
|
|
|
import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; |
|
|
|
|
import org.springframework.security.config.test.SpringTestRule; |
|
|
|
|
import org.springframework.security.config.users.ReactiveAuthenticationTestConfiguration; |
|
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
|
import org.springframework.security.core.AuthenticationException; |
|
|
|
|
import org.springframework.security.core.authority.AuthorityUtils; |
|
|
|
|
import org.springframework.security.core.context.SecurityContext; |
|
|
|
|
import org.springframework.security.core.context.SecurityContextImpl; |
|
|
|
|
import org.springframework.security.core.userdetails.ReactiveUserDetailsService; |
|
|
|
|
import org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder; |
|
|
|
|
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; |
|
|
|
|
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; |
|
|
|
|
@ -176,6 +179,24 @@ public class OAuth2LoginTests {
@@ -176,6 +179,24 @@ public class OAuth2LoginTests {
|
|
|
|
|
assertThat(driver.getCurrentUrl()).startsWith("https://github.com/login/oauth/authorize"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void defaultLoginPageWithSingleClientRegistrationAndFormLoginThenLinks() { |
|
|
|
|
this.spring.register(OAuth2LoginWithSingleClientRegistrations.class, OAuth2LoginWithFormLogin.class).autowire(); |
|
|
|
|
// @formatter:off
|
|
|
|
|
WebTestClient webTestClient = WebTestClientBuilder |
|
|
|
|
.bindToWebFilters(new GitHubWebFilter(), this.springSecurity) |
|
|
|
|
.build(); |
|
|
|
|
WebDriver driver = WebTestClientHtmlUnitDriverBuilder |
|
|
|
|
.webTestClientSetup(webTestClient) |
|
|
|
|
.build(); |
|
|
|
|
FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
|
|
|
|
.assertAt() |
|
|
|
|
.assertLoginFormPresent() |
|
|
|
|
.oauth2Login() |
|
|
|
|
.assertClientRegistrationByName(OAuth2LoginTests.github.getClientName()); |
|
|
|
|
// @formatter:on
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// gh-8118
|
|
|
|
|
@Test |
|
|
|
|
public void defaultLoginPageWithSingleClientRegistrationAndXhrRequestThenDoesNotRedirectForAuthorization() { |
|
|
|
|
@ -584,6 +605,30 @@ public class OAuth2LoginTests {
@@ -584,6 +605,30 @@ public class OAuth2LoginTests {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class OAuth2LoginWithFormLogin { |
|
|
|
|
|
|
|
|
|
@Bean |
|
|
|
|
SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { |
|
|
|
|
ReactiveUserDetailsService reactiveUserDetailsService = ReactiveAuthenticationTestConfiguration |
|
|
|
|
.userDetailsService(); |
|
|
|
|
ReactiveAuthenticationManager authenticationManager = new UserDetailsRepositoryReactiveAuthenticationManager( |
|
|
|
|
reactiveUserDetailsService); |
|
|
|
|
http.authenticationManager(authenticationManager); |
|
|
|
|
// @formatter:off
|
|
|
|
|
http |
|
|
|
|
.authorizeExchange() |
|
|
|
|
.anyExchange().authenticated() |
|
|
|
|
.and() |
|
|
|
|
.oauth2Login() |
|
|
|
|
.and() |
|
|
|
|
.formLogin(); |
|
|
|
|
// @formatter:on
|
|
|
|
|
return http.build(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
static class OAuth2LoginMockAuthenticationManagerConfig { |
|
|
|
|
|
|
|
|
|
|