This is an automated email from the ASF dual-hosted git repository.
yasithdev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/master by this push:
new ce7dd9034e Remove dead credential email-notification subsystem (#665)
ce7dd9034e is described below
commit ce7dd9034ef353a446fe68515ebcbfe7933fef77
Author: Yasith Jayawardana <[email protected]>
AuthorDate: Sat Jun 13 00:38:56 2026 -0400
Remove dead credential email-notification subsystem (#665)
A fully self-contained, unreferenced cluster under credential-service/util:
NotifierBootstrap, EmailNotifier, EmailNotifierConfiguration,
EmailNotificationMessage, NotificationMessage, CredentialStoreNotifier, and
EmailNotifierTest. The classes only reference each other and are reachable
only
from the dead NotifierBootstrap entry point; nothing wires them. The reactor
(incl. test sources) compiles cleanly without them.
---
.../credential/util/CredentialStoreNotifier.java | 59 ---------
.../credential/util/EmailNotificationMessage.java | 53 --------
.../airavata/credential/util/EmailNotifier.java | 76 -----------
.../util/EmailNotifierConfiguration.java | 73 ----------
.../credential/util/NotificationMessage.java | 43 ------
.../credential/util/NotifierBootstrap.java | 147 ---------------------
.../credential/util/EmailNotifierTest.java | 77 -----------
7 files changed, 528 deletions(-)
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/CredentialStoreNotifier.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/CredentialStoreNotifier.java
deleted file mode 100644
index b5299a58b2..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/CredentialStoreNotifier.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util; /*
- *
- * Licensed to the Apache
Software Foundation (ASF) under one
- * or more contributor license
agreements. See the NOTICE file
- * distributed with this work for
additional information
- * regarding copyright ownership.
The ASF licenses this file
- * to you under the Apache
License, Version 2.0 (the
- * "License"); you may not use
this file except in compliance
- * with the License. You may
obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable
law or agreed to in writing,
- * software distributed under the
License is distributed on an
- * "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or
implied. See the License for the
- * specific language governing
permissions and limitations
- * under the License.
- *
- */
-
-import org.apache.airavata.credential.repository.CredentialStoreException;
-
-/**
- * This class is used to notify particular entity with expiring credentials.
- * The default implementation uses email messages.
- * User: AmilaJ ([email protected])
- * Date: 12/3/13
- * Time: 4:17 PM
- */
-public interface CredentialStoreNotifier {
-
- /**
- * The specific notifier implementation needs to implement following
method.
- * This method should actually deliver message to desired entity.
- * @param message The actual message encapsulated
- * @throws CredentialStoreException
- */
- void notifyMessage(NotificationMessage message) throws
CredentialStoreException;
-}
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotificationMessage.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotificationMessage.java
deleted file mode 100644
index 6512c2b412..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotificationMessage.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-/**
- * User: AmilaJ ([email protected])
- * Date: 12/3/13
- * Time: 5:01 PM
- */
-public class EmailNotificationMessage extends NotificationMessage {
-
- public EmailNotificationMessage(String subject, String senderEmail, String
msg) {
- super(msg);
- this.subject = subject;
- this.senderEmail = senderEmail;
- }
-
- private String subject;
- private String senderEmail;
-
- public String getSubject() {
- return subject;
- }
-
- public void setSubject(String subject) {
- this.subject = subject;
- }
-
- public String getSenderEmail() {
- return senderEmail;
- }
-
- public void setSenderEmail(String senderEmail) {
- this.senderEmail = senderEmail;
- }
-}
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifier.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifier.java
deleted file mode 100644
index 74ceb223b6..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifier.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-import jakarta.mail.MessagingException;
-import jakarta.mail.internet.MimeMessage;
-import org.apache.airavata.credential.repository.CredentialStoreException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.mail.javamail.JavaMailSender;
-import org.springframework.mail.javamail.JavaMailSenderImpl;
-import org.springframework.mail.javamail.MimeMessageHelper;
-
-/**
- * Sends email notifications using Spring's JavaMailSender.
- */
-public class EmailNotifier implements CredentialStoreNotifier {
-
- private static final Logger log =
LoggerFactory.getLogger(EmailNotifier.class);
-
- private final JavaMailSender mailSender;
- private final String fromAddress;
-
- public EmailNotifier(EmailNotifierConfiguration config) {
- JavaMailSenderImpl sender = new JavaMailSenderImpl();
- sender.setHost(config.getEmailServer());
- sender.setPort(config.getEmailServerPort());
- sender.setUsername(config.getEmailUserName());
- sender.setPassword(config.getEmailPassword());
- if (config.isSslConnect()) {
- sender.getJavaMailProperties().put("mail.smtp.ssl.enable", "true");
- }
- sender.getJavaMailProperties().put("mail.smtp.auth", "true");
- this.mailSender = sender;
- this.fromAddress = config.getFromAddress();
- }
-
- /** Package-private constructor for testing with a mock/stub
JavaMailSender. */
- EmailNotifier(JavaMailSender mailSender, String fromAddress) {
- this.mailSender = mailSender;
- this.fromAddress = fromAddress;
- }
-
- public void notifyMessage(NotificationMessage message) throws
CredentialStoreException {
- try {
- EmailNotificationMessage emailMessage = (EmailNotificationMessage)
message;
- MimeMessage mimeMessage = mailSender.createMimeMessage();
- MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,
false);
- helper.setFrom(fromAddress);
- helper.setTo(emailMessage.getSenderEmail());
- helper.setSubject(emailMessage.getSubject());
- helper.setText(emailMessage.getMessage());
- mailSender.send(mimeMessage);
- } catch (MessagingException e) {
- log.error("[CredentialStore] Error sending email notification
message.");
- throw new CredentialStoreException("Error sending email
notification message", e);
- }
- }
-}
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifierConfiguration.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifierConfiguration.java
deleted file mode 100644
index 2c7628bde6..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/EmailNotifierConfiguration.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-/**
- * User: AmilaJ ([email protected])
- * Date: 12/3/13
- * Time: 5:06 PM
- */
-public class EmailNotifierConfiguration {
- private String emailServer;
- private int emailServerPort;
- private String emailUserName;
- private String emailPassword;
- private boolean sslConnect;
- private String fromAddress;
-
- public EmailNotifierConfiguration(
- String emailServer,
- int emailServerPort,
- String emailUserName,
- String emailPassword,
- boolean sslConnect,
- String fromAddress) {
- this.emailServer = emailServer;
- this.emailServerPort = emailServerPort;
- this.emailUserName = emailUserName;
- this.emailPassword = emailPassword;
- this.sslConnect = sslConnect;
- this.fromAddress = fromAddress;
- }
-
- public String getEmailServer() {
- return emailServer;
- }
-
- public int getEmailServerPort() {
- return emailServerPort;
- }
-
- public String getEmailUserName() {
- return emailUserName;
- }
-
- public String getEmailPassword() {
- return emailPassword;
- }
-
- public boolean isSslConnect() {
- return sslConnect;
- }
-
- public String getFromAddress() {
- return fromAddress;
- }
-}
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotificationMessage.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotificationMessage.java
deleted file mode 100644
index ac93acba4c..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotificationMessage.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-/**
- * User: AmilaJ ([email protected])
- * Date: 12/3/13
- * Time: 4:21 PM
- */
-
-/**
- * Encapsulates the notification message.
- * Usually says particular credential is expiring and need to renew.
- */
-public class NotificationMessage {
-
- protected String message;
-
- public NotificationMessage(String msg) {
- this.message = msg;
- }
-
- public String getMessage() {
- return message;
- }
-}
diff --git
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotifierBootstrap.java
b/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotifierBootstrap.java
deleted file mode 100644
index ecd9ddbb58..0000000000
---
a/airavata-api/credential-service/src/main/java/org/apache/airavata/credential/util/NotifierBootstrap.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-/**
- * User: AmilaJ ([email protected])
- * Date: 12/27/13
- * Time: 2:22 PM
- */
-import java.text.ParseException;
-import java.util.*;
-import java.util.stream.Collectors;
-import org.apache.airavata.credential.repository.CredentialRepository;
-import org.apache.airavata.credential.repository.CredentialStoreException;
-import org.apache.airavata.model.credential.store.proto.CommunityUser;
-import org.apache.airavata.model.credential.store.proto.StoredCredential;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class runs a timer. Periodically it checks for expiring credentials.
- * Then if there are expiring credentials this will send an email.
- */
-public class NotifierBootstrap extends TimerTask {
-
- private static boolean enabled = false;
-
- private static String MESSAGE = "Credentials for community user {0}
expires at {1}";
- private static String SUBJECT = "Expiring credentials for user {0}";
-
- private CredentialRepository credentialRepository;
- private CredentialEncryptionUtil encryptionUtil;
-
- private long period;
-
- protected static Logger log =
LoggerFactory.getLogger(NotifierBootstrap.class);
-
- private CredentialStoreNotifier credentialStoreNotifier;
-
- public NotifierBootstrap(
- long period,
- CredentialRepository credentialRepository,
- CredentialEncryptionUtil encryptionUtil,
- EmailNotifierConfiguration configuration) {
- this.period = period;
- this.credentialRepository = credentialRepository;
- this.encryptionUtil = encryptionUtil;
-
- // bootstrap
- if (enabled) {
- Timer timer = new Timer();
- timer.scheduleAtFixedRate(this, 0, period);
- }
-
- this.credentialStoreNotifier = new EmailNotifier(configuration);
- }
-
- public long getPeriod() {
- return period;
- }
-
- public void setPeriod(long period) {
- this.period = period;
- }
-
- public static boolean isEnabled() {
- return enabled;
- }
-
- public static void setEnabled(boolean enabled) {
- NotifierBootstrap.enabled = enabled;
- }
-
- @Override
- public void run() {
-
- if (!enabled) return;
-
- // retrieve OA4MP credentials
- try {
- List<StoredCredential> credentials =
credentialRepository.findAll().stream()
- .map(entity -> {
- try {
- StoredCredential stored =
-
encryptionUtil.convertByteArrayToCredential(entity.getCredential());
- long persistedTime = entity.getTimePersisted() !=
null
- ? entity.getTimePersisted().getTime()
- : 0;
- return CredentialEncryptionUtil.overlayDbFields(
- stored,
- entity.getPortalUserId(),
- persistedTime,
- entity.getDescription(),
- entity.getTokenId());
- } catch (CredentialStoreException e) {
- throw new RuntimeException(
- "Error deserializing credential for token
" + entity.getTokenId(), e);
- }
- })
- .collect(Collectors.toList());
-
- for (StoredCredential credential : credentials) {
- if (credential.getCredentialCase() ==
StoredCredential.CredentialCase.CERTIFICATE_CREDENTIAL) {
- var certificateCredential =
credential.getCertificateCredential();
-
- Date date =
Utility.convertStringToDate(certificateCredential.getNotAfter());
- date.setDate(date.getDate() + 1); // gap is 1 days
-
- Date currentDate = new Date();
- if (currentDate.after(date)) {
- // Send an email
- CommunityUser communityUser =
certificateCredential.getCommunityUser();
- String body = String.format(
- MESSAGE, communityUser.getUsername(),
certificateCredential.getNotAfter());
- String subject = String.format(SUBJECT,
communityUser.getUsername());
- NotificationMessage notificationMessage =
- new EmailNotificationMessage(subject,
communityUser.getUserEmail(), body);
-
-
this.credentialStoreNotifier.notifyMessage(notificationMessage);
- }
- }
- }
-
- } catch (CredentialStoreException e) {
- log.error("Error sending emails about credential expiring.", e);
- } catch (ParseException e) {
- log.error("Error parsing date time when sending emails", e);
- }
- }
-}
diff --git
a/airavata-api/credential-service/src/test/java/org/apache/airavata/credential/util/EmailNotifierTest.java
b/airavata-api/credential-service/src/test/java/org/apache/airavata/credential/util/EmailNotifierTest.java
deleted file mode 100644
index c0b86ab3a9..0000000000
---
a/airavata-api/credential-service/src/test/java/org/apache/airavata/credential/util/EmailNotifierTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
-*
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* to you under the Apache License, Version 2.0 (the
-* "License"); you may not use this file except in compliance
-* with the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing,
-* software distributed under the License is distributed on an
-* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-* KIND, either express or implied. See the License for the
-* specific language governing permissions and limitations
-* under the License.
-*/
-package org.apache.airavata.credential.util;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-import com.icegreen.greenmail.util.GreenMail;
-import com.icegreen.greenmail.util.ServerSetup;
-import jakarta.mail.internet.MimeMessage;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-class EmailNotifierTest {
-
- private GreenMail greenMail;
-
- @BeforeEach
- void setUp() {
- greenMail = new GreenMail(new ServerSetup(0, "localhost",
ServerSetup.PROTOCOL_SMTP));
- greenMail.start();
- greenMail.setUser("[email protected]", "[email protected]", "password");
- }
-
- @AfterEach
- void tearDown() {
- greenMail.stop();
- }
-
- @Test
- void notifyMessage_sendsEmail() throws Exception {
- EmailNotifierConfiguration config = new EmailNotifierConfiguration(
- "localhost", greenMail.getSmtp().getPort(), "[email protected]",
"password", false, "[email protected]");
-
- EmailNotifier notifier = new EmailNotifier(config);
- EmailNotificationMessage message =
- new EmailNotificationMessage("Test Subject",
"[email protected]", "Test body content");
-
- notifier.notifyMessage(message);
-
- MimeMessage[] received = greenMail.getReceivedMessages();
- assertEquals(1, received.length);
- assertEquals("Test Subject", received[0].getSubject());
- assertTrue(received[0].getContent().toString().contains("Test body
content"));
- }
-
- @Test
- void notifyMessage_multipleMessages_allDelivered() throws Exception {
- EmailNotifierConfiguration config = new EmailNotifierConfiguration(
- "localhost", greenMail.getSmtp().getPort(), "[email protected]",
"password", false, "[email protected]");
-
- EmailNotifier notifier = new EmailNotifier(config);
-
- notifier.notifyMessage(new EmailNotificationMessage("Msg 1",
"[email protected]", "First message"));
- notifier.notifyMessage(new EmailNotificationMessage("Msg 2",
"[email protected]", "Second message"));
-
- MimeMessage[] received = greenMail.getReceivedMessages();
- assertEquals(2, received.length);
- }
-}