vincenzo 2003/07/17 06:57:48
Modified: src/java/org/apache/james/smtpserver SMTPHandler.java
Added: src/java/org/apache/james/transport/matchers
SMTPAuthSuccessful.java SMTPAuthUserIs.java
Log:
Adding support to check for successful authentication of users if SMTP AUTH is
active.
Revision Changes Path
1.52 +9 -1
james-server/src/java/org/apache/james/smtpserver/SMTPHandler.java
Index: SMTPHandler.java
===================================================================
RCS file:
/home/cvs/james-server/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- SMTPHandler.java 4 Jun 2003 23:20:35 -0000 1.51
+++ SMTPHandler.java 17 Jul 2003 13:57:48 -0000 1.52
@@ -216,6 +216,11 @@
private final static String MAIL_OPTION_SIZE = "SIZE";
/**
+ * The mail attribute holding the SMTP AUTH user name, if any.
+ */
+ private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME =
"org.apache.james.SMTPAuthUser";
+
+ /**
* The thread executing this handler
*/
private Thread handlerThread;
@@ -1451,6 +1456,9 @@
}
mail.setRemoteHost(remoteHost);
mail.setRemoteAddr(remoteIP);
+ if (getUser() != null) {
+ mail.setAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME, getUser());
+ }
theConfigData.getMailServer().sendMail(mail);
Collection theRecipients = mail.getRecipients();
String recipientString = "";
1.1
james-server/src/java/org/apache/james/transport/matchers/SMTPAuthSuccessful.java
Index: SMTPAuthSuccessful.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
package org.apache.james.transport.matchers;
import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import java.util.Collection;
import java.util.StringTokenizer;
/**
* <P>Matches mails that are sent by an SMTP authenticated user.</P>
* <P>If the sender was not authenticated it will not match.</P>
* <PRE><CODE>
* <mailet match="SMTPAuthPassed"
class="<any-class>">
* </CODE></PRE>
*
* @version CVS $Revision: 1.1 $ $Date: 2003/07/17 13:57:48 $
* @since 2.2.0
*/
public class SMTPAuthSuccessful extends GenericMatcher {
/**
* The mail attribute holding the SMTP AUTH user name, if any.
*/
private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME =
"org.apache.james.SMTPAuthUser";
public Collection match(Mail mail) {
String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
if (authUser != null) {
return mail.getRecipients();
} else {
return null;
}
}
}
1.1
james-server/src/java/org/apache/james/transport/matchers/SMTPAuthUserIs.java
Index: SMTPAuthUserIs.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache", "Jakarta", "JAMES" and "Apache Software Foundation"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
package org.apache.james.transport.matchers;
import org.apache.mailet.GenericMatcher;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import java.util.Collection;
import java.util.StringTokenizer;
/**
* <P>Matches mails that are sent by an SMTP authenticated user present in a
supplied list.</P>
* <P>If the sender was not authenticated it will not match.</P>
* <P>Configuration string: a comma, tab or space separated list of James users.</P>
* <PRE><CODE>
* <mailet match="SMTPAuthUserIs=<list-of-user-names>"
class="<any-class>">
* </CODE></PRE>
*
* @version CVS $Revision: 1.1 $ $Date: 2003/07/17 13:57:48 $
* @since 2.2.0
*/
public class SMTPAuthUserIs extends GenericMatcher {
/**
* The mail attribute holding the SMTP AUTH user name, if any.
*/
private final static String SMTP_AUTH_USER_ATTRIBUTE_NAME =
"org.apache.james.SMTPAuthUser";
private Collection users;
public void init() throws javax.mail.MessagingException {
StringTokenizer st = new StringTokenizer(getCondition(), ", \t", false);
users = new java.util.HashSet();
while (st.hasMoreTokens()) {
users.add(new MailAddress(st.nextToken()));
}
}
public Collection match(Mail mail) {
String authUser = (String) mail.getAttribute(SMTP_AUTH_USER_ATTRIBUTE_NAME);
if (authUser != null && users.contains(authUser)) {
return mail.getRecipients();
} else {
return null;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]