From 19b5d49dc832e34729b1296552c8cc4e0cb7bf33 Mon Sep 17 00:00:00 2001 From: Siddhant <86899184+Siddhanttimeline@users.noreply.github.com> Date: Tue, 27 Aug 2024 23:23:20 +0530 Subject: [PATCH] [FIX] Fix IsEmailServiceEnabled. (#17601) * fix isEmailServiceEnabled. * use getSmtpSettings() from emailUtil --- .../service/resources/teams/UserResource.java | 7 ++++++- .../service/security/auth/BasicAuthenticator.java | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java index e954b07a65b..4ddf3dba19c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java @@ -27,6 +27,7 @@ import static org.openmetadata.service.exception.CatalogExceptionMessage.EMAIL_S import static org.openmetadata.service.jdbi3.UserRepository.AUTH_MECHANISM_FIELD; import static org.openmetadata.service.secrets.ExternalSecretsManager.NULL_SECRET_STRING; import static org.openmetadata.service.security.jwt.JWTTokenGenerator.getExpiryDate; +import static org.openmetadata.service.util.EmailUtil.getSmtpSettings; import static org.openmetadata.service.util.UserUtil.getRoleListFromUser; import static org.openmetadata.service.util.UserUtil.getRolesFromAuthorizationToken; import static org.openmetadata.service.util.UserUtil.getUser; @@ -191,6 +192,10 @@ public class UserResource extends EntityResource { return user; } + private boolean isEmailServiceEnabled() { + return getSmtpSettings().getEnableSmtpServer(); + } + public UserResource( Authorizer authorizer, Limits limits, AuthenticatorHandler authenticatorHandler) { super(Entity.USER, authorizer, limits); @@ -643,7 +648,7 @@ public class UserResource extends EntityResource { } private void sendInviteMailToUserForBasicAuth(UriInfo uriInfo, User user, CreateUser create) { - if (isBasicAuth() && isEmailServiceEnabled) { + if (isBasicAuth() && isEmailServiceEnabled()) { try { authHandler.sendInviteMailToUser( uriInfo, diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java index e323fbb25ec..c44cee55815 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java @@ -111,6 +111,10 @@ public class BasicAuthenticator implements AuthenticatorHandler { this.isSelfSignUpAvailable = config.getAuthenticationConfiguration().getEnableSelfSignup(); } + private boolean isEmailServiceEnabled() { + return getSmtpSettings().getEnableSmtpServer(); + } + @Override public User registerUser(RegistrationRequest newRegistrationRequest) { if (isSelfSignUpAvailable) { @@ -173,7 +177,7 @@ public class BasicAuthenticator implements AuthenticatorHandler { @Override public void sendEmailVerification(UriInfo uriInfo, User user) throws IOException { - if (isEmailServiceEnabled) { + if (isEmailServiceEnabled()) { UUID mailVerificationToken = UUID.randomUUID(); EmailVerificationToken emailVerificationToken = TokenUtil.getEmailVerificationToken(user.getId(), mailVerificationToken); @@ -310,7 +314,7 @@ public class BasicAuthenticator implements AuthenticatorHandler { loginAttemptCache.recordSuccessfulLogin(userName); // in case admin updates , send email to user - if (request.getRequestType() == USER && isEmailServiceEnabled) { + if (request.getRequestType() == USER && isEmailServiceEnabled()) { // Send mail sendInviteMailToUser( uriInfo,