You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/01/08 06:23:10 UTC

svn commit: r897097 - in /incubator/jspwiki/trunk: ./ etc/ src/java/org/apache/wiki/ src/java/org/apache/wiki/content/inspect/ src/java/org/apache/wiki/filters/ src/java/org/apache/wiki/tags/ src/java/org/apache/wiki/ui/stripes/ tests/java/org/apache/w...

Author: ajaquith
Date: Fri Jan  8 05:22:52 2010
New Revision: 897097

URL: http://svn.apache.org/viewvc?rev=897097&view=rev
Log:
Minor renaming of a few content-inspection types and methods. Added default weights for the content inspectors to jspwiki.properties. Removed the listener code from the Inspection class. The code was good and it worked nicely, but it is no longer needed due to the way we integrate CAPTCHA now. We can always add listeners back if we have to, but in the meantime: a simpler API is a better API.

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionPlan.java
      - copied, changed from r896518, incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionFactory.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionPlanTest.java
      - copied, changed from r896518, incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionFactoryTest.java
Removed:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionInterruptedException.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionListener.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionFactory.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionFactoryTest.java
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/etc/jspwiki.properties
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/AsirraCaptcha.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Challenge.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Inspection.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionPlan.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SpamProtectTag.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/SpamInterceptor.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/AllTests.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/InspectionTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/SpamInterceptorTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Fri Jan  8 05:22:52 2010
@@ -1,3 +1,16 @@
+2010-01-08 Andrew Jaquith <ajaquith AT apache DOT org>
+
+        * 3.0.0-svn-197
+
+        * Minor renaming of a few content-inspection types
+        and methods. Added default weights for the content
+        inspectors to jspwiki.properties. Removed the listener
+        code from the Inspection class. The code was good
+        and it worked nicely, but it is no longer needed due
+        to the way we integrate CAPTCHA now. We can always
+        add listeners back if we have to, but in the
+        meantime: a simpler API is a better API.
+
 2010-01-06 Harry Metske <me...@apache.org>
 
         * 3.0.0-svn-196

Modified: incubator/jspwiki/trunk/etc/jspwiki.properties
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/etc/jspwiki.properties?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/etc/jspwiki.properties (original)
+++ incubator/jspwiki/trunk/etc/jspwiki.properties Fri Jan  8 05:22:52 2010
@@ -791,6 +791,22 @@
 # The CAPTCHA to use (default: Asirra)
 jspwiki.captcha.implementation = org.apache.wiki.content.inspect.AsirraCaptcha
 
+#  Content inspection
+#
+#  Spam threshold: anything below this value is considered spam.
+#  Spam scores start at 0.0.
+spamScoreLimit = -1.0
+
+# Weights for spam content inspectors: failure subtracts these weights
+inspectorWeight.spam.org.apache.wiki.content.inspect.AkismetInspector = 0.0
+inspectorWeight.spam.org.apache.wiki.content.inspect.BanListInspector = 1.0
+inspectorWeight.spam.org.apache.wiki.content.inspect.BotTrapInspector = 1.0
+inspectorWeight.spam.org.apache.wiki.content.inspect.ChangeRateInspector = 1.0
+inspectorWeight.spam.org.apache.wiki.content.inspect.LinkCountInspector = 1.0
+inspectorWeight.spam.org.apache.wiki.content.inspect.PatternInspector = 1.0
+
+# Weights for spam content inspectors: failure adds these weights
+inspectorWeight.spam.org.apache.wiki.content.inspect.UserInspectorInspector = 1.0
 
 ###########################################################################
 #

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Fri Jan  8 05:22:52 2010
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "196";
+    public static final String     BUILD         = "197";
 
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/AsirraCaptcha.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/AsirraCaptcha.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/AsirraCaptcha.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/AsirraCaptcha.java Fri Jan  8 05:22:52 2010
@@ -16,7 +16,6 @@
 import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.wiki.WikiContext;
 import org.apache.wiki.i18n.InternationalizationManager;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Challenge.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Challenge.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Challenge.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Challenge.java Fri Jan  8 05:22:52 2010
@@ -10,17 +10,14 @@
 /**
  * <p>
  * Describes how Challenge classes should implement scripting and processing
- * methods to test particular Challenge schemes, such as CAPTCHA.
- * </p>
- * <p>
- * Challenge specifies three logical states, which are invoked by a combination
- * of custom JSP tags and the {@link SpamInterceptor} interceptor.
+ * methods to test particular Challenge schemes, such as CAPTCHA. Implementing
+ * classes need to implement two methods:
  * </p>
  * <ol>
  * <li><strong>formContent</strong>. When a JSP containing a &lt;SpamProtect&gt;
  * tag is encountered, the {@link SpamProtectTag#doEndTag()} method calls
- * {@link #formContent(WikiActionBeanContext)} to generate any content needed to be
- * included in the &lt;form&gt; element of the page. Note that the
+ * {@link #formContent(WikiActionBeanContext)} to generate any content needed to
+ * be included in the &lt;form&gt; element of the page. Note that the
  * &lt;SpamProtect&gt tag is not actually guaranteed to be inside of the form
  * element, but in practice, it should be.</li>
  * <li><strong>check</strong>. This method provides any back-end Challenge
@@ -42,8 +39,9 @@
      * actually injected by the {@link SpamProtectTag} tag, when it is
      * encountered on the JSP.
      * 
-     * @param actionBeanContext the current ActionBeanContext. Callers can obtain the complete
-     *            request context by calling {@link net.sourceforge.stripes.action.ActionBeanContext#getRequest()}.
+     * @param actionBeanContext the current ActionBeanContext. Callers can
+     *            obtain the complete request context by calling
+     *            {@link net.sourceforge.stripes.action.ActionBeanContext#getRequest()}.
      * @return the form content
      */
     public String formContent( WikiActionBeanContext actionBeanContext ) throws IOException;
@@ -51,30 +49,39 @@
     /**
      * Tests the Challenge.
      * 
-     * @param actionBeanContext the current ActionBeanContext. Callers can obtain the complete
-     *            request context by calling {@link net.sourceforge.stripes.action.ActionBeanContext#getRequest()}.
+     * @param actionBeanContext the current ActionBeanContext. Callers can
+     *            obtain the complete request context by calling
+     *            {@link net.sourceforge.stripes.action.ActionBeanContext#getRequest()}.
      * @return {@code true} if the test succeeded; {@code false} otherwise
      */
     public boolean check( WikiActionBeanContext actionBeanContext ) throws IOException;
 
-    public enum Request
+    /**
+     * Represents what Challenge was presented to the user in the most recent
+     * HTTP response. {@link SpamProtectTag} writes the State out as an
+     * encrypted hidden form parameter.
+     */
+    public enum State
     {
         /**
-         * No challenge requested, but CAPTCHA should be generated if
-         * content-inspection determines that the ActionBean contains spam.
+         * No challenge was presented, but a CAPTCHA should be presented in
+         * the next response if the content inspector determines that
+         * the ActionBean contains spam. The state
+         * {@link #CHALLENGE_NOT_PRESENTED} occurs only when a form is
+         * presented for the first time.
          */
-        CAPTCHA_ON_DEMAND,
+        CHALLENGE_NOT_PRESENTED,
 
-        /** CAPTCHA was requested. */
-        CAPTCHA,
+        /** CAPTCHA was presented to the user. */
+        CAPTCHA_PRESENTED,
 
         /**
-         * Challenge parameter was omitted, possibly because a spammer submitted
-         * the request.
+         * Challenge parameter was omitted, probably because a spammer submitted
+         * the request without first requesting the form.
          */
-        OMITTED,
+        MISSING_STATE,
 
-        /** Password challenge was requested. */
-        PASSWORD
+        /** Password challenge was presented to the user. */
+        PASSWORD_PRESENTED
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Inspection.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Inspection.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Inspection.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/Inspection.java Fri Jan  8 05:22:52 2010
@@ -50,8 +50,6 @@
 
     private final WikiContext m_context;
 
-    private final Map<Topic, List<InspectionListener>> m_listeners;
-
     private final String m_uid;
 
     /**
@@ -71,29 +69,6 @@
         m_context = context;
         m_plan = plan;
         m_uid = getUniqueID();
-        m_listeners = new HashMap<Topic, List<InspectionListener>>();
-    }
-
-    /**
-     * Adds an InspectionListener for a supplied Topic. The listner object's
-     * {@link InspectionListener#changedScore(Inspection, Finding)} method will
-     * be called whenever an Inspector's
-     * {@link Inspector#inspect(Inspection, Change)} method returns a
-     * Finding whose Topic is equal to {@code topic}.
-     * 
-     * @param topic the Topic to listen for
-     * @param listener the listener that will respond to new Findings added for
-     *            this Topic
-     */
-    public void addListener( Topic topic, InspectionListener listener )
-    {
-        List<InspectionListener> listeners = m_listeners.get( topic );
-        if( listeners == null )
-        {
-            listeners = new ArrayList<InspectionListener>();
-            m_listeners.put( topic, listeners );
-        }
-        listeners.add( listener );
     }
 
     /**
@@ -183,40 +158,33 @@
         m_findings.clear();
         Inspector[] inspectors = m_plan.getInspectors();
 
-        try
+        // Execute the request-scoped inspectors
+        for( Inspector inspector : inspectors )
         {
-            // Execute the request-scoped inspectors
-            for( Inspector inspector : inspectors )
+            if( inspector.getScope() == Scope.REQUEST )
             {
-                if( inspector.getScope() == Scope.REQUEST )
-                {
-                    Finding[] findings = inspector.inspect( this, null );
-                    processFindings( inspector, findings );
-                }
+                Finding[] findings = inspector.inspect( this, null );
+                processFindings( inspector, findings );
             }
+        }
 
-            if( changes == null )
-            {
-                return;
-            }
+        if( changes == null )
+        {
+            return;
+        }
 
-            // Execute the field-scoped inspectors
-            for( Change change : changes )
+        // Execute the field-scoped inspectors
+        for( Change change : changes )
+        {
+            for( Inspector inspector : inspectors )
             {
-                for( Inspector inspector : inspectors )
+                if( inspector.getScope() == Scope.FIELD )
                 {
-                    if( inspector.getScope() == Scope.FIELD )
-                    {
-                        Finding[] findings = inspector.inspect( this, change );
-                        processFindings( inspector, findings );
-                    }
+                    Finding[] findings = inspector.inspect( this, change );
+                    processFindings( inspector, findings );
                 }
             }
         }
-        catch( InspectionInterruptedException e )
-        {
-            log.debug( "Inspection " + m_uid + " interrupted by " + e.getSource().getClass().getName() );
-        }
 
         // Add the changes to the ReputationManager's list of recent changes
         ReputationManager mgr = m_plan.getReputationManager();
@@ -249,9 +217,8 @@
      * Processes any Findings that result from an Inspector's processing
      * @param inspector the inspector that executed
      * @param findings the findings it produced
-     * @throws InspectionInterruptedException if any listeners interrupt processing
      */
-    private void processFindings( Inspector inspector, Finding[] findings ) throws InspectionInterruptedException
+    private void processFindings( Inspector inspector, Finding[] findings )
     {
         float weight = m_plan.getWeight( inspector );
         if( findings != null )
@@ -261,16 +228,6 @@
                 // Increase/decrease score here
                 Topic topic = finding.getTopic();
                 updateScore( topic, finding, weight );
-
-                // Notify any listeners that the score has changed
-                List<InspectionListener> listeners = m_listeners.get( topic );
-                if( listeners != null )
-                {
-                    for( InspectionListener listener : listeners )
-                    {
-                        listener.changedScore( this, finding );
-                    }
-                }
                 log( inspector, finding, weight );
             }
         }
@@ -285,6 +242,7 @@
     private void log( Inspector inspector, Finding finding, float weight )
     {
         String logMessage = finding.getMessage();
+        log.info( logMessage );
         logMessage = TextUtil.replaceString( logMessage, "\r\n", "\\r\\n" );
         logMessage = TextUtil.replaceString( logMessage, "\"", "\\\"" );
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionPlan.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionPlan.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionPlan.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/InspectionPlan.java Fri Jan  8 05:22:52 2010
@@ -9,13 +9,14 @@
 import org.apache.wiki.util.TextUtil;
 
 /**
- * A plan for inspection that defines the sequence of {@link Inspector} objects
+ * <p>A plan for inspection that defines the sequence of {@link Inspector} objects
  * for analyzing content. Inspector objects are added to the InspectionPlan by
  * calling {@link #addInspector(Inspector, float)} with a desired weight,
  * expressed as a floating-point number. The InspectionPlan includes convenience
  * methods for accessing WikiEngine properties to allow each Inspector to
  * initialize itself. References to shared-state objects such as the
- * {@link ReputationManager} are included for Inspectors to use.
+ * {@link ReputationManager} are included for Inspectors to use.</p>
+ * <p>The InspectionPlan class is not thread-safe. It may be extended.</p>
  */
 public class InspectionPlan
 {

Copied: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionPlan.java (from r896518, incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionFactory.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionPlan.java?p2=incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionPlan.java&p1=incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionFactory.java&r1=896518&r2=897097&rev=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionFactory.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/inspect/SpamInspectionPlan.java Fri Jan  8 05:22:52 2010
@@ -13,9 +13,9 @@
  * Factory for creating spam-related {@link Inspection} and
  * {@link InspectionPlan} objects.
  */
-public final class SpamInspectionFactory
+public final class SpamInspectionPlan extends InspectionPlan
 {
-    private static final Logger log = LoggerFactory.getLogger( SpamInspectionFactory.class );
+    private static final Logger log = LoggerFactory.getLogger( SpamInspectionPlan.class );
 
     protected static final String PROP_INSPECTOR_WEIGHT_PREFIX = "inspectorWeight.spam.";
 
@@ -25,44 +25,6 @@
      */
     public static final String PROP_SCORE_LIMIT = "spamScoreLimit";
 
-    private static class SpamListener implements InspectionListener
-    {
-        private final float m_limit;
-
-        public SpamListener( float limit )
-        {
-            super();
-            m_limit = limit;
-        }
-
-        public void changedScore( Inspection inspection, Finding finding ) throws InspectionInterruptedException
-        {
-            float currentScore = inspection.getScore( Topic.SPAM );
-            if( currentScore < m_limit )
-            {
-                throw new InspectionInterruptedException( this, "Limit reached." );
-            }
-        }
-    }
-
-    /**
-     * Causes an existing Inspection to interrupt when spam scores fall below a
-     * given limit. This is done by adding a private {@link InspectionListener}
-     * to the Inspection, whose only function is to listen for findings for
-     * {@link Topic#SPAM}. When the spam score goes below {@code limit}, the
-     * private listener throws an {@link InspectionInterruptedException} which
-     * terminates the inspection.
-     * 
-     * @param inspection the Inspection for which the limit is set
-     * @param limit the spam score that causes the Inspection to stop. Usually
-     *            this is a negative number.
-     */
-    public static void setSpamLimit( Inspection inspection, float limit )
-    {
-        InspectionListener listener = new SpamListener( limit );
-        inspection.addListener( Topic.SPAM, listener );
-    }
-
     /** Default limit at which we consider something to be spam. */
     protected static final float DEFAULT_SCORE_LIMIT = -0.01f;
 
@@ -75,37 +37,50 @@
 
     protected static final String PROP_CAPTCHA_CLASS = "jspwiki.captcha.implementation";
 
-    private static final Map<WikiEngine, InspectionPlan> c_plans = new HashMap<WikiEngine, InspectionPlan>();
-
-    private static final Map<WikiEngine, Challenge> c_captchas = new HashMap<WikiEngine,Challenge>();
+    private static final Map<WikiEngine, SpamInspectionPlan> c_plans = new HashMap<WikiEngine, SpamInspectionPlan>();
+    
+    private final Challenge m_captcha;
 
-    private static final Map<WikiEngine, Float> c_spamLimits = new HashMap<WikiEngine, Float>();
+    private final float m_limit;
     
-    public static float defaultSpamLimit( WikiEngine engine )
+    /**
+     * Private constructor to prevent direct instantiation.
+     * @throws WikiException if the SpamInspectionPlan cannot be
+     * initialized for any reason; the original Exception will be wrapped
+     */
+    private SpamInspectionPlan( Properties properties ) throws WikiException
+    {
+       super( properties ); 
+       
+       // Configure the CAPTCHA
+       m_captcha = initCaptcha( properties );
+       
+       // Get the default spam score limits
+       float limit = DEFAULT_SCORE_LIMIT;
+       String limitString = properties.getProperty( PROP_SCORE_LIMIT, String.valueOf( DEFAULT_SCORE_LIMIT ) );
+       try
+       {
+           limit = Float.parseFloat( limitString );
+       }
+       catch( NumberFormatException e )
+       {
+           log.error( "Property value " + PROP_SCORE_LIMIT + " did not parse to a float. Using " + DEFAULT_SCORE_LIMIT );
+       }
+       m_limit = limit;
+    }
+    
+    public float getSpamLimit()
     {
-        Float limit = c_spamLimits.get( engine );
-        return limit == null ? DEFAULT_SCORE_LIMIT : limit.floatValue();
+        return m_limit;
     }
 
     /**
-     * Looks up and returns the CAPTCHA ({@link Challenge}) for a given WikiEngine.
-     * If the CAPTCHA does not exist, it will be created. <em>Callers should
-     * check for {@code null} values, which indicate a CAPTCHA was
-     * not configured.</em>
-     * @return the CAPTCHA, or {@code null} if one was not specified
-     * in the wiki engine's properties (or not configured)
+     * Returns the CAPTCHA ({@link Challenge}) for a the SpamInspectionPlan.
+     * @return the CAPTCHA
      */
-    public static final Challenge getCaptcha( WikiEngine engine ) throws WikiException
+    public Challenge getCaptcha() throws WikiException
     {
-        if ( c_captchas.containsKey( engine ) )
-        {
-            return c_captchas.get( engine );
-        }
-
-        // Lazily create
-        Challenge captcha = initCaptcha( engine.getWikiProperties() );
-        c_captchas.put( engine, captcha );
-        return captcha;
+        return m_captcha;
     }
 
     /**
@@ -130,45 +105,29 @@
      * <code>{@value #PROP_INSPECTOR_WEIGHT_PREFIX}<var>fullyQualifiedClassname</var></code>.
      * 
      * @param engine the wiki engine
-     * @param props the properties used to initialize the InspectionPlan and
-     *            Inspectors
      * @return the InspectionPlan
      */
-    public static InspectionPlan getInspectionPlan( WikiEngine engine, Properties props )
+    public static SpamInspectionPlan getInspectionPlan( WikiEngine engine ) throws WikiException
     {
-        InspectionPlan plan = c_plans.get( engine );
+        SpamInspectionPlan plan = c_plans.get( engine );
         if( plan != null )
         {
             return plan;
         }
 
         // Create new InspectionPlan for this WikiEngine
-        plan = new InspectionPlan( props );
-        plan.addInspector( new UserInspector(), getWeight( props, UserInspector.class ) );
-        plan.addInspector( new BanListInspector(), getWeight( props, BanListInspector.class ) );
-        plan.addInspector( new ChangeRateInspector(), getWeight( props, ChangeRateInspector.class ) );
-        plan.addInspector( new LinkCountInspector(), getWeight( props, LinkCountInspector.class ) );
-        plan.addInspector( new BotTrapInspector(), getWeight( props, BotTrapInspector.class ) );
-        plan.addInspector( new AkismetInspector(), getWeight( props, AkismetInspector.class ) );
-        plan.addInspector( new PatternInspector(), getWeight( props, PatternInspector.class ) );
+        Properties props = engine.getWikiProperties();
+        plan = new SpamInspectionPlan( props );
+        plan.addInspector( new UserInspector(), plan.getWeight( props, UserInspector.class ) );
+        plan.addInspector( new BanListInspector(), plan.getWeight( props, BanListInspector.class ) );
+        plan.addInspector( new ChangeRateInspector(), plan.getWeight( props, ChangeRateInspector.class ) );
+        plan.addInspector( new LinkCountInspector(), plan.getWeight( props, LinkCountInspector.class ) );
+        plan.addInspector( new BotTrapInspector(), plan.getWeight( props, BotTrapInspector.class ) );
+        plan.addInspector( new AkismetInspector(), plan.getWeight( props, AkismetInspector.class ) );
+        plan.addInspector( new PatternInspector(), plan.getWeight( props, PatternInspector.class ) );
         c_plans.put( engine, plan );
 
         // Figure out the Challenge to use for this WikiEngine
-
-
-        // Get the default spam score limits
-        float limit = DEFAULT_SCORE_LIMIT;
-        String limitString = props.getProperty( PROP_SCORE_LIMIT, String.valueOf( DEFAULT_SCORE_LIMIT ) );
-        try
-        {
-            limit = Float.parseFloat( limitString );
-        }
-        catch( NumberFormatException e )
-        {
-            log.error( "Property value " + PROP_SCORE_LIMIT + " did not parse to a float. Using " + DEFAULT_SCORE_LIMIT );
-        }
-        c_spamLimits.put( engine, Float.valueOf( limit ) );
-
         return plan;
     }
 
@@ -179,7 +138,7 @@
      * @param inspectorClass the Inspector class
      * @return if found, the desired weight; if not, returns {@link #DEFAULT_WEIGHT}
      */
-    protected static float getWeight( Properties props, Class<? extends Inspector> inspectorClass )
+    protected float getWeight( Properties props, Class<? extends Inspector> inspectorClass )
     {
         String key = PROP_INSPECTOR_WEIGHT_PREFIX + inspectorClass.getCanonicalName();
         float weight = DEFAULT_WEIGHT;

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/filters/SpamFilter.java Fri Jan  8 05:22:52 2010
@@ -27,6 +27,7 @@
 import org.apache.commons.jrcs.diff.DifferentiationFailedException;
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.content.inspect.*;
 import org.apache.wiki.log.Logger;
@@ -111,7 +112,7 @@
 
     private static final String ATTR_SPAMFILTER_SCORE = "spamfilter.score";
 
-    private InspectionPlan m_plan;
+    private SpamInspectionPlan m_plan;
 
     private boolean m_useCaptcha = false;
 
@@ -130,7 +131,15 @@
     {
         m_errorPage = properties.getProperty( PROP_ERRORPAGE, m_errorPage );
         m_useCaptcha = properties.getProperty( PROP_CAPTCHA, "" ).equals( "asirra" );
-        m_plan = SpamInspectionFactory.getInspectionPlan( engine, properties );
+        try
+        {
+            m_plan = SpamInspectionPlan.getInspectionPlan( engine );
+        }
+        catch( WikiException e )
+        {
+            e.printStackTrace();
+            throw new RuntimeException( "Could not start PageFilter: " + e.getMessage(), e );
+        }
     }
 
     /** {@inheritDoc} */
@@ -148,14 +157,12 @@
 
         // Run the Inspection
         Inspection inspection = new Inspection( context, m_plan );
-        float spamScoreLimit = SpamInspectionFactory.defaultSpamLimit( m_engine );
-        SpamInspectionFactory.setSpamLimit( inspection, spamScoreLimit );
         inspection.inspect( change );
         float spamScore = inspection.getScore( Topic.SPAM );
         context.setVariable( ATTR_SPAMFILTER_SCORE, spamScore );
 
         // Redirect user if score too low
-        if( spamScore <= spamScoreLimit )
+        if( spamScore <= m_plan.getSpamLimit() )
         {
             StringBuilder s = new StringBuilder();
             for( Finding finding : inspection.getFindings( Topic.SPAM ) )

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SpamProtectTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SpamProtectTag.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SpamProtectTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/SpamProtectTag.java Fri Jan  8 05:22:52 2010
@@ -38,7 +38,7 @@
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.content.inspect.BotTrapInspector;
 import org.apache.wiki.content.inspect.Challenge;
-import org.apache.wiki.content.inspect.SpamInspectionFactory;
+import org.apache.wiki.content.inspect.SpamInspectionPlan;
 import org.apache.wiki.filters.SpamFilter;
 import org.apache.wiki.ui.stripes.SpamInterceptor;
 import org.apache.wiki.ui.stripes.WikiActionBeanContext;
@@ -101,7 +101,7 @@
  */
 public class SpamProtectTag extends WikiTagBase
 {
-    private Challenge.Request m_challenge = Challenge.Request.CAPTCHA_ON_DEMAND;
+    private Challenge.State m_challenge = Challenge.State.CHALLENGE_NOT_PRESENTED;
 
     private static final String CHALLENGE_PASSWORD = "password";
 
@@ -143,9 +143,9 @@
 
     /**
      * Sets the {@code challenge} attribute for this tag. Valid values are
-     * {@code password} for {@link org.apache.wiki.content.inspect.Challenge.Request#PASSWORD} or {@code
-     * captcha} for {@link org.apache.wiki.content.inspect.Challenge.Request#CAPTCHA}. If not supplied, the
-     * challenge will default to {@link org.apache.wiki.content.inspect.Challenge.Request#CAPTCHA_ON_DEMAND}.
+     * {@code password} for {@link org.apache.wiki.content.inspect.Challenge.State#PASSWORD_PRESENTED} or {@code
+     * captcha} for {@link org.apache.wiki.content.inspect.Challenge.State#CAPTCHA_PRESENTED}. If not supplied, the
+     * challenge will default to {@link org.apache.wiki.content.inspect.Challenge.State#CHALLENGE_NOT_PRESENTED}.
      * 
      * @param challenge the type of challenge the user should see
      */
@@ -153,15 +153,15 @@
     {
         if( CHALLENGE_CAPTCHA.equals( challenge.toLowerCase() ) )
         {
-            m_challenge = Challenge.Request.CAPTCHA;
+            m_challenge = Challenge.State.CAPTCHA_PRESENTED;
         }
         else if( CHALLENGE_PASSWORD.equals( challenge.toLowerCase() ) )
         {
-            m_challenge = Challenge.Request.PASSWORD;
+            m_challenge = Challenge.State.PASSWORD_PRESENTED;
         }
         else
         {
-            m_challenge = Challenge.Request.CAPTCHA_ON_DEMAND;
+            m_challenge = Challenge.State.CHALLENGE_NOT_PRESENTED;
         }
     }
 
@@ -222,24 +222,25 @@
     private void writeChallengeFormContent() throws IOException, WikiException
     {
         WikiEngine engine = m_wikiContext.getEngine();
+        SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( engine );
         String challengeContent = null;
 
         switch( m_challenge )
         {
-            case PASSWORD: {
+            case PASSWORD_PRESENTED: {
                 // Not implemented yet
                 break;
             }
-            case CAPTCHA: {
-                Challenge captcha = SpamInspectionFactory.getCaptcha( engine );
+            case CAPTCHA_PRESENTED: {
+                Challenge captcha = plan.getCaptcha();
                 challengeContent = captcha.formContent( m_wikiActionBean.getContext() );
                 break;
             }
-            case CAPTCHA_ON_DEMAND: {
+            case CHALLENGE_NOT_PRESENTED: {
                 if( isSpamDetected( (WikiActionBeanContext)m_wikiContext ) )
                 {
-                    m_challenge = Challenge.Request.CAPTCHA;
-                    Challenge captcha = SpamInspectionFactory.getCaptcha( engine );
+                    m_challenge = Challenge.State.CAPTCHA_PRESENTED;
+                    Challenge captcha = plan.getCaptcha();
                     challengeContent = captcha.formContent( m_wikiActionBean.getContext() );
                 }
                 break;

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/SpamInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/SpamInterceptor.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/SpamInterceptor.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/SpamInterceptor.java Fri Jan  8 05:22:52 2010
@@ -130,7 +130,7 @@
      * creates a new {@link Inspection} that inspects each ActionBean property
      * indicated by the {@link SpamProtect#content()}. The
      * {@link InspectionPlan} for the Inspection is obtained by calling
-     * {@link SpamInspectionFactory#getInspectionPlan(WikiEngine, java.util.Properties)}
+     * {@link SpamInspectionPlan#getInspectionPlan(WikiEngine, java.util.Properties)}
      * . If any of the modifications are determined to be spam, a Stripes
      * {@link ValidationError} is added to the ActionBeanContext.
      * 
@@ -150,31 +150,32 @@
         WikiActionBean actionBean = (WikiActionBean) context.getActionBean();
         boolean isSpam = false;
 
-        switch( getChallengeRequest( actionBean.getContext() ) )
+        switch( getChallengeState( actionBean.getContext() ) )
         {
-            case CAPTCHA_ON_DEMAND: {
+            case CHALLENGE_NOT_PRESENTED: {
                 // First-time submission; no challenge was requested
                 isSpam = checkForSpam( actionBean, eventInfo );
                 break;
             }
 
-            case PASSWORD: {
+            case PASSWORD_PRESENTED: {
                 // Password challenge was requested
                 // Not implemented yet
                 checkForSpam( actionBean, eventInfo );
                 break;
             }
 
-            case CAPTCHA: {
+            case CAPTCHA_PRESENTED: {
                 // CAPTCHA challenge was requested
                 checkForSpam( actionBean, eventInfo );
                 WikiEngine engine = actionBean.getContext().getEngine();
-                Challenge captcha = SpamInspectionFactory.getCaptcha( engine );
+                SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( engine );
+                Challenge captcha = plan.getCaptcha();
                 isSpam = !captcha.check( actionBean.getContext() );
                 break;
             }
 
-            case OMITTED: {
+            case MISSING_STATE: {
                 // The Challenge param wasn't there. Naughty user!
                 checkForSpam( actionBean, eventInfo );
                 isSpam = true;
@@ -195,6 +196,44 @@
     }
 
     /**
+     * Retrieves the encrypted parameter {@link #CHALLENGE_REQUEST_PARAM} from
+     * the HTTP request and returns its value. If the parameter is not found in
+     * the request, we assume that the request was made by a spammer or other
+     * naughty person, and the method returns {@link org.apache.wiki.content.inspect.Challenge.State#MISSING_STATE}.
+     * Otherwise, the value of the parameter is decrypted and returned. This
+     * method is guaranteed to return a non-{@code null} value.
+     * 
+     * @param actionBeanContext the action bean context
+     * @return the Challenge that was requested, or
+     *         {@link org.apache.wiki.content.inspect.Challenge.State#MISSING_STATE} if the parameter
+     *         {@link #CHALLENGE_REQUEST_PARAM} was not found.
+     */
+    private Challenge.State getChallengeState( ActionBeanContext actionBeanContext )
+    {
+        HttpServletRequest request = actionBeanContext.getRequest();
+        String encryptedCaptchaParam = request.getParameter( CHALLENGE_REQUEST_PARAM );
+        if( encryptedCaptchaParam != null )
+        {
+            String captchaParam = CryptoUtil.decrypt( encryptedCaptchaParam );
+            if( captchaParam != null )
+            {
+                try
+                {
+                    Challenge.State challenge = Challenge.State.valueOf( captchaParam );
+                    return challenge;
+                }
+                catch( IllegalArgumentException e )
+                {
+                    // The decrypted Challenge.Request was a funny value
+                }
+            }
+        }
+
+        // Challenge param not found or funny value: assume it's a spammer
+        return Challenge.State.MISSING_STATE;
+    }
+
+    /**
      * Looks up and returns the HandlerInfo object that corresponds to the
      * current Stripes ExecutionContext, based on the ActionBean and event
      * handler method being executed.
@@ -239,34 +278,33 @@
      *         exceeds the spam threshold, or {@code false} otherwise
      * @throws DifferentiationFailedException if it is not possible to create a
      *             {@link Change} object showing what contents changed
+     * @throws WikiException if it the {@link SpamInspectionPlan} cannot be retrieved
      */
-    protected boolean checkForSpam( WikiActionBean actionBean, HandlerInfo eventInfo ) throws DifferentiationFailedException
+    protected boolean checkForSpam( WikiActionBean actionBean, HandlerInfo eventInfo ) throws DifferentiationFailedException, WikiException
     {
         // Retrieve all of the bean fields named in the @SpamProtect annotation
         WikiActionBeanContext actionBeanContext = actionBean.getContext();
         WikiEngine engine = actionBeanContext.getEngine();
-        InspectionPlan plan = SpamInspectionFactory.getInspectionPlan( engine, engine.getWikiProperties() );
+        SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( engine );
         Map<String, Object> fieldValues = getBeanProperties( actionBean, eventInfo.getSpamProtectedFields() );
 
         // Create an Inspection for analyzing the bean's contents
         Inspection inspection = new Inspection( actionBeanContext, plan );
-        float spamScoreLimit = SpamInspectionFactory.defaultSpamLimit( engine );
-        SpamInspectionFactory.setSpamLimit( inspection, spamScoreLimit );
 
         // Let's get to it!
         List<Change> changes = new ArrayList<Change>();
         for( Map.Entry<String, Object> entry : fieldValues.entrySet() )
         {
-            String name = entry.getKey();
+            String field = entry.getKey();
             String value = entry.getValue().toString();
             Change change;
-            if( "page".equals( name ) )
+            if( "page".equals( field ) )
             {
                 change = Change.getPageChange( actionBeanContext, value );
             }
             else
             {
-                change = Change.getChange( name, value );
+                change = Change.getChange( field, value );
             }
             changes.add( change );
         }
@@ -276,44 +314,6 @@
         float spamScore = inspection.getScore( Topic.SPAM );
 
         // Does the spam score exceed the threshold?
-        return spamScore <= spamScoreLimit;
-    }
-
-    /**
-     * Retrieves the encrypted parameter {@link #CHALLENGE_REQUEST_PARAM} from
-     * the HTTP request and returns its value. If the parameter is not found in
-     * the request, we assume that the request was made by a spammer or other
-     * naughty person, and the method returns {@link org.apache.wiki.content.inspect.Challenge.Request#OMITTED}.
-     * Otherwise, the value of the parameter is decrypted and returned. This
-     * method is guaranteed to return a non-{@code null} value.
-     * 
-     * @param actionBeanContext the action bean context
-     * @return the Challenge that was requested, or
-     *         {@link org.apache.wiki.content.inspect.Challenge.Request#OMITTED} if the parameter
-     *         {@link #CHALLENGE_REQUEST_PARAM} was not found.
-     */
-    protected Challenge.Request getChallengeRequest( ActionBeanContext actionBeanContext )
-    {
-        HttpServletRequest request = actionBeanContext.getRequest();
-        String encryptedCaptchaParam = request.getParameter( CHALLENGE_REQUEST_PARAM );
-        if( encryptedCaptchaParam != null )
-        {
-            String captchaParam = CryptoUtil.decrypt( encryptedCaptchaParam );
-            if( captchaParam != null )
-            {
-                try
-                {
-                    Challenge.Request challenge = Challenge.Request.valueOf( captchaParam );
-                    return challenge;
-                }
-                catch( IllegalArgumentException e )
-                {
-                    // The decrypted Challenge.Request was a funny value
-                }
-            }
-        }
-
-        // Challenge param not found or funny value: assume it's a spammer
-        return Challenge.Request.OMITTED;
+        return spamScore <= plan.getSpamLimit();
     }
 }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java Fri Jan  8 05:22:52 2010
@@ -186,7 +186,7 @@
         trip.addParameter( BotTrapInspector.REQ_TRAP_PARAM, new String[0] );
         trip.addParameter( "TOKENA", trip.getRequest().getSession().getId() );
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, paramValue );
-        paramValue = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        paramValue = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, paramValue );
 
         // Add the UTF-8 token

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/AllTests.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/AllTests.java Fri Jan  8 05:22:52 2010
@@ -39,7 +39,7 @@
         suite.addTest( InspectionPlanTest.suite() );
         suite.addTest( InspectionTest.suite() );
         suite.addTest( ReputationManagerTest.suite() );
-        suite.addTest( SpamInspectionFactoryTest.suite() );
+        suite.addTest( SpamInspectionPlanTest.suite() );
 
         return suite;
     }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/InspectionTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/InspectionTest.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/InspectionTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/InspectionTest.java Fri Jan  8 05:22:52 2010
@@ -64,35 +64,6 @@
     }
 
     /**
-     * Dummy listener class that can be configured to interrupt an Inspection.
-     */
-    static class TestInspectionListener implements InspectionListener
-    {
-        private final boolean m_interrupt;
-
-        private boolean m_executed = false;
-
-        public TestInspectionListener( boolean interrupt )
-        {
-            m_interrupt = interrupt;
-        }
-
-        public void changedScore( Inspection inspection, Finding score ) throws InspectionInterruptedException
-        {
-            m_executed = true;
-            if( m_interrupt )
-            {
-                throw new InspectionInterruptedException( this, "Interrupted by TestInspectionListener." );
-            }
-        }
-
-        public boolean isExecuted()
-        {
-            return m_executed;
-        }
-    }
-
-    /**
      * Dummy inspector class that returns a predictable Result.
      */
     static class TestInspector implements Inspector
@@ -206,60 +177,4 @@
         findings = inspection.getFindings( new Topic( "NoFindingsTopic" ) );
         assertEquals( 0, findings.length );
     }
-
-    public void testAddListener() throws Exception
-    {
-        InspectionPlan plan = new InspectionPlan( m_props );
-        Inspector pass = new TestInspector( Topic.SPAM, Result.PASSED );
-        Inspector pass2 = new TestInspector( Topic.SPAM, Result.PASSED );
-        plan.addInspector( pass, 2 );
-        plan.addInspector( pass2, 1 );
-
-        // Configure the inspection with 2 listeners
-        WikiPage page = m_engine.getFrontPage( ContentManager.DEFAULT_SPACE );
-        WikiContext context = m_engine.getWikiContextFactory().newViewContext( page );
-        Inspection inspection = new Inspection( context, plan );
-        TestInspectionListener listener = new TestInspectionListener( false );
-        TestInspectionListener listener2 = new TestInspectionListener( false );
-        inspection.addListener( Topic.SPAM, listener );
-        inspection.addListener( new Topic( "Topic2" ), listener2 );
-
-        // Run the inspection
-        inspection.inspect( Change.getChange( "page", "Sample text" ) );
-
-        // Verify that Spam listener fired, but Topic2 listener did not
-        assertTrue( listener.isExecuted() );
-        assertFalse( listener2.isExecuted() );
-
-        // Verify the listener did not interrupt execution
-        assertEquals( 3.0f, inspection.getScore( Topic.SPAM ) );
-    }
-
-    public void testAddInterruptingListener() throws Exception
-    {
-        InspectionPlan plan = new InspectionPlan( m_props );
-        Inspector pass = new TestInspector( Topic.SPAM, Result.PASSED );
-        Inspector pass2 = new TestInspector( Topic.SPAM, Result.PASSED );
-        plan.addInspector( pass, 2 );
-        plan.addInspector( pass2, 1 );
-
-        // Configure the inspection with 2 listeners that interrupt
-        WikiPage page = m_engine.getFrontPage( ContentManager.DEFAULT_SPACE );
-        WikiContext context = m_engine.getWikiContextFactory().newViewContext( page );
-        Inspection inspection = new Inspection( context, plan );
-        TestInspectionListener listener = new TestInspectionListener( true );
-        TestInspectionListener listener2 = new TestInspectionListener( true );
-        inspection.addListener( Topic.SPAM, listener );
-        inspection.addListener( new Topic( "Topic2" ), listener2 );
-
-        // Run the inspection
-        inspection.inspect( Change.getChange( "page", "Sample text" ) );
-
-        // Verify that Spam listener fired, but Topic2 listener did not
-        assertTrue( listener.isExecuted() );
-        assertFalse( listener2.isExecuted() );
-
-        // Verify the Spam listener interrupted execution
-        assertEquals( 2f, inspection.getScore( Topic.SPAM ) );
-    }
 }

Copied: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionPlanTest.java (from r896518, incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionFactoryTest.java)
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionPlanTest.java?p2=incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionPlanTest.java&p1=incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionFactoryTest.java&r1=896518&r2=897097&rev=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionFactoryTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/inspect/SpamInspectionPlanTest.java Fri Jan  8 05:22:52 2010
@@ -40,11 +40,11 @@
 
 /**
  */
-public class SpamInspectionFactoryTest extends TestCase
+public class SpamInspectionPlanTest extends TestCase
 {
     public static Test suite()
     {
-        return new TestSuite( SpamInspectionFactoryTest.class );
+        return new TestSuite( SpamInspectionPlanTest.class );
     }
 
     private Properties m_props = new Properties();
@@ -53,7 +53,7 @@
 
     private static final float PERFECT_SCORE = 0f;
 
-    public SpamInspectionFactoryTest( String s )
+    public SpamInspectionPlanTest( String s )
     {
         super( s );
     }
@@ -62,7 +62,6 @@
     {
         m_props.load( TestEngine.findTestProperties() );
         m_props.setProperty( InspectionPlan.PROP_BANTIME, "1" );
-        m_engine = new TestEngine( m_props );
     }
 
     public void tearDown() throws Exception
@@ -78,6 +77,9 @@
      */
     public void testBanListInspector() throws Exception
     {
+        initDefaultPlanProperties();
+        m_engine = new TestEngine( m_props );
+
         // Create a new HTTP request. Make sure to add the BotTrap/UTF-8
         // parameters.
         MockHttpServletRequest request = new MockHttpServletRequest( "/", "/" );
@@ -103,6 +105,9 @@
      */
     public void testChangeRateInspectorVelocity() throws Exception
     {
+        initDefaultPlanProperties();
+        m_engine = new TestEngine( m_props );
+
         // Create a new HTTP request. Make sure to add the BotTrap/UTF-8
         // parameters.
         MockHttpServletRequest request = new MockHttpServletRequest( "/", "/" );
@@ -135,6 +140,9 @@
      */
     public void testLinkCountInspector() throws Exception
     {
+        initDefaultPlanProperties();
+        m_engine = new TestEngine( m_props );
+
         // Create a new HTTP request. Make sure to add the BotTrap/UTF-8
         // parameters.
         MockHttpServletRequest request = new MockHttpServletRequest( "/", "/" );
@@ -164,6 +172,9 @@
      */
     public void testChangeRateInspectorSimilarity() throws Exception
     {
+        initDefaultPlanProperties();
+        m_engine = new TestEngine( m_props );
+
         // Create a new HTTP request. Make sure to add the BotTrap/UTF-8
         // parameters.
         MockHttpServletRequest request = new MockHttpServletRequest( "/", "/" );
@@ -200,6 +211,9 @@
      */
     public void testBotTrapInspector() throws Exception
     {
+        initDefaultPlanProperties();
+        m_engine = new TestEngine( m_props );
+
         // Create a new HTTP request. Make sure to add the BotTrap/UTF-8
         // parameters.
         MockHttpServletRequest request = new MockHttpServletRequest( "/", "/" );
@@ -250,7 +264,9 @@
 
     public void testGetInspectionPlan() throws Exception
     {
-        InspectionPlan plan = SpamInspectionFactory.getInspectionPlan( m_engine, m_props );
+        m_engine = new TestEngine( m_props );
+
+        InspectionPlan plan = SpamInspectionPlan.getInspectionPlan( m_engine );
         Inspector[] inspectors = plan.getInspectors();
         assertEquals( 7, inspectors.length );
         assertEquals( UserInspector.class, inspectors[0].getClass() );
@@ -264,30 +280,45 @@
 
     public void testGetScoreLimit() throws Exception
     {
-        SpamInspectionFactory.getInspectionPlan( m_engine, m_props );
+        m_engine = new TestEngine( m_props );
+
+        SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( m_engine );
         // the value in the test properties file
-        assertEquals( -0.5f, SpamInspectionFactory.defaultSpamLimit( m_engine ) );
+        assertEquals( -0.5f, plan.getSpamLimit() );
     }
 
     public void testGetWeight() throws Exception
     {
-        String key = SpamInspectionFactory.PROP_INSPECTOR_WEIGHT_PREFIX + BanListInspector.class.getCanonicalName();
+        String key = SpamInspectionPlan.PROP_INSPECTOR_WEIGHT_PREFIX + BanListInspector.class.getCanonicalName();
         m_props.put( key, "-2.0f" );
-        assertEquals( -2.0f, SpamInspectionFactory.getWeight( m_props, BanListInspector.class ) );
-        assertEquals( SpamInspectionFactory.DEFAULT_WEIGHT, SpamInspectionFactory.getWeight( m_props, UserInspector.class ) );
+        m_engine = new TestEngine( m_props );
+        SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( m_engine );
+        assertEquals( -2.0f, plan.getWeight( m_props, BanListInspector.class ) );
+        assertEquals( SpamInspectionPlan.DEFAULT_WEIGHT, plan.getWeight( m_props, UserInspector.class ) );
     }
 
     public void testSetScoreLimit() throws Exception
     {
-        m_props.put( SpamInspectionFactory.PROP_SCORE_LIMIT, "-2.0f" );
-        SpamInspectionFactory.getInspectionPlan( m_engine, m_props );
-        assertEquals( -2.0f, SpamInspectionFactory.defaultSpamLimit( m_engine ) );
+        m_props.put( SpamInspectionPlan.PROP_SCORE_LIMIT, "-2.0f" );
+        m_engine = new TestEngine( m_props );
+        SpamInspectionPlan plan = SpamInspectionPlan.getInspectionPlan( m_engine );
+        assertEquals( -2.0f, plan.getSpamLimit() );
     }
 
     private Inspection createInspection( HttpServletRequest request ) throws Exception
     {
+        InspectionPlan plan = SpamInspectionPlan.getInspectionPlan( m_engine );
+        plan.getReputationManager().unbanHost( request );
+        WikiPage page = m_engine.getFrontPage( ContentManager.DEFAULT_SPACE );
+        WikiContext context = m_engine.getWikiContextFactory().newViewContext( request, null, page );
+        Inspection inspection = new Inspection( context, plan );
+        return inspection;
+    }
+    
+    private void initDefaultPlanProperties()
+    {
         // Make sure all of the Inspectors always run (disable the score limits)
-        m_props.put( SpamInspectionFactory.PROP_SCORE_LIMIT, "-1000f" );
+        m_props.put( SpamInspectionPlan.PROP_SCORE_LIMIT, "-1000f" );
 
         // Define predictable weights for each Inspector
         setWeight( UserInspector.class, 1f );
@@ -302,14 +333,6 @@
         m_props.put( LinkCountInspector.PROP_MAXURLS, "2" );
         m_props.put( ChangeRateInspector.PROP_PAGECHANGES, "100" );
         m_props.put( ChangeRateInspector.PROP_SIMILARCHANGES, "50" );
-
-        // Create the plan
-        InspectionPlan plan = SpamInspectionFactory.getInspectionPlan( m_engine, m_props );
-        plan.getReputationManager().unbanHost( request );
-        WikiPage page = m_engine.getFrontPage( ContentManager.DEFAULT_SPACE );
-        WikiContext context = m_engine.getWikiContextFactory().newViewContext( request, null, page );
-        Inspection inspection = new Inspection( context, plan );
-        return inspection;
     }
 
     private void setupSpamParams( MockHttpServletRequest request )
@@ -324,7 +347,7 @@
 
     private void setWeight( Class<? extends Inspector> inspectorClass, float weight )
     {
-        String key = SpamInspectionFactory.PROP_INSPECTOR_WEIGHT_PREFIX + inspectorClass.getCanonicalName();
+        String key = SpamInspectionPlan.PROP_INSPECTOR_WEIGHT_PREFIX + inspectorClass.getCanonicalName();
         m_props.setProperty( key, String.valueOf( weight ) );
     }
 }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/SpamInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/SpamInterceptorTest.java?rev=897097&r1=897096&r2=897097&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/SpamInterceptorTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/SpamInterceptorTest.java Fri Jan  8 05:22:52 2010
@@ -36,6 +36,8 @@
 import org.apache.wiki.content.inspect.Challenge;
 import org.apache.wiki.tags.SpamProtectTag;
 
+import com.sun.tools.javac.util.Context;
+
 public class SpamInterceptorTest extends TestCase
 {
     public static Test suite()
@@ -85,7 +87,7 @@
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, CryptoUtil.encrypt( "TOKENA" ) );
         
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Add the UTF-8 token
@@ -99,7 +101,7 @@
         // ...but that we failed the token check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testInvalidTrap() throws Exception
@@ -111,7 +113,7 @@
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, CryptoUtil.encrypt( "TOKENA" ) );
 
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Add the UTF-8 token
@@ -125,7 +127,7 @@
         // ...but that we failed the trap check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testMissingToken() throws Exception
@@ -136,7 +138,7 @@
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, CryptoUtil.encrypt( "" ) );
 
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Add the UTF-8 token
@@ -150,7 +152,7 @@
         // ...but that we failed the token check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testMissingTrap() throws Exception
@@ -161,7 +163,7 @@
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, CryptoUtil.encrypt( "TOKENA" ) );
 
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Add the UTF-8 token
@@ -188,7 +190,7 @@
         trip.addParameter( BotTrapInspector.REQ_SPAM_PARAM, paramValue );
 
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Verify that we got the ActionBean...
@@ -199,7 +201,7 @@
         // ...but that we failed the UTF-8 check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testNoChallenge() throws Exception
@@ -223,7 +225,7 @@
         // ...but that we failed the challenge check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testNoToken() throws Exception
@@ -232,7 +234,7 @@
         MockRoundtrip trip = m_engine.guestTrip( "/Test.action" );
 
         // Add the challenge param
-        String challengeParam = CryptoUtil.encrypt( Challenge.Request.CAPTCHA_ON_DEMAND.name() );
+        String challengeParam = CryptoUtil.encrypt( Challenge.State.CHALLENGE_NOT_PRESENTED.name() );
         trip.addParameter( SpamInterceptor.CHALLENGE_REQUEST_PARAM, challengeParam );
 
         // Add the UTF-8 token
@@ -246,7 +248,7 @@
         // ...but that we failed the token check
         assertEquals( 1, trip.getValidationErrors().size() );
         assertTrue( SpamProtectTag.isSpamDetected( bean.getContext() ) );
-        assertEquals( null, trip.getDestination() );
+        assertEquals( bean.getContext().getSourcePage(), trip.getDestination() );
     }
 
     public void testToken() throws Exception