File tree 5 files changed +14
-9
lines changed
main/java/sample/userinfo
5 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 33
33
import org .springframework .http .MediaType ;
34
34
import org .springframework .security .config .Customizer ;
35
35
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
36
- import org .springframework .security .config .annotation .web .configurers . oauth2 . server . resource . OAuth2ResourceServerConfigurer ;
36
+ import org .springframework .security .config .annotation .web .configuration . EnableWebSecurity ;
37
37
import org .springframework .security .core .userdetails .User ;
38
38
import org .springframework .security .core .userdetails .UserDetails ;
39
39
import org .springframework .security .core .userdetails .UserDetailsService ;
54
54
import org .springframework .security .web .util .matcher .MediaTypeRequestMatcher ;
55
55
56
56
@ Configuration (proxyBeanMethods = false )
57
+ @ EnableWebSecurity
57
58
public class EnableUserInfoSecurityConfig {
58
59
59
60
@ Bean // <1>
@@ -64,7 +65,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
64
65
.oidc (Customizer .withDefaults ()); // Enable OpenID Connect 1.0
65
66
// @formatter:off
66
67
http
67
- .oauth2ResourceServer (OAuth2ResourceServerConfigurer :: jwt ) // <2>
68
+ .oauth2ResourceServer (( oauth2 ) -> oauth2 . jwt ( Customizer . withDefaults ()) ) // <2>
68
69
.exceptionHandling ((exceptions ) -> exceptions
69
70
.defaultAuthenticationEntryPointFor (
70
71
new LoginUrlAuthenticationEntryPoint ("/login" ),
Original file line number Diff line number Diff line change 34
34
import org .springframework .http .MediaType ;
35
35
import org .springframework .security .config .Customizer ;
36
36
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
37
- import org .springframework .security .config .annotation .web .configurers . oauth2 . server . resource . OAuth2ResourceServerConfigurer ;
37
+ import org .springframework .security .config .annotation .web .configuration . EnableWebSecurity ;
38
38
import org .springframework .security .core .userdetails .User ;
39
39
import org .springframework .security .core .userdetails .UserDetails ;
40
40
import org .springframework .security .core .userdetails .UserDetailsService ;
60
60
import org .springframework .security .web .util .matcher .RequestMatcher ;
61
61
62
62
@ Configuration (proxyBeanMethods = false )
63
+ @ EnableWebSecurity
63
64
public class JwtUserInfoMapperSecurityConfig {
64
65
65
66
@ Bean // <1>
@@ -90,7 +91,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
90
91
.anyRequest ().authenticated ()
91
92
)
92
93
.csrf (csrf -> csrf .ignoringRequestMatchers (endpointsMatcher ))
93
- .oauth2ResourceServer (OAuth2ResourceServerConfigurer ::jwt ) // <4>
94
+ .oauth2ResourceServer (resourceServer -> resourceServer
95
+ .jwt (Customizer .withDefaults ()) // <4>
96
+ )
94
97
.exceptionHandling ((exceptions ) -> exceptions
95
98
.defaultAuthenticationEntryPointFor (
96
99
new LoginUrlAuthenticationEntryPoint ("/login" ),
Original file line number Diff line number Diff line change 43
43
import org .springframework .security .config .Customizer ;
44
44
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
45
45
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
46
- import org .springframework .security .config .annotation .web .configurers .oauth2 .server .resource .OAuth2ResourceServerConfigurer ;
47
46
import org .springframework .security .oauth2 .core .endpoint .OAuth2ParameterNames ;
48
47
import org .springframework .security .oauth2 .core .oidc .endpoint .OidcParameterNames ;
49
48
import org .springframework .security .oauth2 .jwt .JwtDecoder ;
@@ -209,7 +208,9 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
209
208
new MediaTypeRequestMatcher (MediaType .TEXT_HTML )
210
209
)
211
210
)
212
- .oauth2ResourceServer (OAuth2ResourceServerConfigurer ::jwt );
211
+ .oauth2ResourceServer ((resourceServer ) -> resourceServer
212
+ .jwt (Customizer .withDefaults ())
213
+ );
213
214
// @formatter:on
214
215
return http .build ();
215
216
}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ The following listing shows how to enable the {spring-security-reference-base-ur
22
22
[[sample.userinfo]]
23
23
include::code:EnableUserInfoSecurityConfig[]
24
24
25
- TIP: Click on the "Expanded folded text" icon in the code sample above to display the full example.
25
+ TIP: Click on the "Expand folded text" icon in the code sample above to display the full example.
26
26
27
27
This configuration provides the following:
28
28
Original file line number Diff line number Diff line change @@ -557,7 +557,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
557
557
558
558
...
559
559
560
- http.oauth2ResourceServer(OAuth2ResourceServerConfigurer:: jwt);
560
+ http.oauth2ResourceServer(resourceServer -> resourceServer. jwt(Customizer.withDefaults()) );
561
561
562
562
return http.build();
563
563
}
@@ -650,7 +650,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity h
650
650
651
651
...
652
652
653
- http.oauth2ResourceServer(OAuth2ResourceServerConfigurer:: jwt);
653
+ http.oauth2ResourceServer(resourceServer -> resourceServer. jwt(Customizer.withDefaults()) );
654
654
655
655
return http.build();
656
656
}
You can’t perform that action at this time.
0 commit comments