james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r452248 - in /james/jspf/trunk/src/main/java/org/apache/james/jspf: ./ core/ localpolicy/ localpolicy/terms/ terms/
Date Mon, 02 Oct 2006 22:37:06 GMT
Author: norman
Date: Mon Oct  2 15:37:04 2006
New Revision: 452248

URL: http://svn.apache.org/viewvc?view=rev&rev=452248
Log:
Add support for trusted-forwarder.org. See JSPF-30

Added:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/
    james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/FallbackPolicy.java
      - copied, changed from r451863, james/jspf/trunk/src/main/java/org/apache/james/jspf/core/FallbackPolicy.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java
  (with props)
    james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/
    james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java
  (with props)
Removed:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/FallbackPolicy.java
Modified:
    james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
    james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java?view=diff&rev=452248&r1=452247&r2=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/SPF.java Mon Oct  2 15:37:04 2006
@@ -22,7 +22,6 @@
 
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Directive;
-import org.apache.james.jspf.core.FallbackPolicy;
 import org.apache.james.jspf.core.Logger;
 import org.apache.james.jspf.core.Modifier;
 import org.apache.james.jspf.core.SPF1Constants;
@@ -32,6 +31,8 @@
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
 import org.apache.james.jspf.exceptions.TempErrorException;
+import org.apache.james.jspf.localpolicy.FallbackPolicy;
+import org.apache.james.jspf.localpolicy.TrustedForwarderPolicy;
 import org.apache.james.jspf.macro.MacroExpand;
 import org.apache.james.jspf.parser.SPF1Parser;
 
@@ -56,6 +57,8 @@
     private boolean useBestGuess = false;
 
     private FallbackPolicy fallBack;
+
+    private boolean useTrustedForwarder = false;
     
     /**
      * Uses default Log4JLogger and DNSJava based dns resolver
@@ -199,9 +202,15 @@
 
         String qualifier = null;
         boolean hasCommand = false;
-
-        // get all commands
-        Iterator com = spfRecord.getDirectives().iterator();
+        Iterator com = null;
+        
+        // trustedForwarder support is enabled
+        if (useTrustedForwarder) {
+            com = new TrustedForwarderPolicy(spfRecord.getDirectives(),log).getUpdatedDirectives().iterator();
+        } else {
+            // get all commands
+            com = spfRecord.getDirectives().iterator();
+        }
         while (com.hasNext()) {
 
             // if we reach maximum calls we must throw a PermErrorException. See
@@ -405,5 +414,17 @@
      */
     public FallbackPolicy getFallbackPolicy() {
         return fallBack;
+    }
+    
+    /**
+     * Set to true to enable trusted-forwarder.org whitelist. The whitelist will only be
queried if
+     * the last Mechanism is -all or ?all. 
+     * See http://trusted-forwarder.org for more informations
+     * Default is false.
+     * 
+     * @param useTrustedForwarder true or false
+     */
+    public synchronized void useTrustedForwarder(boolean useTrustedForwarder) {
+        this.useTrustedForwarder = useTrustedForwarder;
     }
 }

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java?view=diff&rev=452248&r1=452247&r2=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/core/Directive.java Mon Oct  2 15:37:04
2006
@@ -87,5 +87,9 @@
     public String getQualifier() {
         return qualifier;
     }
+    
+    public String toString() {
+        return qualifier + mechanism;
+    }
 
 }

Copied: james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/FallbackPolicy.java
(from r451863, james/jspf/trunk/src/main/java/org/apache/james/jspf/core/FallbackPolicy.java)
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/FallbackPolicy.java?view=diff&rev=452248&p1=james/jspf/trunk/src/main/java/org/apache/james/jspf/core/FallbackPolicy.java&r1=451863&p2=james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/FallbackPolicy.java&r2=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/core/FallbackPolicy.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/FallbackPolicy.java Mon
Oct  2 15:37:04 2006
@@ -17,13 +17,15 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.jspf.core;
+package org.apache.james.jspf.localpolicy;
 
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.apache.james.jspf.core.Logger;
+import org.apache.james.jspf.core.SPF1Record;
 import org.apache.james.jspf.exceptions.NeutralException;
 import org.apache.james.jspf.exceptions.NoneException;
 import org.apache.james.jspf.exceptions.PermErrorException;
@@ -40,7 +42,7 @@
 
     private Logger log;
 
-    public FallbackPolicy(Logger log) {
+    public FallbackPolicy(Logger log){
         this.log = log;
         fallBackMap = Collections.synchronizedMap(new HashMap());
         parser = new SPF1Parser(log);

Added: james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java?view=auto&rev=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java
(added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java
Mon Oct  2 15:37:04 2006
@@ -0,0 +1,88 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.jspf.localpolicy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.james.jspf.core.Directive;
+import org.apache.james.jspf.exceptions.PermErrorException;
+import org.apache.james.jspf.localpolicy.terms.TrustedForwarderMechanism;
+import org.apache.james.jspf.core.Logger;
+
+/**
+ * 
+ * This class represent a local policy to support the whitelist of trusted-forwarder.org
+ */
+public class TrustedForwarderPolicy {
+
+    /**
+     * The hostname to include
+     */
+    private static final String TRUSTED_FORWARDER_HOST = "spf.trusted-forwarder.org";
+    
+    /**
+     * The ArrayList whill holds the Directives to return
+     */
+    private ArrayList aCom;
+    
+    /**
+     * The logger
+     */
+    private Logger log;
+    
+    /**
+     * Default Constructor 
+     * 
+     * @param directives the Collection which holds all directives
+     * @parm log the logger the logger
+     * @throws IllegalArgumentException get thrown if the given Collection is null
+     */
+    public TrustedForwarderPolicy (Collection directives,Logger log)throws IllegalArgumentException
{
+        if (directives == null) throw new IllegalArgumentException("Passed Collection is
null");
+        this.aCom = new ArrayList(directives);
+        this.log = log;
+    }
+
+    /**
+     * Return an updated Collection which hold now a new include mechanism to quere trusted-forwarder.org.
The
+     * Collection get only updated if the last mechanism is -all or ?all. If not the original
Collection is returned
+     * 
+     * @return aCom a Collection which holds the directives
+     */
+    public Collection getUpdatedDirectives() {
+        String mechanism = ((Directive) aCom.get(aCom.size())).toString();
+        if (mechanism.equals("-all") || mechanism.equals("?all")) {
+            log.debug("Add TrustedForwarderPolicy = include:"+TRUSTED_FORWARDER_HOST);
+            try {
+                TrustedForwarderMechanism trusted = new TrustedForwarderMechanism();
+                trusted.setHost(TRUSTED_FORWARDER_HOST);
+                aCom.add(aCom.size()-1, new Directive(null,trusted));
+            } catch (PermErrorException e) {
+                // will never happen
+            }
+            return aCom;
+        } else {
+            return aCom;
+        }
+    }
+}

Propchange: james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/TrustedForwarderPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java?view=auto&rev=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java
(added)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java
Mon Oct  2 15:37:04 2006
@@ -0,0 +1,40 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.jspf.localpolicy.terms;
+
+import org.apache.james.jspf.terms.IncludeMechanism;
+
+/**
+ * Costum mechanism to support whitelist trusted-forwarder.org
+ *
+ */
+public class TrustedForwarderMechanism extends IncludeMechanism {
+    
+    /**
+     * Set the host to use 
+     * 
+     * @param host the host to include
+     */
+    public synchronized void setHost(String host) {
+        this.host = host;
+    }
+
+}

Propchange: james/jspf/trunk/src/main/java/org/apache/james/jspf/localpolicy/terms/TrustedForwarderMechanism.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java?view=diff&rev=452248&r1=452247&r2=452248
==============================================================================
--- james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java (original)
+++ james/jspf/trunk/src/main/java/org/apache/james/jspf/terms/IncludeMechanism.java Mon Oct
 2 15:37:04 2006
@@ -47,9 +47,9 @@
     public static final String REGEX = "[iI][nN][cC][lL][uU][dD][eE]" + "\\:"
             + SPF1Parser.DOMAIN_SPEC_REGEX;
 
-    private String host;
+    protected String host;
     
-    private Logger log;
+    protected Logger log;
 
     /**
      * Set the host which should be used for include



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message