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 2003/05/21 06:17:26 UTC
cvs commit: jakarta-james/src/java/org/apache/james/smtpserver SMTPHandler.java SMTPHandlerConfigurationData.java SMTPServer.java
noel 2003/05/20 21:17:26
Modified: src/java/org/apache/james/smtpserver Tag: branch_2_1_fcs
SMTPHandler.java SMTPHandlerConfigurationData.java
SMTPServer.java
Log:
Add the ability to authorize networks using a new <authorizedAddresses> element. SMTP AUTH can be enabled generally, and then disabled for authorized networks.
Revision Changes Path
No revision
No revision
1.35.4.10 +6 -6 jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
Index: SMTPHandler.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
retrieving revision 1.35.4.9
retrieving revision 1.35.4.10
diff -u -r1.35.4.9 -r1.35.4.10
--- SMTPHandler.java 26 Mar 2003 06:31:16 -0000 1.35.4.9
+++ SMTPHandler.java 21 May 2003 04:17:25 -0000 1.35.4.10
@@ -638,7 +638,7 @@
} else {
resetState();
state.put(CURRENT_HELO_MODE, COMMAND_HELO);
- if (theConfigData.isAuthRequired()) {
+ if (theConfigData.isAuthRequired(remoteIP)) {
//This is necessary because we're going to do a multiline response
responseBuffer.append("250-");
} else {
@@ -653,7 +653,7 @@
.append(remoteIP)
.append("])");
responseString = clearResponseBuffer();
- if (theConfigData.isAuthRequired()) {
+ if (theConfigData.isAuthRequired(remoteIP)) {
writeLoggedResponse(responseString);
responseString = "250-AUTH LOGIN PLAIN";
writeLoggedResponse(responseString);
@@ -684,7 +684,7 @@
responseString = "250-SIZE " + maxMessageSize;
writeLoggedResponse(responseString);
}
- if (theConfigData.isAuthRequired()) {
+ if (theConfigData.isAuthRequired(remoteIP)) {
//This is necessary because we're going to do a multiline response
responseBuffer.append("250-");
} else {
@@ -699,7 +699,7 @@
.append(remoteIP)
.append("])");
responseString = clearResponseBuffer();
- if (theConfigData.isAuthRequired()) {
+ if (theConfigData.isAuthRequired(remoteIP)) {
writeLoggedResponse(responseString);
responseString = "250-AUTH LOGIN PLAIN";
writeLoggedResponse(responseString);
@@ -1129,7 +1129,7 @@
}
return;
}
- if (theConfigData.isAuthRequired()) {
+ if (theConfigData.isAuthRequired(remoteIP)) {
// Make sure the mail is being sent locally if not
// authenticated else reject.
if (getUser() == null) {
1.1.4.3 +8 -2 jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java
Index: SMTPHandlerConfigurationData.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandlerConfigurationData.java,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -r1.1.4.2 -r1.1.4.3
--- SMTPHandlerConfigurationData.java 8 Mar 2003 21:54:07 -0000 1.1.4.2
+++ SMTPHandlerConfigurationData.java 21 May 2003 04:17:25 -0000 1.1.4.3
@@ -65,7 +65,6 @@
* Provides a number of server-wide constant values to the
* SMTPHandlers
*
- * @author Peter M. Goldstein <fa...@alum.mit.edu>
*/
public interface SMTPHandlerConfigurationData {
@@ -91,6 +90,14 @@
long getMaxMessageSize();
/**
+ * Returns whether SMTP AUTH is active for this server, and
+ * necessary for the IP address passed.
+ *
+ * @return whether SMTP authentication is on
+ */
+ boolean isAuthRequired(String remoteIP);
+
+ /**
* Returns whether SMTP auth is active for this server.
*
* @return whether SMTP authentication is on
@@ -118,5 +125,4 @@
* @return the local users repository
*/
UsersRepository getUsersRepository();
-
}
1.17.4.3 +31 -5 jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java
Index: SMTPServer.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
retrieving revision 1.17.4.2
retrieving revision 1.17.4.3
diff -u -r1.17.4.2 -r1.17.4.3
--- SMTPServer.java 8 Mar 2003 21:54:07 -0000 1.17.4.2
+++ SMTPServer.java 21 May 2003 04:17:25 -0000 1.17.4.3
@@ -78,23 +78,20 @@
import org.apache.james.services.MailServer;
import org.apache.james.services.UsersRepository;
import org.apache.james.services.UsersStore;
+import org.apache.james.util.NetMatcher;
import org.apache.james.util.watchdog.Watchdog;
import org.apache.james.util.watchdog.WatchdogFactory;
import org.apache.james.util.watchdog.WatchdogTarget;
import org.apache.mailet.MailetContext;
import java.net.InetAddress;
import java.net.UnknownHostException;
+
/**
* <p>Accepts SMTP connections on a server socket and dispatches them to SMTPHandlers.</p>
*
* <p>Also responsible for loading and parsing SMTP specific configuration.</p>
*
* @version 1.1.0, 06/02/2001
- * @author Federico Barbieri <sc...@pop.systemy.it>
- * @author Matthew Pangaro <ma...@lokitech.com>
- * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
- * @author <a href="mailto:danny@apache.org">Danny Angus</a>
- * @author Peter M. Goldstein <fa...@alum.mit.edu>
*/
/*
* IMPORTANT: SMTPServer extends AbstractJamesService. If you implement ANY
@@ -133,6 +130,12 @@
private boolean verifyIdentity = false;
/**
+ * This is a Network Matcher that should be configured to contain
+ * authorized networks that bypass SMTP AUTH requirements.
+ */
+ private NetMatcher authorizedNetworks = null;
+
+ /**
* The maximum message size allowed by this SMTP server. The default
* value, 0, means no limit.
*/
@@ -200,6 +203,18 @@
} else {
getLogger().info("This SMTP server does not require authentication.");
}
+
+ String authorizedAddresses = handlerConfiguration.getChild("authorizedAddresses").getValue(null);
+ if (authorizedAddresses != null) {
+ java.util.StringTokenizer st = new java.util.StringTokenizer(authorizedAddresses, ", ", false);
+ java.util.Collection networks = new java.util.ArrayList();
+ while (st.hasMoreTokens()) {
+ String addr = st.nextToken();
+ networks.add(addr);
+ }
+ authorizedNetworks = new NetMatcher(networks);
+ }
+
// get the message size limit from the conf file and multiply
// by 1024, to put it in bytes
maxMessageSize = handlerConfiguration.getChild( "maxmessagesize" ).getValueAsLong( maxMessageSize ) * 1024;
@@ -349,6 +364,17 @@
*/
public long getMaxMessageSize() {
return SMTPServer.this.maxMessageSize;
+ }
+
+ /**
+ * @see org.apache.james.smtpserver.SMTPHandlerConfigurationData#isAuthRequired()
+ */
+ public boolean isAuthRequired(String remoteIP) {
+ boolean authRequired = SMTPServer.this.authRequired;
+ if (authorizedNetworks != null) {
+ authRequired = authRequired && SMTPServer.this.authorizedNetworks.matchInetNetwork(remoteIP);
+ }
+ return authRequired;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org