You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/07/24 19:02:29 UTC
svn commit: r425118 - in /james/server/trunk: ./ lib/ src/conf/
src/java/org/apache/james/smtpserver/core/filter/fastfail/
src/test/org/apache/james/smtpserver/
Author: norman
Date: Mon Jul 24 10:02:28 2006
New Revision: 425118
URL: http://svn.apache.org/viewvc?rev=425118&view=rev
Log:
Add new jSPF snapshot to support loggin via avalon
Remove not longer needed log4j jar
Added:
james/server/trunk/lib/jspf-0.9-SNAPSHOT.jar (with props)
Removed:
james/server/trunk/lib/jspf-0.9b1.jar
james/server/trunk/lib/log4j-1.2.13.jar
Modified:
james/server/trunk/build.xml
james/server/trunk/include.properties
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
Modified: james/server/trunk/build.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/build.xml?rev=425118&r1=425117&r2=425118&view=diff
==============================================================================
--- james/server/trunk/build.xml (original)
+++ james/server/trunk/build.xml Mon Jul 24 10:02:28 2006
@@ -91,7 +91,6 @@
<include name="${bcmail.jar}"/>
<include name="${bcmail-workaround.jar}"/>
<include name="${jspf.jar}"/>
- <include name="${log4j.jar}"/>
</fileset>
<pathelement path="${java.class.path}" />
<pathelement path="${build.classes}" />
@@ -530,7 +529,6 @@
<include name="${cornerstone-datasources-impl.jar}"/>
<include name="${concurrent.jar}"/>
<include name="${jspf.jar}"/>
- <include name="${log4j.jar}"/>
</lib>
<zipfileset dir="${conf.dir}" fullpath="conf/sqlResources.xml">
<include name="sqlResources.xml"/>
Modified: james/server/trunk/include.properties
URL: http://svn.apache.org/viewvc/james/server/trunk/include.properties?rev=425118&r1=425117&r2=425118&view=diff
==============================================================================
--- james/server/trunk/include.properties (original)
+++ james/server/trunk/include.properties Mon Jul 24 10:02:28 2006
@@ -92,9 +92,6 @@
bcmail-workaround.jar=bcmail-jdk14-129-workaround.jar
# ----- jSPF -----
-jspf.jar=jspf-0.9b1.jar
-
-# ----- Log4J-----
-log4j.jar=log4j-1.2.13.jar
+jspf.jar=jspf-0.9-SNAPSHOT.jar
Added: james/server/trunk/lib/jspf-0.9-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/james/server/trunk/lib/jspf-0.9-SNAPSHOT.jar?rev=425118&view=auto
==============================================================================
Binary file - no diff available.
Propchange: james/server/trunk/lib/jspf-0.9-SNAPSHOT.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?rev=425118&r1=425117&r2=425118&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Mon Jul 24 10:02:28 2006
@@ -949,8 +949,8 @@
<!-- If checkAuthNetworks is set to true sender domain will be checked also for clients that -->
<!-- are allowed to relay. Default is false. -->
<!--
- <handler class="org.apache.james.smtpserver.core.filter.fastfail" command="MAIL,RCPT">
- <checkAuthClients> false </checkAuthClients>
+ <handler class="org.apache.james.smtpserver.core.filter.fastfail.SPFHandler" command="MAIL,RCPT">
+ <checkAuthNetworks> false </checkAuthNetworks>
<blockSoftFail> false </blockSoftFail>
</handler>
-->
Modified: james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java?rev=425118&r1=425117&r2=425118&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/filter/fastfail/SPFHandler.java Mon Jul 24 10:02:28 2006
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -42,12 +43,13 @@
*
* Sample Configuration: <br>
* <br>
- * <handler class="org.apache.james.smtpserver.core.SPFHandler"
- * command="MAIL,RCPT"> <blockSoftFail>false</blockSoftFail>
+ * <handler class="org.apache.james.smtpserver.core.SPFHandler" command="MAIL,RCPT">
+ * <blockSoftFail>false</blockSoftFail>
+ * <checkAuthNetworks>false</checkAuthNetworks>
* </handler>
*/
public class SPFHandler extends AbstractLogEnabled implements CommandHandler,
- MessageHandler, Configurable {
+ MessageHandler, Configurable,Initializable {
public static final String SPF_BLOCKLISTED = "SPF_BLOCKLISTED";
@@ -68,6 +70,10 @@
private boolean checkAuthNetworks = false;
+ private SPF spf;
+
+
+
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
@@ -85,6 +91,18 @@
}
}
+
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ if (dnsService == null) {
+ spf = new SPF(new SPFLogger(getLogger()));
+ } else {
+ spf = new SPF(dnsService, new SPFLogger(getLogger()));
+ }
+ }
/**
* block the email on a softfail
@@ -144,8 +162,7 @@
// We have no Sender or HELO/EHLO yet return false
if (sender == null || heloEhlo == null) {
- getLogger().info("No Sender or HELO present");
- System.out.println("sender: " + sender + " helo: " + heloEhlo);
+ getLogger().info("No Sender or HELO/EHLO present");
} else {
// No checks for authorized cliends
if (session.isRelayingAllowed() && checkAuthNetworks == false) {
@@ -154,14 +171,7 @@
+ " is allowed to relay. Don't check it");
} else {
- SPF spf;
-
String ip = session.getRemoteIPAddress();
- if (dnsService == null) {
- spf = new SPF();
- } else {
- spf = new SPF(dnsService);
- }
SPFResult result = spf
.checkSPF(ip, sender.toString(), heloEhlo);
@@ -216,7 +226,7 @@
&& (recipientAddress.getUser().equalsIgnoreCase("postmaster")
|| recipientAddress.getUser().equalsIgnoreCase("abuse") || ((session
.isAuthRequired() && session.getUser() != null)))) {
- System.out.println("HERE2 " + blocklisted);
+
//remove invalid data
session.getState().remove(SPF_BLOCKLISTED);
session.getState().remove(SPF_DETAIL);
@@ -267,5 +277,134 @@
// Store the spf header as attribute for later using
mail.setAttribute(SPF_HEADER_MAIL_ATTRIBUTE_NAME, (String) session
.getState().get(SPF_HEADER));
+ }
+
+ /**
+ * Inner class to provide a wrapper for loggin to avalon
+ */
+ class SPFLogger implements org.apache.james.jspf.core.Logger {
+
+ /**
+ * Avalon Logger
+ */
+ org.apache.avalon.framework.logger.Logger logger;
+
+ SPFLogger(org.apache.avalon.framework.logger.Logger logger) {
+ this.logger = logger;
+ }
+
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#debug(String)
+ */
+ public void debug(String arg0) {
+ logger.debug(arg0);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#debug(String, Throwable)
+ */
+ public void debug(String arg0, Throwable arg1) {
+ logger.debug(arg0, arg1);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#error(String)
+ */
+ public void error(String arg0) {
+ logger.error(arg0);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#error(String, Throwable)
+ */
+ public void error(String arg0, Throwable arg1) {
+ logger.error(arg0, arg1);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#fatalError(String)
+ */
+ public void fatalError(String arg0) {
+ logger.fatalError(arg0);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#fatalError(String, Throwable)
+ */
+ public void fatalError(String arg0, Throwable arg1) {
+ logger.fatalError(arg0, arg1);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#info(String)
+ */
+ public void info(String arg0) {
+ logger.info(arg0);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#info(String, Throwable)
+ */
+ public void info(String arg0, Throwable arg1) {
+ logger.info(arg0, arg1);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#isDebugEnabled()
+ */
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#isErrorEnabled()
+ */
+ public boolean isErrorEnabled() {
+ return logger.isErrorEnabled();
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#isFatalErrorEnabled()
+ */
+ public boolean isFatalErrorEnabled() {
+ return logger.isFatalErrorEnabled();
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#isInfoEnabled()
+ */
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#isWarnEnabled()
+ */
+ public boolean isWarnEnabled() {
+ return logger.isWarnEnabled();
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#warn(String)
+ */
+ public void warn(String arg0) {
+ logger.warn(arg0);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#warn(String, Throwable)
+ */
+ public void warn(String arg0, Throwable arg1) {
+ logger.warn(arg0, arg1);
+ }
+
+ /**
+ * @see org.apache.james.jspf.core.Logger#getChildLogger(String)
+ */
+ public org.apache.james.jspf.core.Logger getChildLogger(String arg0) {
+ return new SPFLogger(logger.getChildLogger(arg0));
+ }
+
}
}
Modified: james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java?rev=425118&r1=425117&r2=425118&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/SPFHandlerTest.java Mon Jul 24 10:02:28 2006
@@ -24,8 +24,6 @@
import java.util.List;
-import javax.mail.internet.ParseException;
-
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.james.jspf.core.DNSService;
import org.apache.james.jspf.exceptions.NoneException;
@@ -313,15 +311,18 @@
spf.onMessage(mockedSMTPSession);
}
- public void testSPFpass() throws ParseException {
+ public void testSPFpass() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf1.james.apache.org",
new MailAddress("test@spf1.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
- ContainerUtil.enableLogging(spf, new MockLogger());
+ ContainerUtil.enableLogging(spf, new MockLogger());
+
spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
runHandlers(spf, mockedSMTPSession);
@@ -339,15 +340,17 @@
assertFalse(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFfail() throws ParseException {
+ public void testSPFfail() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf2.james.apache.org",
new MailAddress("test@spf2.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
-
- spf.setDNSService(mockedDnsService);
+
+ spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
runHandlers(spf, mockedSMTPSession);
@@ -362,15 +365,17 @@
assertTrue(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFsoftFail() throws ParseException {
+ public void testSPFsoftFail() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
new MailAddress("test@spf3.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
-
+
spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
runHandlers(spf, mockedSMTPSession);
@@ -388,15 +393,18 @@
assertFalse(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFsoftFailRejectEnabled() throws ParseException {
+ public void testSPFsoftFailRejectEnabled() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf3.james.apache.org",
new MailAddress("test@spf3.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
-
+
spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
+
spf.setBlockSoftFail(true);
setCommand("MAIL");
@@ -416,15 +424,18 @@
assertTrue(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFpermError() throws ParseException {
+ public void testSPFpermError() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
new MailAddress("test@spf4.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
-
+
spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
+
spf.setBlockSoftFail(true);
runHandlers(spf, mockedSMTPSession);
@@ -440,16 +451,18 @@
assertTrue(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFtempError() throws ParseException {
+ public void testSPFtempError() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf5.james.apache.org",
new MailAddress("test@spf5.james.apache.org"), new MailAddress(
"test@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
-
+
spf.setDNSService(mockedDnsService);
+ spf.initialize();
+
runHandlers(spf, mockedSMTPSession);
assertNull("no reject", mockedSMTPSession.getState().get(
@@ -463,7 +476,7 @@
assertTrue(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFNoRecord() throws ParseException {
+ public void testSPFNoRecord() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf6.james.apache.org",
new MailAddress("test@spf6.james.apache.org"), new MailAddress(
"test@localhost"));
@@ -473,6 +486,8 @@
spf.setDNSService(mockedDnsService);
+ spf.initialize();
+
runHandlers(spf, mockedSMTPSession);
assertNull("no reject", mockedSMTPSession.getState().get(
@@ -489,7 +504,7 @@
assertFalse(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFpermErrorNotRejectPostmaster() throws ParseException {
+ public void testSPFpermErrorNotRejectPostmaster() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
new MailAddress("test@spf4.james.apache.org"), new MailAddress(
"postmaster@localhost"));
@@ -498,6 +513,9 @@
ContainerUtil.enableLogging(spf, new MockLogger());
spf.setDNSService(mockedDnsService);
+
+ spf.initialize();
+
spf.setBlockSoftFail(true);
runHandlers(spf, mockedSMTPSession);
@@ -513,13 +531,15 @@
assertFalse(mockedSMTPSession.getStopHandlerProcessing());
}
- public void testSPFpermErrorNotRejectAbuse() throws ParseException {
+ public void testSPFpermErrorNotRejectAbuse() throws Exception {
setupMockedSMTPSession("192.168.100.1", "spf4.james.apache.org",
new MailAddress("test@spf4.james.apache.org"), new MailAddress(
"abuse@localhost"));
SPFHandler spf = new SPFHandler();
ContainerUtil.enableLogging(spf, new MockLogger());
+
+ spf.initialize();
spf.setDNSService(mockedDnsService);
spf.setBlockSoftFail(true);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org