Skip to content

Commit f109388

Browse files
committed
Use lambda DSL in all samples in documentation
Issue: gh-7774
1 parent 0295b51 commit f109388

File tree

4 files changed

+225
-134
lines changed

4 files changed

+225
-134
lines changed

docs/manual/src/docs/asciidoc/_includes/reactive/oauth2/resource-server.adoc

Lines changed: 61 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,17 @@ More powerful than `jwkSetUri()` is `decoder()`, which will completely replace a
217217
@Bean
218218
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
219219
http
220-
.authorizeExchange()
221-
.anyExchange().authenticated()
222-
.and()
223-
.oauth2ResourceServer()
224-
.jwt()
225-
.decoder(myCustomDecoder());
220+
.authorizeExchange(exchanges ->
221+
exchanges
222+
.anyExchange().authenticated()
223+
)
224+
.oauth2ResourceServer(oauth2ResourceServer ->
225+
oauth2ResourceServer
226+
.jwt(jwt ->
227+
jwt
228+
.decoder(myCustomDecoder())
229+
)
230+
);
226231
return http.build();
227232
}
228233
----
@@ -425,12 +430,17 @@ To this end, the DSL exposes `jwtAuthenticationConverter()`:
425430
@Bean
426431
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
427432
http
428-
.authorizeExchange()
429-
.anyExchange().authenticated()
430-
.and()
431-
.oauth2ResourceServer()
432-
.jwt()
433-
.jwtAuthenticationConverter(grantedAuthoritiesExtractor());
433+
.authorizeExchange(exchanges ->
434+
exchanges
435+
.anyExchange().authenticated()
436+
)
437+
.oauth2ResourceServer(oauth2ResourceServer ->
438+
oauth2ResourceServer
439+
.jwt(jwt ->
440+
jwt
441+
.jwtAuthenticationConverter(grantedAuthoritiesExtractor())
442+
)
443+
);
434444
return http.build();
435445
}
436446
@@ -667,9 +677,10 @@ When use Opaque Token, this `SecurityWebFilterChain` looks like:
667677
@Bean
668678
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
669679
http
670-
.authorizeExchange()
671-
.anyExchange().authenticated()
672-
.and()
680+
.authorizeExchange(exchanges ->
681+
exchanges
682+
.anyExchange().authenticated()
683+
)
673684
.oauth2ResourceServer(ServerHttpSecurity.OAuth2ResourceServerSpec::opaqueToken)
674685
return http.build();
675686
}
@@ -686,13 +697,18 @@ public class MyCustomSecurityConfiguration {
686697
@Bean
687698
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
688699
http
689-
.authorizeExchange()
690-
.pathMatchers("/messages/**").hasAuthority("SCOPE_message:read")
691-
.anyExchange().authenticated()
692-
.and()
693-
.oauth2ResourceServer()
694-
.opaqueToken()
695-
.introspector(myIntrospector());
700+
.authorizeExchange(exchanges ->
701+
exchanges
702+
.pathMatchers("/messages/**").hasAuthority("SCOPE_message:read")
703+
.anyExchange().authenticated()
704+
)
705+
.oauth2ResourceServer(oauth2ResourceServer ->
706+
oauth2ResourceServer
707+
.opaqueToken(opaqueToken ->
708+
opaqueToken
709+
.introspector(myIntrospector())
710+
)
711+
);
696712
return http.build();
697713
}
698714
}
@@ -728,13 +744,18 @@ public class DirectlyConfiguredIntrospectionUri {
728744
@Bean
729745
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
730746
http
731-
.authorizeExchange()
732-
.anyExchange().authenticated()
733-
.and()
734-
.oauth2ResourceServer()
735-
.opaqueToken()
736-
.introspectionUri("https://idp.example.com/introspect")
737-
.introspectionClientCredentials("client", "secret");
747+
.authorizeExchange(exchanges ->
748+
exchanges
749+
.anyExchange().authenticated()
750+
)
751+
.oauth2ResourceServer(oauth2ResourceServer ->
752+
oauth2ResourceServer
753+
.opaqueToken(opaqueToken ->
754+
opaqueToken
755+
.introspectionUri("https://idp.example.com/introspect")
756+
.introspectionClientCredentials("client", "secret")
757+
)
758+
);
738759
return http.build();
739760
}
740761
}
@@ -754,12 +775,17 @@ public class DirectlyConfiguredIntrospector {
754775
@Bean
755776
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
756777
http
757-
.authorizeExchange()
758-
.anyExchange().authenticated()
759-
.and()
760-
.oauth2ResourceServer()
761-
.opaqueToken()
762-
.introspector(myCustomIntrospector());
778+
.authorizeExchange(exchanges ->
779+
exchanges
780+
.anyExchange().authenticated()
781+
)
782+
.oauth2ResourceServer(oauth2ResourceServer ->
783+
oauth2ResourceServer
784+
.opaqueToken(opaqueToken ->
785+
opaqueToken
786+
.introspector(myCustomIntrospector())
787+
)
788+
);
763789
return http.build();
764790
}
765791
}

docs/manual/src/docs/asciidoc/_includes/servlet/authorization/expression-based.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ or in Java configuration
140140
[source,java]
141141
----
142142
http
143-
.authorizeRequests()
144-
.antMatchers("/user/**").access("@webSecurity.check(authentication,request)")
145-
...
143+
.authorizeRequests(authorizeRequests ->
144+
authorizeRequests
145+
.antMatchers("/user/**").access("@webSecurity.check(authentication,request)")
146+
...
147+
)
146148
----
147149

148150
[[el-access-web-path-variables]]

0 commit comments

Comments
 (0)