File tree 4 files changed +16
-124
lines changed
docs/src/docs/asciidoc/guides
samples/demo-authorizationserver/src/main/java/sample
4 files changed +16
-124
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,6 @@ Select from the following use cases to see an example of each:
123
123
124
124
* I want to <<advanced-use-cases-capture-users>>
125
125
* I want to <<advanced-use-cases-map-claims>>
126
- * I want to <<advanced-use-cases-configurer>>
127
126
128
127
[[advanced-use-cases-capture-users]]
129
128
=== Capture Users in a Database
@@ -166,37 +165,3 @@ public OAuth2TokenCustomizer<JwtEncodingContext> idTokenCustomizer() {
166
165
return new FederatedIdentityIdTokenCustomizer();
167
166
}
168
167
----
169
-
170
- [[advanced-use-cases-configurer]]
171
- === Create My Own Configurer
172
-
173
- The following example `SecurityConfigurer` combines configuration for all of the above examples into a single reusable component:
174
-
175
- .`FederatedIdentityConfigurer`
176
- [source,java]
177
- ----
178
- include::{samples-dir}/demo-authorizationserver/src/main/java/sample/federation/FederatedIdentityConfigurer.java[tags=imports;class]
179
- ----
180
-
181
- The configurer can be applied using the Spring Security DSL as in the following example:
182
-
183
- .Apply Configurer
184
- [source,java]
185
- ----
186
- http.apply(new FederatedIdentityConfigurer());
187
- ----
188
-
189
- The configurer also has its own DSL to customize the defaults.
190
- Here's a full example:
191
-
192
- .Customize using Configurer
193
- [source,java]
194
- ----
195
- http.apply(new FederatedIdentityConfigurer())
196
- .oauth2UserHandler((oauth2User) -> {
197
- // TODO: Handle login of an OAuth2 user...
198
- })
199
- .oidcUserHandler((oidcUser) -> {
200
- // TODO: Handle login of an OIDC user...
201
- });
202
- ----
Original file line number Diff line number Diff line change 22
22
import com .nimbusds .jose .jwk .source .JWKSource ;
23
23
import com .nimbusds .jose .proc .SecurityContext ;
24
24
import sample .authentication .DeviceClientAuthenticationProvider ;
25
- import sample .jose .Jwks ;
26
- import sample .federation .FederatedIdentityConfigurer ;
27
25
import sample .federation .FederatedIdentityIdTokenCustomizer ;
26
+ import sample .jose .Jwks ;
28
27
import sample .web .authentication .DeviceClientAuthenticationConverter ;
29
28
30
29
import org .springframework .context .annotation .Bean ;
@@ -121,8 +120,7 @@ public SecurityFilterChain authorizationServerSecurityFilterChain(
121
120
exceptions .authenticationEntryPoint (new LoginUrlAuthenticationEntryPoint ("/login" ))
122
121
)
123
122
.oauth2ResourceServer (oauth2ResourceServer ->
124
- oauth2ResourceServer .jwt (Customizer .withDefaults ()))
125
- .apply (new FederatedIdentityConfigurer ());
123
+ oauth2ResourceServer .jwt (Customizer .withDefaults ()));
126
124
// @formatter:on
127
125
return http .build ();
128
126
}
Original file line number Diff line number Diff line change 15
15
*/
16
16
package sample .config ;
17
17
18
+ import sample .federation .FederatedIdentityAuthenticationSuccessHandler ;
19
+
18
20
import org .springframework .context .annotation .Bean ;
19
21
import org .springframework .context .annotation .Configuration ;
20
22
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
26
28
import org .springframework .security .core .userdetails .UserDetailsService ;
27
29
import org .springframework .security .provisioning .InMemoryUserDetailsManager ;
28
30
import org .springframework .security .web .SecurityFilterChain ;
31
+ import org .springframework .security .web .authentication .AuthenticationSuccessHandler ;
29
32
import org .springframework .security .web .session .HttpSessionEventPublisher ;
30
33
31
34
/**
@@ -47,13 +50,23 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
47
50
.anyRequest ().authenticated ()
48
51
)
49
52
.formLogin (formLogin ->
50
- formLogin .loginPage ("/login" )
53
+ formLogin
54
+ .loginPage ("/login" )
55
+ )
56
+ .oauth2Login (oauth2Login ->
57
+ oauth2Login
58
+ .loginPage ("/login" )
59
+ .successHandler (authenticationSuccessHandler ())
51
60
);
52
61
53
62
return http .build ();
54
63
}
55
64
// @formatter:on
56
65
66
+ private AuthenticationSuccessHandler authenticationSuccessHandler () {
67
+ return new FederatedIdentityAuthenticationSuccessHandler ();
68
+ }
69
+
57
70
// @formatter:off
58
71
@ Bean
59
72
public UserDetailsService users () {
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments