File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
main/java/org/springframework/security/authentication/dao
test/java/org/springframework/security/authentication/dao Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,16 @@ public class DaoAuthenticationProvider extends AbstractUserDetailsAuthentication
61
61
private UserDetailsPasswordService userDetailsPasswordService ;
62
62
63
63
public DaoAuthenticationProvider () {
64
- setPasswordEncoder (PasswordEncoderFactories .createDelegatingPasswordEncoder ());
64
+ this (PasswordEncoderFactories .createDelegatingPasswordEncoder ());
65
+ }
66
+
67
+ /**
68
+ * Creates a new instance using the provided {@link PasswordEncoder}
69
+ * @param passwordEncoder the {@link PasswordEncoder} to use. Cannot be null.
70
+ * @since 6.0.3
71
+ */
72
+ public DaoAuthenticationProvider (PasswordEncoder passwordEncoder ) {
73
+ setPasswordEncoder (passwordEncoder );
65
74
}
66
75
67
76
@ Override
Original file line number Diff line number Diff line change @@ -441,6 +441,13 @@ public void testUserNotFoundDefaultEncoder() {
441
441
assertThatExceptionOfType (UsernameNotFoundException .class ).isThrownBy (() -> provider .authenticate (token ));
442
442
}
443
443
444
+ @ Test
445
+ public void constructWhenPasswordEncoderProvidedThenSets () {
446
+ DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider (
447
+ NoOpPasswordEncoder .getInstance ());
448
+ assertThat (daoAuthenticationProvider .getPasswordEncoder ()).isSameAs (NoOpPasswordEncoder .getInstance ());
449
+ }
450
+
444
451
/**
445
452
* This is an explicit test for SEC-2056. It is intentionally ignored since this test
446
453
* is not deterministic and {@link #testUserNotFoundEncodesPassword()} ensures that
You can’t perform that action at this time.
0 commit comments