Skip to content

Commit

Permalink
Create Admin Password for Admin User (#15191)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3e3c067)
  • Loading branch information
mohityadav766 committed Feb 27, 2024
1 parent cb7237e commit c697ac4
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void createOrUpdateUser(
if (authProvider.equals(AuthProvider.BASIC)) {
if (originalUser.getAuthenticationMechanism() == null
|| originalUser.getAuthenticationMechanism().equals(new AuthenticationMechanism())) {
String randomPwd = getPassword();
String randomPwd = getPassword(username);
updateUserWithHashedPwd(updatedUser, randomPwd);
EmailUtil.sendInviteMailToAdmin(updatedUser, randomPwd);
}
Expand All @@ -105,7 +105,7 @@ private static void createOrUpdateUser(
updatedUser = user(username, domain, username).withIsAdmin(isAdmin).withIsEmailVerified(true);
// Update Auth Mechanism if not present, and send mail to the user
if (authProvider.equals(AuthProvider.BASIC)) {
String randomPwd = getPassword();
String randomPwd = getPassword(username);
updateUserWithHashedPwd(updatedUser, randomPwd);
EmailUtil.sendInviteMailToAdmin(updatedUser, randomPwd);
}
Expand All @@ -117,9 +117,10 @@ private static void createOrUpdateUser(
}
}

private static String getPassword() {
private static String getPassword(String username) {
try {
if (Boolean.FALSE.equals(EmailUtil.getSmtpSettings().getEnableSmtpServer())) {
if (Boolean.TRUE.equals(EmailUtil.getSmtpSettings().getEnableSmtpServer())
&& !ADMIN_USER_NAME.equals(username)) {
EmailUtil.testConnection();
return PasswordUtil.generateRandomPassword();
}
Expand Down

0 comments on commit c697ac4

Please sign in to comment.