Fix Random Password not generated when Email Config is present (#11701)

This commit is contained in:
Mohit Yadav 2023-05-22 11:29:33 +05:30 committed by GitHub
parent ddbc7fe14d
commit 3050363faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,7 +80,7 @@ public final class UserUtil {
if (providerType.equals(SSOAuthMechanism.SsoServiceType.BASIC.value())) {
if (originalUser.getAuthenticationMechanism() == null
|| originalUser.getAuthenticationMechanism().equals(new AuthenticationMechanism())) {
updateUserWithHashedPwd(updatedUser, ADMIN_USER_NAME);
updateUserWithHashedPwd(updatedUser, getPassword());
EmailUtil.sendInviteMailToAdmin(updatedUser, ADMIN_USER_NAME);
}
} else {
@ -96,7 +96,7 @@ public final class UserUtil {
updatedUser = user(username, domain, username).withIsAdmin(isAdmin).withIsEmailVerified(true);
// Update Auth Mechanism if not present, and send mail to the user
if (providerType.equals(SSOAuthMechanism.SsoServiceType.BASIC.value())) {
updateUserWithHashedPwd(updatedUser, ADMIN_USER_NAME);
updateUserWithHashedPwd(updatedUser, getPassword());
EmailUtil.sendInviteMailToAdmin(updatedUser, ADMIN_USER_NAME);
}
}
@ -105,6 +105,16 @@ public final class UserUtil {
addOrUpdateUser(updatedUser);
}
private static String getPassword() {
try {
EmailUtil.getInstance().testConnection();
return PasswordUtil.generateRandomPassword();
} catch (Exception ex) {
LOG.info("Password set to Default.");
}
return ADMIN_USER_NAME;
}
public static void updateUserWithHashedPwd(User user, String pwd) {
String hashedPwd = BCrypt.withDefaults().hashToString(12, pwd.toCharArray());
user.setAuthenticationMechanism(