mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-27 06:12:27 +00:00
Remove Unneeded OAuth2AuthorizedClientRepository
Issue gh-8603
This commit is contained in:
parent
900f551890
commit
8d84bc58f6
@ -21,11 +21,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.server.WebSessionServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
|
|
||||||
@ -46,14 +42,6 @@ public class OAuth2LoginApplicationTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ReactiveClientRegistrationRepository clientRegistrationRepository;
|
ReactiveClientRegistrationRepository clientRegistrationRepository;
|
||||||
|
|
||||||
@TestConfiguration
|
|
||||||
static class AuthorizedClient {
|
|
||||||
@Bean
|
|
||||||
ServerOAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new WebSessionServerOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestWhenMockOidcLoginThenIndex() {
|
public void requestWhenMockOidcLoginThenIndex() {
|
||||||
this.clientRegistrationRepository.findByRegistrationId("github")
|
this.clientRegistrationRepository.findByRegistrationId("github")
|
||||||
|
@ -28,7 +28,6 @@ import org.springframework.core.ReactiveAdapterRegistry;
|
|||||||
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.reactive.result.method.annotation.OAuth2AuthorizedClientArgumentResolver;
|
import org.springframework.security.oauth2.client.web.reactive.result.method.annotation.OAuth2AuthorizedClientArgumentResolver;
|
||||||
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
||||||
import org.springframework.security.oauth2.client.web.server.WebSessionServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.web.reactive.result.method.annotation.AuthenticationPrincipalArgumentResolver;
|
import org.springframework.security.web.reactive.result.method.annotation.AuthenticationPrincipalArgumentResolver;
|
||||||
import org.springframework.security.web.server.context.SecurityContextServerWebExchangeWebFilter;
|
import org.springframework.security.web.server.context.SecurityContextServerWebExchangeWebFilter;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@ -55,13 +54,13 @@ public class OAuth2LoginControllerTests {
|
|||||||
@Mock
|
@Mock
|
||||||
ReactiveClientRegistrationRepository clientRegistrationRepository;
|
ReactiveClientRegistrationRepository clientRegistrationRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
ServerOAuth2AuthorizedClientRepository authorizedClientRepository;
|
||||||
|
|
||||||
WebTestClient rest;
|
WebTestClient rest;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
ServerOAuth2AuthorizedClientRepository authorizedClientRepository =
|
|
||||||
new WebSessionServerOAuth2AuthorizedClientRepository();
|
|
||||||
|
|
||||||
this.rest = WebTestClient
|
this.rest = WebTestClient
|
||||||
.bindToController(this.controller)
|
.bindToController(this.controller)
|
||||||
.apply(springSecurity())
|
.apply(springSecurity())
|
||||||
@ -69,7 +68,7 @@ public class OAuth2LoginControllerTests {
|
|||||||
.argumentResolvers(c -> {
|
.argumentResolvers(c -> {
|
||||||
c.addCustomResolver(new AuthenticationPrincipalArgumentResolver(new ReactiveAdapterRegistry()));
|
c.addCustomResolver(new AuthenticationPrincipalArgumentResolver(new ReactiveAdapterRegistry()));
|
||||||
c.addCustomResolver(new OAuth2AuthorizedClientArgumentResolver
|
c.addCustomResolver(new OAuth2AuthorizedClientArgumentResolver
|
||||||
(this.clientRegistrationRepository, authorizedClientRepository));
|
(this.clientRegistrationRepository, this.authorizedClientRepository));
|
||||||
})
|
})
|
||||||
.viewResolvers(c -> c.viewResolver(this.viewResolver))
|
.viewResolvers(c -> c.viewResolver(this.viewResolver))
|
||||||
.build();
|
.build();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -41,7 +41,6 @@ import org.junit.runner.RunWith;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
@ -53,9 +52,7 @@ import org.springframework.security.oauth2.client.registration.ClientRegistratio
|
|||||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
|
import org.springframework.security.oauth2.client.userinfo.OAuth2UserRequest;
|
||||||
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
|
import org.springframework.security.oauth2.client.userinfo.OAuth2UserService;
|
||||||
import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
|
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter;
|
import org.springframework.security.oauth2.client.web.OAuth2LoginAuthenticationFilter;
|
||||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||||
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
||||||
@ -381,10 +378,5 @@ public class OAuth2LoginApplicationTests {
|
|||||||
when(userService.loadUser(any())).thenReturn(user);
|
when(userService.loadUser(any())).thenReturn(user);
|
||||||
return userService;
|
return userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
OAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new HttpSessionOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -23,13 +23,9 @@ import org.junit.runner.RunWith;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.context.TestConfiguration;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
import org.springframework.security.oauth2.client.registration.ClientRegistration;
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
@ -53,14 +49,6 @@ public class OAuth2LoginControllerTests {
|
|||||||
@MockBean
|
@MockBean
|
||||||
ClientRegistrationRepository clientRegistrationRepository;
|
ClientRegistrationRepository clientRegistrationRepository;
|
||||||
|
|
||||||
@TestConfiguration
|
|
||||||
static class AuthorizedClient {
|
|
||||||
@Bean
|
|
||||||
public OAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new HttpSessionOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void rootWhenAuthenticatedReturnsUserAndClient() throws Exception {
|
public void rootWhenAuthenticatedReturnsUserAndClient() throws Exception {
|
||||||
this.mvc.perform(get("/").with(oauth2Login()))
|
this.mvc.perform(get("/").with(oauth2Login()))
|
||||||
|
@ -32,8 +32,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.server.WebSessionServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
@ -102,10 +100,5 @@ public class OAuth2WebClientControllerTests {
|
|||||||
WebClient web() {
|
WebClient web() {
|
||||||
return WebClient.create(web.url("/").toString());
|
return WebClient.create(web.url("/").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
ServerOAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new WebSessionServerOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.server.ServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.server.WebSessionServerOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
@ -102,10 +100,5 @@ public class RegisteredOAuth2AuthorizedClientControllerTests {
|
|||||||
WebClient web() {
|
WebClient web() {
|
||||||
return WebClient.create(web.url("/").toString());
|
return WebClient.create(web.url("/").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
ServerOAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new WebSessionServerOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
@ -100,10 +98,5 @@ public class OAuth2WebClientControllerTests {
|
|||||||
WebClient web() {
|
WebClient web() {
|
||||||
return WebClient.create(web.url("/").toString());
|
return WebClient.create(web.url("/").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
OAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new HttpSessionOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,6 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
|
||||||
import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
@ -100,10 +98,5 @@ public class RegisteredOAuth2AuthorizedClientControllerTests {
|
|||||||
WebClient web() {
|
WebClient web() {
|
||||||
return WebClient.create(web.url("/").toString());
|
return WebClient.create(web.url("/").toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
|
||||||
OAuth2AuthorizedClientRepository authorizedClientRepository() {
|
|
||||||
return new HttpSessionOAuth2AuthorizedClientRepository();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user