diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/UserUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/UserUtil.java index 5c61f9d1efe..e782e96205d 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/UserUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/UserUtil.java @@ -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(