Skip to content

Commit 75197ca

Browse files
kse-musicsjohnr
authored andcommitted
inject PasswordEncoder into DaoAuthenticationProvider constructor
Closes gh-14691
1 parent d6ae058 commit 75197ca

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

config/src/main/java/org/springframework/security/config/annotation/authentication/configuration/InitializeUserDetailsBeanManagerConfigurer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -67,11 +67,14 @@ public void configure(AuthenticationManagerBuilder auth) throws Exception {
6767
PasswordEncoder passwordEncoder = getBeanOrNull(PasswordEncoder.class);
6868
UserDetailsPasswordService passwordManager = getBeanOrNull(UserDetailsPasswordService.class);
6969
CompromisedPasswordChecker passwordChecker = getBeanOrNull(CompromisedPasswordChecker.class);
70-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
71-
provider.setUserDetailsService(userDetailsService);
70+
DaoAuthenticationProvider provider;
7271
if (passwordEncoder != null) {
73-
provider.setPasswordEncoder(passwordEncoder);
72+
provider = new DaoAuthenticationProvider(passwordEncoder);
73+
}
74+
else {
75+
provider = new DaoAuthenticationProvider();
7476
}
77+
provider.setUserDetailsService(userDetailsService);
7578
if (passwordManager != null) {
7679
provider.setUserDetailsPasswordService(passwordManager);
7780
}

0 commit comments

Comments
 (0)