Skip to content

Commit

Permalink
feat(mail): enable backward compat for javamail resource from app ser…
Browse files Browse the repository at this point in the history
…ver #7424
  • Loading branch information
poikilotherm committed Sep 24, 2023
1 parent 51af5e1 commit 36d78fd
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse.util;

import edu.harvard.iq.dataverse.settings.JvmSettings;
import jakarta.annotation.Resource;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
Expand All @@ -10,6 +11,7 @@

import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;

@ApplicationScoped
public class MailSessionProducer {
Expand All @@ -34,12 +36,29 @@ public class MailSessionProducer {
);

private static final String PREFIX = "mail.smtp.";
private static final Logger logger = Logger.getLogger(MailSessionProducer.class.getCanonicalName());

Session systemMailSession;

/**
* Inject the application server provided (user defined) javamail resource to enable backwards compatibility.
* @deprecated This should be removed with the next major release of Dataverse, as it would be a breaking change.
*/
@Deprecated(forRemoval = true, since = "6.1")
@Resource(name = "mail/notifyMailSession")
Session appserverProvidedSession;


@Produces
@Named("mail/systemSession")
public Session getSession() {
// For backward compatibility, prefer to return the mail resource configured on the appserver.
if (appserverProvidedSession != null) {
logger.warning("The configuration of mail transfer agents using asadmin create-javamail-resource is" +
" deprecated. Please migrate to using JVM options, see Dataverse guides for details");
return appserverProvidedSession;
}

if (systemMailSession == null) {
// Initialize with null (= no authenticator) is a valid argument for the session factory method.
Authenticator authenticator = null;
Expand Down

0 comments on commit 36d78fd

Please sign in to comment.