File tree 4 files changed +33
-3
lines changed
main/java/org/springframework/security/config/annotation/web/reactive
test/java/org/springframework/security/config/annotation/web/reactive
main/java/org/springframework/security/authentication
test/java/org/springframework/security/authentication
4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 28
28
import org .springframework .security .authentication .ReactiveAuthenticationManager ;
29
29
import org .springframework .security .authentication .UserDetailsRepositoryReactiveAuthenticationManager ;
30
30
import org .springframework .security .config .web .server .ServerHttpSecurity ;
31
+ import org .springframework .security .core .userdetails .ReactiveUserDetailsPasswordService ;
31
32
import org .springframework .security .core .userdetails .ReactiveUserDetailsService ;
32
33
import org .springframework .security .crypto .password .PasswordEncoder ;
33
34
import org .springframework .security .web .reactive .result .method .annotation .AuthenticationPrincipalArgumentResolver ;
@@ -54,6 +55,9 @@ class ServerHttpSecurityConfiguration implements WebFluxConfigurer {
54
55
@ Autowired (required = false )
55
56
private PasswordEncoder passwordEncoder ;
56
57
58
+ @ Autowired (required = false )
59
+ private ReactiveUserDetailsPasswordService userDetailsPasswordService ;
60
+
57
61
@ Autowired (required = false )
58
62
private BeanFactory beanFactory ;
59
63
@@ -92,6 +96,7 @@ private ReactiveAuthenticationManager authenticationManager() {
92
96
if (this .passwordEncoder != null ) {
93
97
manager .setPasswordEncoder (this .passwordEncoder );
94
98
}
99
+ manager .setUserDetailsPasswordService (this .userDetailsPasswordService );
95
100
return manager ;
96
101
}
97
102
return null ;
Original file line number Diff line number Diff line change @@ -237,6 +237,34 @@ public static PasswordEncoder passwordEncoder() {
237
237
}
238
238
}
239
239
240
+ @ Test
241
+ public void passwordUpdateManagerUsed () {
242
+ this .spring .register (MapReactiveUserDetailsServiceConfig .class ).autowire ();
243
+ WebTestClient client = WebTestClientBuilder .bindToWebFilters (this .springSecurityFilterChain ).build ();
244
+
245
+ client
246
+ .get ()
247
+ .uri ("/" )
248
+ .headers (h -> h .setBasicAuth ("user" , "password" ))
249
+ .exchange ()
250
+ .expectStatus ().isOk ();
251
+
252
+ ReactiveUserDetailsService users = this .spring .getContext ().getBean (ReactiveUserDetailsService .class );
253
+ assertThat (users .findByUsername ("user" ).block ().getPassword ()).startsWith ("{bcrypt}" );
254
+ }
255
+
256
+ @ EnableWebFluxSecurity
257
+ static class MapReactiveUserDetailsServiceConfig {
258
+ @ Bean
259
+ public MapReactiveUserDetailsService userDetailsService () {
260
+ return new MapReactiveUserDetailsService (User .withUsername ("user" )
261
+ .password ("{noop}password" )
262
+ .roles ("USER" )
263
+ .build ()
264
+ );
265
+ }
266
+ }
267
+
240
268
@ Test
241
269
public void formLoginWorks () {
242
270
this .spring .register (Config .class ).autowire ();
Original file line number Diff line number Diff line change 20
20
21
21
import org .springframework .security .core .userdetails .ReactiveUserDetailsPasswordService ;
22
22
import org .springframework .security .core .userdetails .ReactiveUserDetailsService ;
23
- import org .springframework .security .core .userdetails .User ;
24
23
import org .springframework .security .crypto .factory .PasswordEncoderFactories ;
25
24
import org .springframework .security .crypto .password .PasswordEncoder ;
26
25
import org .springframework .util .Assert ;
Original file line number Diff line number Diff line change @@ -115,7 +115,6 @@ public void authenticateWhenPasswordServiceThenUpdated() {
115
115
public void authenticateWhenPasswordServiceAndBadCredentialsThenNotUpdated () {
116
116
when (this .userDetailsService .findByUsername (any ())).thenReturn (Mono .just (this .user ));
117
117
when (this .encoder .matches (any (), any ())).thenReturn (false );
118
- when (this .userDetailsPasswordService .updatePassword (any (), any ())).thenReturn (Mono .just (this .user ));
119
118
this .manager .setPasswordEncoder (this .encoder );
120
119
this .manager .setUserDetailsPasswordService (this .userDetailsPasswordService );
121
120
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken (
@@ -132,7 +131,6 @@ public void authenticateWhenPasswordServiceAndUpgradeFalseThenNotUpdated() {
132
131
when (this .userDetailsService .findByUsername (any ())).thenReturn (Mono .just (this .user ));
133
132
when (this .encoder .matches (any (), any ())).thenReturn (true );
134
133
when (this .encoder .upgradeEncoding (any ())).thenReturn (false );
135
- when (this .userDetailsPasswordService .updatePassword (any (), any ())).thenReturn (Mono .just (this .user ));
136
134
this .manager .setPasswordEncoder (this .encoder );
137
135
this .manager .setUserDetailsPasswordService (this .userDetailsPasswordService );
138
136
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken (
You can’t perform that action at this time.
0 commit comments