mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-04 22:53:27 +00:00
Fix Email sent everytime a admin owns an Entity during startup (#10697)
* Fix Email sent everytime a admin owns an Entity during startup * fix
This commit is contained in:
parent
3d8e7e6d41
commit
acb0e71a3e
@ -179,8 +179,9 @@ public class UserResource extends EntityResource<User, UserRepository> {
|
||||
this.authenticationConfiguration = config.getAuthenticationConfiguration();
|
||||
SmtpSettings smtpSettings = config.getSmtpSettings();
|
||||
this.isEmailServiceEnabled = smtpSettings != null && smtpSettings.getEnableSmtpServer();
|
||||
this.dao.initializeUsers(config);
|
||||
// Keep this before initializeUsers, else getUpdater() will fail
|
||||
SubjectCache.initialize();
|
||||
this.dao.initializeUsers(config);
|
||||
}
|
||||
|
||||
public static class UserList extends ResultList<User> {
|
||||
|
@ -23,7 +23,6 @@ import static org.openmetadata.schema.auth.SSOAuthMechanism.SsoServiceType.OKTA;
|
||||
import static org.openmetadata.schema.entity.teams.AuthenticationMechanism.AuthType.JWT;
|
||||
import static org.openmetadata.schema.entity.teams.AuthenticationMechanism.AuthType.SSO;
|
||||
import static org.openmetadata.service.Entity.ADMIN_USER_NAME;
|
||||
import static org.openmetadata.service.resources.teams.UserResource.USER_PROTECTED_FIELDS;
|
||||
|
||||
import at.favre.lib.crypto.bcrypt.BCrypt;
|
||||
import java.io.IOException;
|
||||
@ -76,24 +75,24 @@ public final class UserUtil {
|
||||
|
||||
public static void addUserForBasicAuth(String username, String pwd, String domain) throws IOException {
|
||||
UserRepository userRepository = (UserRepository) Entity.getEntityRepository(Entity.USER);
|
||||
User originalUser;
|
||||
try {
|
||||
List<String> fields = userRepository.getAllowedFieldsCopy();
|
||||
fields.add(USER_PROTECTED_FIELDS);
|
||||
originalUser = userRepository.getByName(null, username, new EntityUtil.Fields(fields, String.join(",", fields)));
|
||||
List<String> fields = List.of("profile", "roles", "teams", "authenticationMechanism", "isEmailVerified");
|
||||
User originalUser = userRepository.getByName(null, username, new EntityUtil.Fields(fields));
|
||||
if (originalUser.getAuthenticationMechanism() == null) {
|
||||
updateUserWithHashedPwd(originalUser, pwd);
|
||||
updateBasicAuthUser(originalUser, pwd);
|
||||
}
|
||||
addOrUpdateUser(originalUser);
|
||||
} catch (EntityNotFoundException e) {
|
||||
// TODO: Not the best way ! :(
|
||||
User user = user(username, domain, username).withIsAdmin(true).withIsEmailVerified(true);
|
||||
updateUserWithHashedPwd(user, pwd);
|
||||
addOrUpdateUser(user);
|
||||
EmailUtil.sendInviteMailToAdmin(user, pwd);
|
||||
updateBasicAuthUser(user, pwd);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateBasicAuthUser(User user, String pwd) {
|
||||
updateUserWithHashedPwd(user, pwd);
|
||||
addOrUpdateUser(user);
|
||||
EmailUtil.sendInviteMailToAdmin(user, pwd);
|
||||
}
|
||||
|
||||
public static void updateUserWithHashedPwd(User user, String pwd) {
|
||||
String hashedPwd = BCrypt.withDefaults().hashToString(12, pwd.toCharArray());
|
||||
user.setAuthenticationMechanism(
|
||||
|
Loading…
x
Reference in New Issue
Block a user