mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-01 19:18:05 +00:00
[Email] Added explicit senderMail in configuration (#8126)
* [Email] Added explicit senderMail in configuration * Fix failing tests Co-authored-by: Ayush Shah <ayush@getcollate.io>
This commit is contained in:
parent
7975f0e6fe
commit
cba9240fe9
@ -243,6 +243,7 @@ email:
|
|||||||
supportUrl: ${OM_SUPPORT_URL:-"https://slack.open-metadata.org"}
|
supportUrl: ${OM_SUPPORT_URL:-"https://slack.open-metadata.org"}
|
||||||
enableSmtpServer : ${AUTHORIZER_ENABLE_SMTP:-false}
|
enableSmtpServer : ${AUTHORIZER_ENABLE_SMTP:-false}
|
||||||
openMetadataUrl: ${OPENMETADATA_SERVER_URL:-""}
|
openMetadataUrl: ${OPENMETADATA_SERVER_URL:-""}
|
||||||
|
senderMail: ${OPENMETADATA_SMTP_SENDER_MAIL:-""}
|
||||||
serverEndpoint: ${SMTP_SERVER_ENDPOINT:-""}
|
serverEndpoint: ${SMTP_SERVER_ENDPOINT:-""}
|
||||||
serverPort: ${SMTP_SERVER_PORT:-""}
|
serverPort: ${SMTP_SERVER_PORT:-""}
|
||||||
username: ${SMTP_SERVER_USERNAME:-""}
|
username: ${SMTP_SERVER_USERNAME:-""}
|
||||||
|
|||||||
@ -96,7 +96,9 @@ public class OpenMetadataApplication extends Application<OpenMetadataApplication
|
|||||||
throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException,
|
throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException,
|
||||||
InvocationTargetException, IOException {
|
InvocationTargetException, IOException {
|
||||||
// init email Util for handling
|
// init email Util for handling
|
||||||
EmailUtil.EmailUtilBuilder.build(catalogConfig.getSmtpSettings());
|
if (catalogConfig.getSmtpSettings() != null && catalogConfig.getSmtpSettings().getEnableSmtpServer()) {
|
||||||
|
EmailUtil.EmailUtilBuilder.build(catalogConfig.getSmtpSettings());
|
||||||
|
}
|
||||||
final Jdbi jdbi = createAndSetupJDBI(environment, catalogConfig.getDataSourceFactory());
|
final Jdbi jdbi = createAndSetupJDBI(environment, catalogConfig.getDataSourceFactory());
|
||||||
final SecretsManager secretsManager =
|
final SecretsManager secretsManager =
|
||||||
SecretsManagerFactory.createSecretsManager(
|
SecretsManagerFactory.createSecretsManager(
|
||||||
|
|||||||
@ -65,12 +65,12 @@ public class UserRepository extends EntityRepository<User> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final Fields getFieldsWithUserAuth(String fields) {
|
public final Fields getFieldsWithUserAuth(String fields) {
|
||||||
|
List<String> tempFields = getAllowedFieldsCopy();
|
||||||
if (fields != null && fields.equals("*")) {
|
if (fields != null && fields.equals("*")) {
|
||||||
List<String> tempFields = getAllowedFieldsCopy();
|
|
||||||
tempFields.add("authenticationMechanism");
|
tempFields.add("authenticationMechanism");
|
||||||
return new Fields(allowedFields, String.join(",", tempFields));
|
return new Fields(tempFields, String.join(",", tempFields));
|
||||||
}
|
}
|
||||||
return new Fields(allowedFields, fields);
|
return new Fields(tempFields, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -41,6 +41,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
|||||||
import org.jdbi.v3.core.Jdbi;
|
import org.jdbi.v3.core.Jdbi;
|
||||||
import org.openmetadata.schema.api.configuration.airflow.AirflowConfiguration;
|
import org.openmetadata.schema.api.configuration.airflow.AirflowConfiguration;
|
||||||
import org.openmetadata.schema.api.security.AuthenticationConfiguration;
|
import org.openmetadata.schema.api.security.AuthenticationConfiguration;
|
||||||
|
import org.openmetadata.schema.email.SmtpSettings;
|
||||||
import org.openmetadata.schema.entity.Bot;
|
import org.openmetadata.schema.entity.Bot;
|
||||||
import org.openmetadata.schema.entity.BotType;
|
import org.openmetadata.schema.entity.BotType;
|
||||||
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
|
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
|
||||||
@ -71,6 +72,7 @@ import org.openmetadata.service.security.policyevaluator.SubjectCache;
|
|||||||
import org.openmetadata.service.security.policyevaluator.SubjectContext;
|
import org.openmetadata.service.security.policyevaluator.SubjectContext;
|
||||||
import org.openmetadata.service.util.EmailUtil;
|
import org.openmetadata.service.util.EmailUtil;
|
||||||
import org.openmetadata.service.util.EntityUtil;
|
import org.openmetadata.service.util.EntityUtil;
|
||||||
|
import org.openmetadata.service.util.PasswordUtil;
|
||||||
import org.openmetadata.service.util.RestUtil;
|
import org.openmetadata.service.util.RestUtil;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -81,8 +83,8 @@ public class DefaultAuthorizer implements Authorizer {
|
|||||||
private Set<String> botPrincipalUsers;
|
private Set<String> botPrincipalUsers;
|
||||||
private Set<String> testUsers;
|
private Set<String> testUsers;
|
||||||
private String principalDomain;
|
private String principalDomain;
|
||||||
|
|
||||||
private String providerType;
|
private String providerType;
|
||||||
|
private boolean isSmtpEnabled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(OpenMetadataApplicationConfig openMetadataApplicationConfig, Jdbi dbi) {
|
public void init(OpenMetadataApplicationConfig openMetadataApplicationConfig, Jdbi dbi) {
|
||||||
@ -94,6 +96,8 @@ public class DefaultAuthorizer implements Authorizer {
|
|||||||
this.testUsers = new HashSet<>(openMetadataApplicationConfig.getAuthorizerConfiguration().getTestPrincipals());
|
this.testUsers = new HashSet<>(openMetadataApplicationConfig.getAuthorizerConfiguration().getTestPrincipals());
|
||||||
this.principalDomain = openMetadataApplicationConfig.getAuthorizerConfiguration().getPrincipalDomain();
|
this.principalDomain = openMetadataApplicationConfig.getAuthorizerConfiguration().getPrincipalDomain();
|
||||||
this.providerType = openMetadataApplicationConfig.getAuthenticationConfiguration().getProvider();
|
this.providerType = openMetadataApplicationConfig.getAuthenticationConfiguration().getProvider();
|
||||||
|
SmtpSettings smtpSettings = openMetadataApplicationConfig.getSmtpSettings();
|
||||||
|
this.isSmtpEnabled = smtpSettings != null && smtpSettings.getEnableSmtpServer();
|
||||||
SubjectCache.initialize();
|
SubjectCache.initialize();
|
||||||
PolicyCache.initialize();
|
PolicyCache.initialize();
|
||||||
RoleCache.initialize();
|
RoleCache.initialize();
|
||||||
@ -149,7 +153,12 @@ public class DefaultAuthorizer implements Authorizer {
|
|||||||
String[] tokens = adminUser.split(COLON_DELIMITER);
|
String[] tokens = adminUser.split(COLON_DELIMITER);
|
||||||
addUserForBasicAuth(tokens[0], tokens[1], domain);
|
addUserForBasicAuth(tokens[0], tokens[1], domain);
|
||||||
} else {
|
} else {
|
||||||
addUserForBasicAuth(adminUser, DEFAULT_ADMIN, domain);
|
boolean isDefaultAdmin = adminUser.equals(DEFAULT_ADMIN);
|
||||||
|
String token = PasswordUtil.generateRandomPassword();
|
||||||
|
if (isDefaultAdmin || !isSmtpEnabled) {
|
||||||
|
token = DEFAULT_ADMIN;
|
||||||
|
}
|
||||||
|
addUserForBasicAuth(adminUser, token, domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +179,9 @@ public class DefaultAuthorizer implements Authorizer {
|
|||||||
User user = user(username, domain, username).withIsAdmin(true).withIsEmailVerified(true);
|
User user = user(username, domain, username).withIsAdmin(true).withIsEmailVerified(true);
|
||||||
updateUserWithHashedPwd(user, pwd);
|
updateUserWithHashedPwd(user, pwd);
|
||||||
addOrUpdateUser(user);
|
addOrUpdateUser(user);
|
||||||
sendInviteMailToAdmin(user, pwd);
|
if (isSmtpEnabled) {
|
||||||
|
sendInviteMailToAdmin(user, pwd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -173,7 +173,7 @@ public class EmailUtil {
|
|||||||
&& request.getSubject() != null
|
&& request.getSubject() != null
|
||||||
&& !request.getSubject().equals("")) {
|
&& !request.getSubject().equals("")) {
|
||||||
// Sender Details
|
// Sender Details
|
||||||
emailBuilder.from(defaultSmtpSettings.getUsername());
|
emailBuilder.from(defaultSmtpSettings.getSenderMail());
|
||||||
|
|
||||||
// Recipient
|
// Recipient
|
||||||
request
|
request
|
||||||
@ -239,7 +239,7 @@ public class EmailUtil {
|
|||||||
EmailPopulatingBuilder emailBuilder = EmailBuilder.startingBlank();
|
EmailPopulatingBuilder emailBuilder = EmailBuilder.startingBlank();
|
||||||
emailBuilder.withSubject(subject);
|
emailBuilder.withSubject(subject);
|
||||||
emailBuilder.to(to);
|
emailBuilder.to(to);
|
||||||
emailBuilder.from(defaultSmtpSettings.getUsername());
|
emailBuilder.from(defaultSmtpSettings.getSenderMail());
|
||||||
|
|
||||||
templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage);
|
templateConfiguration.setClassForTemplateLoading(getClass(), baseTemplatePackage);
|
||||||
Template template = templateConfiguration.getTemplate(templatePath);
|
Template template = templateConfiguration.getTemplate(templatePath);
|
||||||
@ -253,7 +253,7 @@ public class EmailUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMail(Email email) {
|
public void sendMail(Email email) {
|
||||||
if (mailer != null) {
|
if (mailer != null && defaultSmtpSettings.getEnableSmtpServer()) {
|
||||||
mailer.sendMail(email, true);
|
mailer.sendMail(email, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,7 +177,10 @@ airflowConfiguration:
|
|||||||
|
|
||||||
email:
|
email:
|
||||||
enableSmtpServer : false
|
enableSmtpServer : false
|
||||||
|
emailingEntity: ""
|
||||||
|
supportUrl: ""
|
||||||
openMetadataUrl: ""
|
openMetadataUrl: ""
|
||||||
|
senderMail: ""
|
||||||
serverEndpoint: ""
|
serverEndpoint: ""
|
||||||
serverPort: ""
|
serverPort: ""
|
||||||
username: ""
|
username: ""
|
||||||
|
|||||||
@ -25,6 +25,10 @@
|
|||||||
"description": "Openmetadata Server Endpoint",
|
"description": "Openmetadata Server Endpoint",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"senderMail": {
|
||||||
|
"description": "Mail of the sender",
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"serverEndpoint": {
|
"serverEndpoint": {
|
||||||
"description": "Smtp Server Endpoint",
|
"description": "Smtp Server Endpoint",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@ -48,5 +52,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": ["serverEndpoint", "serverPort", "username", "password"]
|
"required": ["serverEndpoint", "serverPort", "username", "password", "senderMail"]
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user