feat(#12405): The LDAP default password is a fixed value 'nacos' and cannot be customized. (#12406)

This commit is contained in:
blake.qiu 2024-07-24 14:50:49 +08:00 committed by GitHub
parent fbfa39d06d
commit 96a93189c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 9 deletions

View File

@ -94,11 +94,10 @@ public class LdapAuthenticationProvider implements AuthenticationProvider {
try {
userDetails = userDetailsService.loadUserByUsername(AuthConstants.LDAP_PREFIX + username);
} catch (UsernameNotFoundException exception) {
String nacosPassword = PasswordEncoderUtil.encode(AuthConstants.LDAP_DEFAULT_PASSWORD);
userDetailsService.createUser(AuthConstants.LDAP_PREFIX + username, nacosPassword);
userDetailsService.createUser(AuthConstants.LDAP_PREFIX + username, AuthConstants.LDAP_DEFAULT_ENCODED_PASSWORD);
User user = new User();
user.setUsername(AuthConstants.LDAP_PREFIX + username);
user.setPassword(nacosPassword);
user.setPassword(AuthConstants.LDAP_DEFAULT_ENCODED_PASSWORD);
userDetails = new NacosUserDetails(user);
}
return new UsernamePasswordAuthenticationToken(userDetails, password, userDetails.getAuthorities());

View File

@ -73,11 +73,8 @@ public class AuthConstants {
* LDAP Ignore partial result exception.
*/
public static final String NACOS_CORE_AUTH_IGNORE_PARTIAL_RESULT_EXCEPTION = "nacos.core.auth.ldap.ignore.partial.result.exception";
@Deprecated
public static final String LDAP_DEFAULT_PASSWORD = "nacos";
public static final String LDAP_DEFAULT_ENCODED_PASSWORD = PasswordEncoderUtil.encode(LDAP_DEFAULT_PASSWORD);
public static final String LDAP_DEFAULT_ENCODED_PASSWORD = PasswordEncoderUtil.encode(System.getProperty("ldap.default.password", "nacos"));
public static final String LDAP_PREFIX = "LDAP_";
}

View File

@ -81,7 +81,7 @@ class LdapAuthenticationProviderTest {
private List<RoleInfo> roleInfos = new ArrayList<>();
private String defaultPassWord = "nacos";
private String defaultPassWord = System.getProperty("ldap.default.password", "nacos");
@BeforeEach
void setUp() throws NoSuchMethodException {