[FIX] Fix IsEmailServiceEnabled. (#17601)

* fix isEmailServiceEnabled.

* use getSmtpSettings() from emailUtil
This commit is contained in:
Siddhant 2024-08-27 23:23:20 +05:30 committed by GitHub
parent 8c9abbcae7
commit 19b5d49dc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -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.jdbi3.UserRepository.AUTH_MECHANISM_FIELD;
import static org.openmetadata.service.secrets.ExternalSecretsManager.NULL_SECRET_STRING; import static org.openmetadata.service.secrets.ExternalSecretsManager.NULL_SECRET_STRING;
import static org.openmetadata.service.security.jwt.JWTTokenGenerator.getExpiryDate; 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.getRoleListFromUser;
import static org.openmetadata.service.util.UserUtil.getRolesFromAuthorizationToken; import static org.openmetadata.service.util.UserUtil.getRolesFromAuthorizationToken;
import static org.openmetadata.service.util.UserUtil.getUser; import static org.openmetadata.service.util.UserUtil.getUser;
@ -191,6 +192,10 @@ public class UserResource extends EntityResource<User, UserRepository> {
return user; return user;
} }
private boolean isEmailServiceEnabled() {
return getSmtpSettings().getEnableSmtpServer();
}
public UserResource( public UserResource(
Authorizer authorizer, Limits limits, AuthenticatorHandler authenticatorHandler) { Authorizer authorizer, Limits limits, AuthenticatorHandler authenticatorHandler) {
super(Entity.USER, authorizer, limits); super(Entity.USER, authorizer, limits);
@ -643,7 +648,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
} }
private void sendInviteMailToUserForBasicAuth(UriInfo uriInfo, User user, CreateUser create) { private void sendInviteMailToUserForBasicAuth(UriInfo uriInfo, User user, CreateUser create) {
if (isBasicAuth() && isEmailServiceEnabled) { if (isBasicAuth() && isEmailServiceEnabled()) {
try { try {
authHandler.sendInviteMailToUser( authHandler.sendInviteMailToUser(
uriInfo, uriInfo,

View File

@ -111,6 +111,10 @@ public class BasicAuthenticator implements AuthenticatorHandler {
this.isSelfSignUpAvailable = config.getAuthenticationConfiguration().getEnableSelfSignup(); this.isSelfSignUpAvailable = config.getAuthenticationConfiguration().getEnableSelfSignup();
} }
private boolean isEmailServiceEnabled() {
return getSmtpSettings().getEnableSmtpServer();
}
@Override @Override
public User registerUser(RegistrationRequest newRegistrationRequest) { public User registerUser(RegistrationRequest newRegistrationRequest) {
if (isSelfSignUpAvailable) { if (isSelfSignUpAvailable) {
@ -173,7 +177,7 @@ public class BasicAuthenticator implements AuthenticatorHandler {
@Override @Override
public void sendEmailVerification(UriInfo uriInfo, User user) throws IOException { public void sendEmailVerification(UriInfo uriInfo, User user) throws IOException {
if (isEmailServiceEnabled) { if (isEmailServiceEnabled()) {
UUID mailVerificationToken = UUID.randomUUID(); UUID mailVerificationToken = UUID.randomUUID();
EmailVerificationToken emailVerificationToken = EmailVerificationToken emailVerificationToken =
TokenUtil.getEmailVerificationToken(user.getId(), mailVerificationToken); TokenUtil.getEmailVerificationToken(user.getId(), mailVerificationToken);
@ -310,7 +314,7 @@ public class BasicAuthenticator implements AuthenticatorHandler {
loginAttemptCache.recordSuccessfulLogin(userName); loginAttemptCache.recordSuccessfulLogin(userName);
// in case admin updates , send email to user // in case admin updates , send email to user
if (request.getRequestType() == USER && isEmailServiceEnabled) { if (request.getRequestType() == USER && isEmailServiceEnabled()) {
// Send mail // Send mail
sendInviteMailToUser( sendInviteMailToUser(
uriInfo, uriInfo,