Skip to content

Commit b130e72

Browse files
committed
Polish gh-18153
Issue gh-18144
1 parent e6db56a commit b130e72

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

docs/modules/ROOT/pages/servlet/oauth2/authorization-server/configuration-model.adoc

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,6 @@ public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
9595

9696
The main intent of `OAuth2AuthorizationServerConfiguration` is to provide a convenient method to apply the minimal default configuration for an OAuth2 authorization server. However, in most cases, customizing the configuration will be required.
9797

98-
The following example shows how you can wire an authorization server with nothing more than an `HttpSecurity` builder while still re-using Spring Boot’s defaults for users and static resources:
99-
100-
[source,java]
101-
----
102-
@Bean
103-
SecurityFilterChain springSecurity(HttpSecurity http) {
104-
http
105-
.authorizeHttpRequests(requests -> requests
106-
.anyRequest().authenticated()
107-
)
108-
.authorizationServer(auth -> auth
109-
.oidc(Customizer.withDefaults())
110-
)
111-
.formLogin(Customizer.withDefaults());
112-
return http.build();
113-
}
114-
----
115-
11698
[[oauth2AuthorizationServer-customizing-the-configuration]]
11799
== Customizing the configuration
118100

docs/modules/ROOT/pages/servlet/oauth2/authorization-server/getting-started.adoc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,34 @@ spring:
108108
require-authorization-consent: true
109109
----
110110

111+
If you want to customize the default `HttpSecurity` configuration, you may override Spring Boot's auto-configuration with the following example:
112+
113+
[[oauth2AuthorizationServer-minimal-sample-gettingstarted]]
114+
.SecurityConfig.java
115+
[source,java]
116+
----
117+
@Configuration
118+
@EnableWebSecurity
119+
public class SecurityConfig {
120+
121+
@Bean
122+
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
123+
http
124+
.authorizeHttpRequests((authorize) ->
125+
authorize
126+
.anyRequest().authenticated()
127+
)
128+
.formLogin(Customizer.withDefaults())
129+
.oauth2AuthorizationServer((authorizationServer) ->
130+
authorizationServer
131+
.oidc(Customizer.withDefaults()) // Enable OpenID Connect 1.0
132+
);
133+
return http.build();
134+
}
135+
136+
}
137+
----
138+
111139
TIP: Beyond the Getting Started experience, most users will want to customize the default configuration. The xref:servlet/oauth2/authorization-server/getting-started.adoc#oauth2AuthorizationServer-defining-required-components[next section] demonstrates providing all of the necessary beans yourself.
112140

113141
[[oauth2AuthorizationServer-defining-required-components]]

0 commit comments

Comments
 (0)