Skip to content

Commit

Permalink
Release 3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
autumoswitzerland committed Nov 11, 2024
1 parent 5ae76ce commit df5b192
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 28 deletions.
2 changes: 1 addition & 1 deletion THIRDPARTYLICENSES.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<body>
<h1>Third Party Licenses</h1>
<div class="htitle">
<span class="htitle0">autumo beetRoot 3.1.2 </span><span class="htitled"> &#x2022; </span><span class="htitle1"> A slim &amp; rapid Java web-dev framework</span><br>
<span class="htitle0">autumo beetRoot 3.1.3 </span><span class="htitled"> &#x2022; </span><span class="htitle1"> A slim &amp; rapid Java web-dev framework</span><br>
</div>
<span class="header">&copy; 2024 <a class="comp" href="https://autumo.ch">autumo GmbH</a></span><br>
<span class="header">Date: 2024-11-05</span><br>
Expand Down
5 changes: 2 additions & 3 deletions etc/pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
<version.maven.resources.plugin>3.3.1</version.maven.resources.plugin>
<version.maven.surefire.plugin>3.0.0-M5</version.maven.surefire.plugin>

<version.autumo.beetroot>3.1.2</version.autumo.beetroot>
<version.nanohttpd>BEETROOT-2.3.5</version.nanohttpd
>
<version.autumo.beetroot>3.1.3</version.autumo.beetroot>
<version.nanohttpd>BEETROOT-2.3.5</version.nanohttpd>
<version.hikaricp>6.0.0</version.hikaricp>
<version.jcolor>5.5.1</version.jcolor>
<version.angus.activation>2.0.2</version.angus.activation>
Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


# Vars
VERSION=3.1.2
VERSION=3.1.3
SLF4J_SIMPLE_VERSION=1.7.36
LOG4J_WEB_VERSION=2.24.1

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<name>autumo-beetroot</name>
<groupId>ch.autumo.beetroot</groupId>
<artifactId>autumo-beetroot</artifactId>
<version>3.1.2</version>
<version>3.1.3</version>
<packaging>jar</packaging>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public String getFullConfigBasePath() {
*
* @return file name
*/
public String getConfigFileNme() {
public String getConfigFileName() {
return cfgFileName;
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/ch/autumo/beetroot/mailing/AbstractMailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public abstract class AbstractMailer implements Mailer {

private static final Logger LOG = LoggerFactory.getLogger(AbstractMailer.class.getName());

/** default SMTP port. */
public static final int DEFAULT_SMTP_PORT = 25;

/** Mail formats. */
protected String mailformats[] = null;
/** Mail authentication? */
Expand Down Expand Up @@ -96,8 +99,8 @@ protected Properties initialize() throws Exception {
if (port < 0) {
port = BeetRootConfigurationManager.getInstance().getInt("mail_port");
if (port == -1) {
LOG.warn("Using mail port 25.");
port = 25;
LOG.warn("Using mail port {}.", DEFAULT_SMTP_PORT);
port = DEFAULT_SMTP_PORT;
}
}
host = BeetRootDatabaseManager.getInstance().getProperty("mail.host");
Expand Down Expand Up @@ -235,7 +238,7 @@ protected String replaceAllLanguageVariables(String template, BeetRootHTTPSessio
final int pos1 = idx + BaseHandler.TAG_PREFIX_LANG.length();
final int pos2 = template.indexOf("}", idx + BaseHandler.TAG_PREFIX_LANG.length());
int posC = template.indexOf(",", idx + BaseHandler.TAG_PREFIX_LANG.length());
// if a comma is found outside the tag it refers not ro a replace variable!
// if a comma is found outside the tag it refers not to a replace variable!
if (posC > pos2)
posC = -1;
String totrans = null;
Expand Down
80 changes: 71 additions & 9 deletions src/main/java/ch/autumo/beetroot/mailing/JakartaMailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;
Expand All @@ -36,6 +37,7 @@
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
import jakarta.mail.Transport;
import jakarta.mail.URLName;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMessage;
Expand Down Expand Up @@ -79,17 +81,73 @@ protected PasswordAuthentication getPasswordAuthentication() {
}

/**
* Lookup JNDI context.
*
* @param jndiContextName JNDI context name (or mail session name)
* @return mail session
* @throws Exception
* Looks up the JNDI mail session context.
*
* @param jndiContextName the JNDI context name (or mail session name)
* @return the mail session, configured with fallback credentials if needed
* @throws NamingException if the JNDI lookup fails
* @throws NumberFormatException if the port property is invalid
*/
private Session lookupJndiMailSession(String jndiContextName) throws Exception {
// We still load properties from default configuration, because we still need some value, e.g., 'from'
// We still load properties from default configuration,
// because we still need some value, e.g., 'from'
// and possibly credentials
super.initialize();
final InitialContext ic = new InitialContext();
return (Session) ic.lookup(jndiContextName);
Session session = null;
try {
// Retrieve the JNDI Mail Session
final InitialContext ic = new InitialContext();
session = (Session) ic.lookup(jndiContextName);
if (session == null) {
throw new NamingException("Mail session not found in JNDI context: " + jndiContextName);
}
final Properties jndiProps = session.getProperties();
if (Boolean.parseBoolean(jndiProps.getProperty("mail.smtp.auth", "false"))) {
configureAuthentication(session, jndiProps);
}
} catch (NamingException e) {
LOG.error("Failed to look up JNDI context '{}': {}", jndiContextName, e.getMessage(), e);
throw e;
} catch (NumberFormatException e) {
LOG.error("Invalid port format in JNDI properties for '{}': {}", jndiContextName, e.getMessage(), e);
throw e;
}
return session;
}

/**
* Configures SMTP authentication for the mail session if JNDI credentials are incomplete.
*
* @param session the JNDI mail session
* @param jndiProps the JNDI mail session properties
* @throws NamingException if SMTP host is missing
*/
private void configureAuthentication(Session session, Properties jndiProps) throws NamingException {
final String smtpHost = jndiProps.getProperty("mail.smtp.host");
if (smtpHost == null) {
throw new NamingException("SMTP host property is missing in JNDI properties.");
}
String jndiUsername = jndiProps.getProperty("mail.smtp.user");
String jndiPassword = jndiProps.getProperty("mail.smtp.password");
if (jndiUsername == null || jndiPassword == null) {
LOG.info("Falling back to external configuration for SMTP credentials.");
session.setPasswordAuthentication(
new URLName(
"smtp",
smtpHost,
Integer.parseInt(jndiProps.getProperty("mail.smtp.port", String.valueOf(DEFAULT_SMTP_PORT))),
null,
user,
password
),
new PasswordAuthentication(user, password)
);
} else {
LOG.warn(
"SMTP credentials found in JNDI context. For enhanced security, define them externally: '{}'.",
BeetRootConfigurationManager.getInstance().getConfigFileName()
);
}
}

/**
Expand Down Expand Up @@ -143,7 +201,11 @@ public void mail(String to[], String subject, Map<String, String> variables, Str
} else {
// JNDI mail session
mailSession = this.lookupJndiMailSession(jndiName);
LOG.info("External Mail-session (JNDI) '{}' has been configured from configuration file '{}'.", jndiName, BeetRootConfigurationManager.getInstance().getConfigFileNme());
LOG.info(
"External Mail-session (JNDI) '{}' has been configured from configuration file '{}'.",
jndiName,
BeetRootConfigurationManager.getInstance().getConfigFileName()
);
}
} else {
// Retrieve session name from database and create JNDI context
Expand Down
76 changes: 67 additions & 9 deletions src/main/java/ch/autumo/beetroot/mailing/JavaxMailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -79,17 +81,73 @@ protected PasswordAuthentication getPasswordAuthentication() {
}

/**
* Lookup JNDI context.
*
* @param jndiContextName JNDI context name (or mail session name)
* @return mail session
* @throws Exception
* Looks up the JNDI mail session context.
*
* @param jndiContextName the JNDI context name (or mail session name)
* @return the mail session, configured with fallback credentials if needed
* @throws NamingException if the JNDI lookup fails
* @throws NumberFormatException if the port property is invalid
*/
private Session lookupJndiMailSession(String jndiContextName) throws Exception {
// We still load properties from default configuration, because we still need some value, e.g., 'from'
// We still load properties from default configuration,
// because we still need some value, e.g., 'from'
// and possibly credentials
super.initialize();
final InitialContext ic = new InitialContext();
return (Session) ic.lookup(jndiContextName);
Session session = null;
try {
// Retrieve the JNDI Mail Session
final InitialContext ic = new InitialContext();
session = (Session) ic.lookup(jndiContextName);
if (session == null) {
throw new NamingException("Mail session not found in JNDI context: " + jndiContextName);
}
final Properties jndiProps = session.getProperties();
if (Boolean.parseBoolean(jndiProps.getProperty("mail.smtp.auth", "false"))) {
configureAuthentication(session, jndiProps);
}
} catch (NamingException e) {
LOG.error("Failed to look up JNDI context '{}': {}", jndiContextName, e.getMessage(), e);
throw e;
} catch (NumberFormatException e) {
LOG.error("Invalid port format in JNDI properties for '{}': {}", jndiContextName, e.getMessage(), e);
throw e;
}
return session;
}

/**
* Configures SMTP authentication for the mail session if JNDI credentials are incomplete.
*
* @param session the JNDI mail session
* @param jndiProps the JNDI mail session properties
* @throws NamingException if SMTP host is missing
*/
private void configureAuthentication(Session session, Properties jndiProps) throws NamingException {
final String smtpHost = jndiProps.getProperty("mail.smtp.host");
if (smtpHost == null) {
throw new NamingException("SMTP host property is missing in JNDI properties.");
}
String jndiUsername = jndiProps.getProperty("mail.smtp.user");
String jndiPassword = jndiProps.getProperty("mail.smtp.password");
if (jndiUsername == null || jndiPassword == null) {
LOG.info("Falling back to external configuration for SMTP credentials.");
session.setPasswordAuthentication(
new URLName(
"smtp",
smtpHost,
Integer.parseInt(jndiProps.getProperty("mail.smtp.port", String.valueOf(DEFAULT_SMTP_PORT))),
null,
user,
password
),
new PasswordAuthentication(user, password)
);
} else {
LOG.warn(
"SMTP credentials found in JNDI context. For enhanced security, define them externally: '{}'.",
BeetRootConfigurationManager.getInstance().getConfigFileName()
);
}
}

/**
Expand Down Expand Up @@ -143,7 +201,7 @@ public void mail(String[] to, String subject, Map<String, String> variables, Str
} else {
// JNDI mail session
mailSession = this.lookupJndiMailSession(jndiName);
LOG.info("External Mail-session (JNDI) '{}' has been configured from configuration file '{}'.", jndiName, BeetRootConfigurationManager.getInstance().getConfigFileNme());
LOG.info("External Mail-session (JNDI) '{}' has been configured from configuration file '{}'.", jndiName, BeetRootConfigurationManager.getInstance().getConfigFileName());
}
} else {
// Retrieve session name from database and create JNDI context
Expand Down

0 comments on commit df5b192

Please sign in to comment.