|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
33 | 33 | import org.springframework.http.HttpHeaders;
|
34 | 34 | import org.springframework.security.authentication.ReactiveAuthenticationManager;
|
35 | 35 | import org.springframework.security.authentication.TestingAuthenticationToken;
|
| 36 | +import org.springframework.security.authentication.UserDetailsRepositoryReactiveAuthenticationManager; |
36 | 37 | import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
37 | 38 | import org.springframework.security.config.oauth2.client.CommonOAuth2Provider;
|
38 | 39 | import org.springframework.security.config.test.SpringTestRule;
|
| 40 | +import org.springframework.security.config.users.ReactiveAuthenticationTestConfiguration; |
39 | 41 | import org.springframework.security.core.Authentication;
|
40 | 42 | import org.springframework.security.core.AuthenticationException;
|
41 | 43 | import org.springframework.security.core.authority.AuthorityUtils;
|
42 | 44 | import org.springframework.security.core.context.SecurityContext;
|
43 | 45 | import org.springframework.security.core.context.SecurityContextImpl;
|
| 46 | +import org.springframework.security.core.userdetails.ReactiveUserDetailsService; |
44 | 47 | import org.springframework.security.htmlunit.server.WebTestClientHtmlUnitDriverBuilder;
|
45 | 48 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
46 | 49 | import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
|
@@ -176,6 +179,24 @@ public void defaultLoginPageWithSingleClientRegistrationThenRedirect() {
|
176 | 179 | assertThat(driver.getCurrentUrl()).startsWith("https://github.com/login/oauth/authorize");
|
177 | 180 | }
|
178 | 181 |
|
| 182 | + @Test |
| 183 | + public void defaultLoginPageWithSingleClientRegistrationAndFormLoginThenLinks() { |
| 184 | + this.spring.register(OAuth2LoginWithSingleClientRegistrations.class, OAuth2LoginWithFormLogin.class).autowire(); |
| 185 | + // @formatter:off |
| 186 | + WebTestClient webTestClient = WebTestClientBuilder |
| 187 | + .bindToWebFilters(new GitHubWebFilter(), this.springSecurity) |
| 188 | + .build(); |
| 189 | + WebDriver driver = WebTestClientHtmlUnitDriverBuilder |
| 190 | + .webTestClientSetup(webTestClient) |
| 191 | + .build(); |
| 192 | + FormLoginTests.HomePage.to(driver, FormLoginTests.DefaultLoginPage.class) |
| 193 | + .assertAt() |
| 194 | + .assertLoginFormPresent() |
| 195 | + .oauth2Login() |
| 196 | + .assertClientRegistrationByName(OAuth2LoginTests.github.getClientName()); |
| 197 | + // @formatter:on |
| 198 | + } |
| 199 | + |
179 | 200 | // gh-8118
|
180 | 201 | @Test
|
181 | 202 | public void defaultLoginPageWithSingleClientRegistrationAndXhrRequestThenDoesNotRedirectForAuthorization() {
|
@@ -584,6 +605,30 @@ String home(@RegisteredOAuth2AuthorizedClient("github") OAuth2AuthorizedClient a
|
584 | 605 |
|
585 | 606 | }
|
586 | 607 |
|
| 608 | + @Configuration |
| 609 | + static class OAuth2LoginWithFormLogin { |
| 610 | + |
| 611 | + @Bean |
| 612 | + SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) { |
| 613 | + ReactiveUserDetailsService reactiveUserDetailsService = ReactiveAuthenticationTestConfiguration |
| 614 | + .userDetailsService(); |
| 615 | + ReactiveAuthenticationManager authenticationManager = new UserDetailsRepositoryReactiveAuthenticationManager( |
| 616 | + reactiveUserDetailsService); |
| 617 | + http.authenticationManager(authenticationManager); |
| 618 | + // @formatter:off |
| 619 | + http |
| 620 | + .authorizeExchange() |
| 621 | + .anyExchange().authenticated() |
| 622 | + .and() |
| 623 | + .oauth2Login() |
| 624 | + .and() |
| 625 | + .formLogin(); |
| 626 | + // @formatter:on |
| 627 | + return http.build(); |
| 628 | + } |
| 629 | + |
| 630 | + } |
| 631 | + |
587 | 632 | @Configuration
|
588 | 633 | static class OAuth2LoginMockAuthenticationManagerConfig {
|
589 | 634 |
|
|
0 commit comments