Skip to content

Commit b488ca2

Browse files
committed
feat: add organization name configuration parameter
1 parent 0ae93d0 commit b488ca2

File tree

5 files changed

+28
-20
lines changed

5 files changed

+28
-20
lines changed

backend/src/main/java/com/park/utmstack/service/MailService.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.scheduling.annotation.Async;
2525
import org.springframework.stereotype.Service;
2626
import org.springframework.util.CollectionUtils;
27-
import org.springframework.util.StringUtils;
2827
import org.thymeleaf.context.Context;
2928
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect;
3029
import org.thymeleaf.spring5.SpringTemplateEngine;
@@ -62,6 +61,8 @@ public class MailService {
6261

6362
private static final String BASE_URL = "baseUrl";
6463

64+
private static final String ORG_NAME = "orgName";
65+
6566
private final MessageSource messageSource;
6667
private final SpringTemplateEngine templateEngine;
6768
private final ApplicationEventService eventService;
@@ -79,22 +80,6 @@ public MailService(MessageSource messageSource,
7980
this.templateEngine.addDialect(new Java8TimeDialect());
8081
}
8182

82-
// private JavaMailSender getJavaMailSender() {
83-
// JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
84-
// mailSender.setHost(Constants.CFG.get(Constants.PROP_MAIL_HOST));
85-
// mailSender.setPort(Integer.parseInt(Constants.CFG.get(Constants.PROP_MAIL_PORT)));
86-
// mailSender.setPassword(Constants.CFG.get(Constants.PROP_MAIL_PASSWORD));
87-
// mailSender.setUsername(Constants.CFG.get(Constants.PROP_MAIL_USERNAME));
88-
// mailSender.setProtocol(Constants.CFG.get(Constants.PROP_MAIL_PROTOCOL));
89-
//
90-
// Properties props = mailSender.getJavaMailProperties();
91-
// props.put("mail.smtp.auth", Constants.CFG.get(Constants.PROP_MAIL_SMTP_AUTH));
92-
// props.put("mail.smtp.starttls.enable", Constants.CFG.get(Constants.PROP_MAIL_SMTP_STARTTLS_ENABLE));
93-
// props.put("mail.smtp.ssl.trust", Constants.CFG.get(Constants.PROP_MAIL_SMTP_SSL_TRUST));
94-
//
95-
// return mailSender;
96-
// }
97-
9883
private MailSenderStrategy getSender(String type){
9984
return mailSenders.stream()
10085
.filter(s -> s.getEncryptionType().equals(type))
@@ -277,11 +262,12 @@ public void sendAlertEmail(List<String> emailsTo, AlertType alert, List<LogType>
277262
context.setVariable("relatedLogs", relatedLogs);
278263
context.setVariable("timestamp", alert.getTimestampFormatted());
279264
context.setVariable(BASE_URL, Constants.CFG.get(Constants.PROP_MAIL_BASE_URL));
265+
context.setVariable(ORG_NAME, Constants.CFG.get(Constants.PROP_MAIL_ORGNAME));
280266

281267
final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
282268
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
283269
message.setSubject(String.format("%1$s[%2$s]: %3$s", alert.getIncident() ? "INFOSEC-" : "", alert.getId().substring(0, 5), alert.getName()));
284-
message.setFrom(Constants.CFG.get(Constants.PROP_MAIL_FROM));
270+
message.setFrom(new InternetAddress(Constants.CFG.get(Constants.PROP_MAIL_FROM), Constants.CFG.get(Constants.PROP_MAIL_ORGNAME)));
285271
message.setTo(emailsTo.toArray(new String[0]));
286272

287273
final String htmlContent = templateEngine.process("mail/alertEmail", context);
@@ -314,9 +300,12 @@ public void sendIncidentEmail(List<String> emailsTo, List<AlertType> alerts, Utm
314300
context.setVariable("alerts", alerts);
315301
context.setVariable("incident", incident);
316302
context.setVariable(BASE_URL, Constants.CFG.get(Constants.PROP_MAIL_BASE_URL));
303+
context.setVariable(ORG_NAME, Constants.CFG.get(Constants.PROP_MAIL_ORGNAME));
304+
317305
final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
318306
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
319307
message.setSubject(String.format("%1$s[%2$s]: %3$s", "INFOSEC- New Incident ", incident.getId().toString(), incident.getIncidentName()));
308+
message.setFrom(new InternetAddress(Constants.CFG.get(Constants.PROP_MAIL_FROM), Constants.CFG.get(Constants.PROP_MAIL_ORGNAME)));
320309
message.setFrom(Constants.CFG.get(Constants.PROP_MAIL_FROM));
321310
message.setTo(emailsTo.toArray(new String[0]));
322311

backend/src/main/java/com/park/utmstack/service/mail_config/MailConfigService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public String getParamValue(List<UtmConfigurationParameter> parameters, String s
2828
return parameters.stream()
2929
.filter(p -> p.getConfParamShort().equals(shortName))
3030
.findFirst()
31-
. map(UtmConfigurationParameter::getConfParamValue)
31+
.map(UtmConfigurationParameter::getConfParamValue)
3232
.orElse(Constants.CFG.get(shortName));
3333
}
3434
}

backend/src/main/resources/config/liquibase/changelog/20250319001_add_organization_field_config_params.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@
88
<sql>
99
<![CDATA[
1010
INSERT INTO utm_configuration_parameter (id, section_id, conf_param_short, conf_param_large, conf_param_description, conf_param_value, conf_param_required, conf_param_datatype, modification_time, modification_user, conf_param_option, conf_param_regexp)
11-
VALUES (10, 2, 'utmstack.mail.organization', 'Organization Name', 'Displays the organization name in emails.', '', true, 'text', null, null, null, null);
11+
VALUES (10, 2, 'utmstack.mail.organization', 'Organization Name', 'This field helps identify the organization name in incident and alert notification emails.', '', false, 'text', null, null, null, null);
12+
13+
UPDATE public.utm_configuration_parameter
14+
SET conf_param_required = true
15+
WHERE id = 4 AND section_id = 2;
16+
17+
UPDATE public.utm_configuration_parameter
18+
SET conf_param_required = true
19+
WHERE id = 9 AND section_id = 2;
20+
1221
]]>
1322
</sql>
1423
</changeSet>

backend/src/main/resources/templates/mail/fragments/alert-detail-fragment.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
</thead>
1414
<tbody>
1515

16+
<tr th:if="${orgName != null && !#strings.isEmpty(orgName)}" style="font-family:Roboto, sans-serif;font-size: 13px">
17+
<td style="font-weight: bold;vertical-align: top;" th:text="'Organization:'"></td>
18+
<td style="vertical-align: top;" th:text="${orgName}"></td>
19+
</tr>
20+
1621
<tr style="font-family:Roboto, sans-serif;font-size: 13px">
1722
<td style="font-weight: bold;vertical-align: top;" th:text="'Name:'"></td>
1823
<td style="vertical-align: top;" th:text="${alert.getName()}"></td>

backend/src/main/resources/templates/mail/newIncidentEmail.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ <h1 style="font-family:Roboto, sans-serif;">
2525
</thead>
2626
<tbody>
2727

28+
<tr th:if="${orgName != null && !#strings.isEmpty(orgName)}" style="font-family:Roboto, sans-serif;font-size: 13px">
29+
<td style="font-weight: bold;vertical-align: top;" th:text="'Organization:'"></td>
30+
<td style="vertical-align: top;" th:text="${orgName}"></td>
31+
</tr>
32+
2833
<tr style="font-family:Roboto, sans-serif;font-size: 13px">
2934
<td style="font-weight: bold;vertical-align: top;" th:text="'Name:'"></td>
3035
<td style="vertical-align: top;"

0 commit comments

Comments
 (0)