Skip to content

Commit e602fb0

Browse files
committed
inject PasswordEncoder into DaoAuthenticationProvider constructor
Closes gh-14691
1 parent 0078462 commit e602fb0

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.
@@ -65,11 +65,14 @@ public void configure(AuthenticationManagerBuilder auth) throws Exception {
6565
}
6666
PasswordEncoder passwordEncoder = getBeanOrNull(PasswordEncoder.class);
6767
UserDetailsPasswordService passwordManager = getBeanOrNull(UserDetailsPasswordService.class);
68-
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
69-
provider.setUserDetailsService(userDetailsService);
68+
DaoAuthenticationProvider provider;
7069
if (passwordEncoder != null) {
71-
provider.setPasswordEncoder(passwordEncoder);
70+
provider = new DaoAuthenticationProvider(passwordEncoder);
71+
}
72+
else {
73+
provider = new DaoAuthenticationProvider();
7274
}
75+
provider.setUserDetailsService(userDetailsService);
7376
if (passwordManager != null) {
7477
provider.setUserDetailsPasswordService(passwordManager);
7578
}

0 commit comments

Comments
 (0)