File tree 3 files changed +28
-9
lines changed
login/src/main/java/livelessons
resource-server/src/main/java/livelessons
3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 20
20
import org .springframework .boot .autoconfigure .SpringBootApplication ;
21
21
import org .springframework .context .annotation .Bean ;
22
22
import org .springframework .security .oauth2 .client .OAuth2AuthorizedClientService ;
23
+ import org .springframework .security .oauth2 .client .registration .ClientRegistrationRepository ;
23
24
import org .springframework .security .oauth2 .client .web .AuthenticatedPrincipalOAuth2AuthorizedClientRepository ;
24
25
import org .springframework .security .oauth2 .client .web .OAuth2AuthorizedClientRepository ;
26
+ import org .springframework .security .oauth2 .client .web .reactive .function .client .ServletOAuth2AuthorizedClientExchangeFilterFunction ;
25
27
import org .springframework .web .reactive .function .client .WebClient ;
26
28
27
- import static org .springframework .security .oauth2 .client .web .reactive .function .client .OAuth2ExchangeFilterFunctions .oauth2ServletConfig ;
28
-
29
29
@ SpringBootApplication
30
30
public class LoginApplication {
31
31
@@ -34,9 +34,16 @@ public static void main(String[] args) {
34
34
}
35
35
36
36
@ Bean
37
- WebClient webClient (OAuth2AuthorizedClientRepository authorizedClientRepository ) {
38
- return WebClient .builder ().apply (oauth2ServletConfig (authorizedClientRepository ))
37
+ WebClient webClient (ClientRegistrationRepository clientRegistrationRepository ,
38
+ OAuth2AuthorizedClientRepository authorizedClientRepository ) {
39
+ // @formatter:off
40
+ ServletOAuth2AuthorizedClientExchangeFilterFunction oauth2Client =
41
+ new ServletOAuth2AuthorizedClientExchangeFilterFunction (clientRegistrationRepository ,
42
+ authorizedClientRepository );
43
+ return WebClient .builder ()
44
+ .apply (oauth2Client .oauth2Configuration ())
39
45
.build ();
46
+ // @formatter:on
40
47
}
41
48
42
49
@ Bean
Original file line number Diff line number Diff line change @@ -9,8 +9,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
9
9
10
10
@ Override
11
11
protected void configure (HttpSecurity http ) throws Exception {
12
- http .oauth2Login ().and ().authorizeRequests ().anyRequest ().authenticated ().and ()
13
- .oauth2 ().client ().authorizationCodeGrant ();
12
+ // @formatter:off
13
+ http
14
+ .oauth2Login ()
15
+ .and ()
16
+ .authorizeRequests ()
17
+ .anyRequest ().authenticated ()
18
+ .and ()
19
+ .oauth2Client ()
20
+ .authorizationCodeGrant ();
21
+ // @formatter:on
14
22
}
15
23
16
24
}
Original file line number Diff line number Diff line change @@ -13,12 +13,16 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
13
13
14
14
@ Override
15
15
protected void configure (HttpSecurity http ) throws Exception {
16
+ // @formatter:off
16
17
http
17
- .oauth2 ()
18
- .resourceServer ()
19
- .jwt (). jwkSetUri (this .jwkSetUril )
18
+ .oauth2ResourceServer ()
19
+ .jwt ()
20
+ .jwkSetUri (this .jwkSetUril )
20
21
.and ()
22
+ .and ()
21
23
.authorizeRequests ()
22
24
.
anyRequest ().
access (
"principal?.claims['email'] == '[email protected] '" );
25
+ // @formatter:on
23
26
}
27
+
24
28
}
You can’t perform that action at this time.
0 commit comments