1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 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.
37
37
import org .springframework .security .oauth2 .client .registration .ClientRegistration ;
38
38
import org .springframework .security .oauth2 .client .registration .InMemoryReactiveClientRegistrationRepository ;
39
39
import org .springframework .security .oauth2 .client .userinfo .ReactiveOAuth2UserService ;
40
+ import org .springframework .security .oauth2 .client .web .server .ServerOAuth2AuthorizationRequestResolver ;
40
41
import org .springframework .security .oauth2 .core .OAuth2AccessToken ;
41
42
import org .springframework .security .oauth2 .core .TestOAuth2AccessTokens ;
42
43
import org .springframework .security .oauth2 .core .endpoint .OAuth2AccessTokenResponse ;
59
60
import org .springframework .security .web .server .SecurityWebFilterChain ;
60
61
import org .springframework .security .web .server .WebFilterChainProxy ;
61
62
import org .springframework .security .web .server .authentication .ServerAuthenticationConverter ;
63
+ import org .springframework .security .web .server .util .matcher .ServerWebExchangeMatcher ;
62
64
import org .springframework .test .web .reactive .server .WebTestClient ;
63
65
import org .springframework .web .server .ServerWebExchange ;
64
66
import org .springframework .web .server .WebFilter ;
@@ -100,7 +102,7 @@ public class OAuth2LoginTests {
100
102
101
103
@ Test
102
104
public void defaultLoginPageWithMultipleClientRegistrationsThenLinks () {
103
- this .spring .register (OAuth2LoginWithMulitpleClientRegistrations .class ).autowire ();
105
+ this .spring .register (OAuth2LoginWithMultipleClientRegistrations .class ).autowire ();
104
106
105
107
WebTestClient webTestClient = WebTestClientBuilder
106
108
.bindToWebFilters (this .springSecurity )
@@ -120,7 +122,7 @@ public void defaultLoginPageWithMultipleClientRegistrationsThenLinks() {
120
122
}
121
123
122
124
@ EnableWebFluxSecurity
123
- static class OAuth2LoginWithMulitpleClientRegistrations {
125
+ static class OAuth2LoginWithMultipleClientRegistrations {
124
126
@ Bean
125
127
InMemoryReactiveClientRegistrationRepository clientRegistrationRepository () {
126
128
return new InMemoryReactiveClientRegistrationRepository (github , google );
@@ -165,6 +167,8 @@ public void oauth2LoginWhenCustomObjectsThenUsed() {
165
167
.getBean (OAuth2LoginMockAuthenticationManagerConfig .class );
166
168
ServerAuthenticationConverter converter = config .authenticationConverter ;
167
169
ReactiveAuthenticationManager manager = config .manager ;
170
+ ServerWebExchangeMatcher matcher = config .matcher ;
171
+ ServerOAuth2AuthorizationRequestResolver resolver = config .resolver ;
168
172
169
173
OAuth2AuthorizationExchange exchange = TestOAuth2AuthorizationExchanges .success ();
170
174
OAuth2User user = TestOAuth2Users .create ();
@@ -174,6 +178,8 @@ public void oauth2LoginWhenCustomObjectsThenUsed() {
174
178
175
179
when (converter .convert (any ())).thenReturn (Mono .just (new TestingAuthenticationToken ("a" , "b" , "c" )));
176
180
when (manager .authenticate (any ())).thenReturn (Mono .just (result ));
181
+ when (matcher .matches (any ())).thenReturn (ServerWebExchangeMatcher .MatchResult .match ());
182
+ when (resolver .resolve (any ())).thenReturn (Mono .empty ());
177
183
178
184
webTestClient .get ()
179
185
.uri ("/login/oauth2/code/github" )
@@ -182,6 +188,8 @@ public void oauth2LoginWhenCustomObjectsThenUsed() {
182
188
183
189
verify (converter ).convert (any ());
184
190
verify (manager ).authenticate (any ());
191
+ verify (matcher ).matches (any ());
192
+ verify (resolver ).resolve (any ());
185
193
}
186
194
187
195
@ Configuration
@@ -190,6 +198,10 @@ static class OAuth2LoginMockAuthenticationManagerConfig {
190
198
191
199
ServerAuthenticationConverter authenticationConverter = mock (ServerAuthenticationConverter .class );
192
200
201
+ ServerWebExchangeMatcher matcher = mock (ServerWebExchangeMatcher .class );
202
+
203
+ ServerOAuth2AuthorizationRequestResolver resolver = mock (ServerOAuth2AuthorizationRequestResolver .class );
204
+
193
205
@ Bean
194
206
public SecurityWebFilterChain springSecurityFilter (ServerHttpSecurity http ) {
195
207
http
@@ -198,14 +210,16 @@ public SecurityWebFilterChain springSecurityFilter(ServerHttpSecurity http) {
198
210
.and ()
199
211
.oauth2Login ()
200
212
.authenticationConverter (authenticationConverter )
201
- .authenticationManager (manager );
213
+ .authenticationManager (manager )
214
+ .authenticationMatcher (matcher )
215
+ .authorizationRequestResolver (resolver );
202
216
return http .build ();
203
217
}
204
218
}
205
219
206
220
@ Test
207
221
public void oauth2LoginWhenCustomJwtDecoderFactoryThenUsed () {
208
- this .spring .register (OAuth2LoginWithMulitpleClientRegistrations .class ,
222
+ this .spring .register (OAuth2LoginWithMultipleClientRegistrations .class ,
209
223
OAuth2LoginWithJwtDecoderFactoryBeanConfig .class ).autowire ();
210
224
211
225
WebTestClient webTestClient = WebTestClientBuilder
0 commit comments