jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r901980 - in /incubator/jspwiki/trunk: src/WebContent/WEB-INF/ src/java/org/apache/wiki/action/ src/java/org/apache/wiki/auth/authorize/ src/java/org/apache/wiki/event/ src/java/org/apache/wiki/preferences/ src/java/org/apache/wiki/ui/ src/...
Date Fri, 22 Jan 2010 03:59:39 GMT
Author: ajaquith
Date: Fri Jan 22 03:59:38 2010
New Revision: 901980

URL: http://svn.apache.org/viewvc?rev=901980&view=rev
Log:
WikiServletFilter's sole remaining function (checking for cookie and container authentication)
was moved into WikiInterceptor and WikiContextFactory. WikiServletFilter was removed.

Removed:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/WikiRequestWrapper.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/WikiServletFilter.java
Modified:
    incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/authorize/WebContainerAuthorizer.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/event/WikiPageEvent.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiActionBeanContext.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiInterceptor.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java

Modified: incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml (original)
+++ incubator/jspwiki/trunk/src/WebContent/WEB-INF/web.xml Fri Jan 22 03:59:38 2010
@@ -40,29 +40,6 @@
      <param-value>templates.default</param-value>
    </context-param>
 
-   <!--
-      WikiServletFilter defines a servlet filter which filters all requests. It was
-      introduced in JSPWiki 2.4.
-
-      In 2.7/2.8, the WikiServlet filter also performs an important security function:
-      it sets authentication status based on container credentials. It should generally
-      execute first. Note that if you configure a filter *before* this one that returns
-      non-null values for getUserPrincipal() or getRemoteUser(), WikiSecurityFilter
-      will pick the credentials up, and set the user's WikiSession state to
-      "authenticated." WikiServletFlter will also set the WikiSession's' state
-      to "authenticated" if jspwiki.properties property "jspwiki.cookieAuthentication"
-      is set to true, and the user possesses the correct authentication cookie.
-
-      Lastly, if jspwiki.properties property "jspwiki.cookieAssertions" is set to true,
-      WikiServletFilter will also set WikiSession state to "asserted" if the user
-      possesses the correct "assertion cookie."
-   -->
-
-   <filter>
-      <filter-name>WikiServletFilter</filter-name>
-      <filter-class>org.apache.wiki.ui.WikiServletFilter</filter-class>
-   </filter>
-   
    <!-- Configuration of the Stripes Filter. The Stripes MVC framework provides
          essential request routing, form processing and type conversion services
          for JSPWiki. -->
@@ -121,48 +98,14 @@
    </filter>
 
    <!--
-      This is new in 2.4.  This defines a servlet filter which filters all requests. 
+      The StripesFilter and DynamicMappingFilter process all requests for JSPs and ActionBeans.

    -->
-
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>/attach/*</url-pattern>
-   </filter-mapping>
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>/atom/*</url-pattern>
-   </filter-mapping>
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>/RPCU/</url-pattern>
-   </filter-mapping>
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>/RPC2/</url-pattern>
-   </filter-mapping>
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>/JSON-RPC</url-pattern>
-   </filter-mapping> 
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>*.jsp</url-pattern>
-   </filter-mapping> 
-   <filter-mapping>
-       <filter-name>WikiServletFilter</filter-name>
-       <url-pattern>*.action</url-pattern>
-   </filter-mapping> 
    <filter-mapping>
        <filter-name>StripesFilter</filter-name>
        <url-pattern>*.jsp</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    <filter-mapping>
-       <filter-name>StripesFilter</filter-name>
-       <servlet-name>StripesDispatcher</servlet-name>
-       <dispatcher>REQUEST</dispatcher>
-   </filter-mapping>
-   <filter-mapping>
       <filter-name>DynamicMappingFilter</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>REQUEST</dispatcher>
@@ -177,15 +120,6 @@
       <listener-class>org.apache.wiki.auth.SessionMonitor</listener-class>
    </listener>
    
-    <!-- 
-        Stripes dispatcher Servlet.
-    -->
-    <servlet>
-        <servlet-name>StripesDispatcher</servlet-name>
-        <servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
-        <load-on-startup>1</load-on-startup>
-    </servlet>
-
    <!--
        Now, let's define the XML-RPC interfaces.  You probably don't have to
        touch these.
@@ -236,30 +170,6 @@
        <servlet-class>org.apache.wiki.rpc.atom.AtomAPIServlet</servlet-class>
      
    </servlet>
 
-   <!-- Maps short URLS to JSPs; also, detects webapp shutdown. -->
-   <servlet>
-       <servlet-name>WikiServlet</servlet-name>
-       <servlet-class>org.apache.wiki.WikiServlet</servlet-class>
-       <!--
-       <load-on-startup>1</load-on-startup>
-       -->
-   </servlet>
-
-    <servlet-mapping>
-        <servlet-name>StripesDispatcher</servlet-name>
-        <url-pattern>/dispatcher</url-pattern>
-    </servlet-mapping>
-
-    <servlet-mapping>
-        <servlet-name>StripesDispatcher</servlet-name>
-        <url-pattern>/action/*</url-pattern>
-    </servlet-mapping>
-
-    <servlet-mapping>
-        <servlet-name>StripesDispatcher</servlet-name>
-        <url-pattern>*.action</url-pattern>
-    </servlet-mapping>
-
    <!-- PLACEHOLDER FOR PRE-COMPILED JSP SERVLETS -->
 
    <!--
@@ -290,11 +200,6 @@
    AND REMOVE ME TOO -->
 
    <servlet-mapping>
-       <servlet-name>WikiServlet</servlet-name>
-       <url-pattern>/wiki/*</url-pattern>
-   </servlet-mapping>
-
-   <servlet-mapping>
        <servlet-name>org.jabsorb.JSONRPCServlet</servlet-name>
        <url-pattern>/JSON-RPC</url-pattern>
    </servlet-mapping>

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java Fri Jan
22 03:59:38 2010
@@ -40,10 +40,8 @@
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiProvider;
-import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
-import org.apache.wiki.auth.SessionMonitor;
 import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiPath;
@@ -363,14 +361,14 @@
         WikiActionBeanContext context = new WikiActionBeanContext();
         context.setRequest( request );
         context.setResponse( response );
-        context.setEngine( m_engine );
         context.setServletContext( m_engine.getServletContext() );
-        WikiSession wikiSession = SessionMonitor.getInstance( m_engine ).find( request.getSession()
);
-        context.setWikiSession( wikiSession );
 
         // Set the request context (and related event name)
         context.setRequestContext( requestContext );
 
+        // Run the login stack
+        m_engine.getAuthenticationManager().login( request );
+
         // Extract and set the WikiPage
         if( page == null )
         {

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/authorize/WebContainerAuthorizer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/authorize/WebContainerAuthorizer.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/authorize/WebContainerAuthorizer.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/auth/authorize/WebContainerAuthorizer.java
Fri Jan 22 03:59:38 2010
@@ -159,15 +159,13 @@
      * Group). If either parameter is <code>null</code>, this method must
      * return <code>false</code>.
      * This method simply examines the WikiSession subject to see if it
-     * possesses the desired Principal. We assume that the method
-     * {@link org.apache.wiki.ui.WikiServletFilter#doFilter(javax.servlet.ServletRequest,
javax.servlet.ServletResponse, javax.servlet.FilterChain)}
-     * previously executed, and that it has set the WikiSession
+     * possesses the desired Principal. We assume that the login stack
+     * has previously run, and that it has set the WikiSession
      * subject correctly by logging in the user with the various login modules,
      * in particular {@link org.apache.wiki.auth.login.WebContainerLoginModule}}.
-     * This is definitely a hack,
-     * but it eliminates the need for WikiSession to keep dangling
-     * references to the last WikiContext hanging around, just
-     * so we can look up the HttpServletRequest.
+     * This is definitely a hack, but it eliminates the need for
+     * WikiSession to keep dangling references to the last WikiContext
+     * hanging around, just so we can look up the HttpServletRequest.
      *
      * @param session the current WikiSession
      * @param role the role to check

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/event/WikiPageEvent.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/event/WikiPageEvent.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/event/WikiPageEvent.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/event/WikiPageEvent.java Fri Jan 22 03:59:38
2010
@@ -57,8 +57,7 @@
   * <h3>Page Requested and Delivered Events</h3>
   * <p>
   * These two events are fired once per page request, at the beginning
-  * and after delivery of the page (respectively). They are generated
-  * by the {@link org.apache.wiki.ui.WikiServletFilter}.
+  * and after delivery of the page (respectively).
   * </p>
   *
   * <h3>Page Lock and Unlock Events</h3>
@@ -164,12 +163,10 @@
 
     // PAGE REQUESTS .........
 
-    /** Indicates a wiki page request event (the start of a request). This is based
-      * on events generated by {@link org.apache.wiki.ui.WikiServletFilter}. */
+    /** Indicates a wiki page request event (the start of a request). */
     public static final int PAGE_REQUESTED       = 24;
 
-    /** Indicates a wiki page delivery event (the end of a request). This is based
-      * on events generated by {@link org.apache.wiki.ui.WikiServletFilter}. */
+    /** Indicates a wiki page delivery event (the end of a request). */
     public static final int PAGE_DELIVERED       = 25;
 
     /** Indicates a wiki page delete event (the beginning of a delete request). 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/preferences/Preferences.java Fri Jan
22 03:59:38 2010
@@ -48,7 +48,7 @@
  * and other customizable user interface items. Preferences are initialized by
  * JSPWiki by reading a series of cookies from the user's HTTP request. This
  * happens once per request, during the execution of
- * {@link org.apache.wiki.ui.WikiServletFilter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)}.
+ * {@link org.apache.wiki.ui.stripes.WikiInterceptor}.
  * The method {@link #setupPreferences(HttpServletRequest)} performs the actual
  * initialization.
  * <p>

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/TemplateManager.java Fri Jan 22 03:59:38
2010
@@ -46,40 +46,6 @@
  */
 public class TemplateManager extends ModuleManager
 {
-    /**
-     * Enum that specifies the two types of templates: {@link #VIEW} and
-     * {@link #EDIT}.
-     */
-    public enum Template
-    {
-        /** Template used for viewing things. */
-        VIEW("ViewTemplate.jsp"),
-        /** Template used for editing things. */
-        EDIT("EditTemplate.jsp");
-
-        private final String m_template;
-
-        /**
-         * Package-private constructor.
-         * 
-         * @param template the name of the template
-         */
-        Template( String template )
-        {
-            m_template = template;
-        }
-
-        /**
-         * Returns the JSP for the template.
-         * 
-         * @return the template name
-         */
-        public String template()
-        {
-            return m_template;
-        }
-    }
-
     private static final String SKIN_DIRECTORY = "skins";
 
     /**
@@ -179,32 +145,6 @@
     }
 
     /**
-     * Check the existence of a template.
-     */
-    // FIXME: Does not work yet
-    public boolean templateExists( String templateName )
-    {
-        ServletContext context = m_engine.getServletContext();
-
-        InputStream in = context.getResourceAsStream( getPath( templateName ) + "ViewTemplate.jsp"
);
-
-        if( in != null )
-        {
-            try
-            {
-                in.close();
-            }
-            catch( IOException e )
-            {
-            }
-
-            return true;
-        }
-
-        return false;
-    }
-
-    /**
      * Tries to locate a given resource from the template directory, relative to
      * the root of the JSPWiki webapp context (for example, relative to
      * <code>/JSPWiki/</code>). If the given resource is not found at the 
@@ -333,7 +273,7 @@
      * 
      * @param pageContext The JSP PageContext
      * @param template From which template we should seek initially?
-     * @param name Which resource are we looking for (e.g. "ViewTemplate.jsp")
+     * @param name Which resource are we looking for (e.g. "DefaultLayout.jsp")
      * @return path to the JSP page; null, if it was not found.
      */
     public String findJSP( PageContext pageContext, String template, String name )

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/DefaultWikiContext.java Fri
Jan 22 03:59:38 2010
@@ -26,12 +26,14 @@
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.wiki.WikiContext;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.auth.SessionMonitor;
 import org.apache.wiki.auth.WikiPrincipal;
 import org.apache.wiki.auth.permissions.AllPermission;
 
@@ -442,32 +444,16 @@
     }
 
     /**
-     * Sets the WikiEngine for this WikiContext. This method <em>must</em> be
called
-     * as soon as possible after instantiation.
-     * @param engine the WikiEngine
-     */
-    protected void setEngine( WikiEngine engine )
-    {
-        m_engine = engine;
-    }
-    
-    /**
      * Sets the HttpServletRequest for this WikiContext. This method <em>must</em>
be called
-     * as soon as possible after instantiation.
+     * as soon as possible after instantiation. As a consequence of setting this method the
+     * WikiSession and WikiEngine references are also set.
      * @param request the HTTP request object
      */
     protected void setHttpRequest( HttpServletRequest request )
     {
+        ServletContext servletContext = request.getSession().getServletContext();
+        m_engine = WikiEngine.getInstance( servletContext, null );
         m_request = request;
-    }
-
-    /**
-     * Sets the WikiSession for this WikiContext. This method <em>must</em> be
called
-     * as soon as possible after instantiation.
-     * @param wikiSession the WikiSession
-     */
-    protected void setWikiSession( WikiSession wikiSession )
-    {
-        m_session = wikiSession;
+        m_session = SessionMonitor.getInstance( m_engine ).find( request.getSession() );
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiActionBeanContext.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiActionBeanContext.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiActionBeanContext.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiActionBeanContext.java
Fri Jan 22 03:59:38 2010
@@ -45,11 +45,8 @@
  * </p>
  * <p>
  * When the WikiActionBeanContext is created, callers <em>must</em> set the
- * WikiEngine reference by calling either {@link #setEngine(WikiEngine)}
- * (which sets it directly), or {@link #setServletContext(ServletContext)}
- * (which sets it lazily). when {@link #setServletContext(ServletContext)}. The
- * HttpServletRequest reference is set via
- * {@link #setRequest(HttpServletRequest)}.
+ * WikiEngine reference by calling either {@link #setRequest(HttpServletRequest)}
+ * or {@link #setServletContext(ServletContext)} (which sets it lazily).
  * </p>
  * 
  */
@@ -117,7 +114,8 @@
 
     /**
      *  {@inheritDoc}. Also calls {@link DefaultWikiContext#setHttpRequest(HttpServletRequest)}
on
-     *  the DefaultWikiContext delegate.
+     *  the DefaultWikiContext delegate. As a consequence of setting the request, the
+     *  WikiSession is also set.
      */
     @Override
     public void setRequest( HttpServletRequest request )
@@ -128,8 +126,7 @@
 
     /**
      * Calls the superclass
-     * {@link ActionBeanContext#setServletContext(ServletContext)} and lazily
-     * sets the internal WikiEngine reference, if still <code>null</code>.
+     * {@link ActionBeanContext#setServletContext(ServletContext)}.
      * 
      * @param servletContext the servlet context
      */
@@ -137,39 +134,15 @@
     public void setServletContext( ServletContext servletContext )
     {
         super.setServletContext( servletContext );
-        if( m_delegate.getEngine() == null )
-        {
-            WikiEngine engine = WikiEngine.getInstance( servletContext, null );
-            m_delegate.setEngine( engine );
-        }
     }
 
     /**
-     *  Sets the WikiEngine by calling {@link DefaultWikiContext#setEngine(WikiEngine)} on
-     *  the DefaultWikiContext delegate.
-     */
-    public void setEngine( WikiEngine engine )
-    {
-        m_delegate.setEngine( engine );
-    }
-
-    /**
-     *  Sets the WikiSession by calling {@link DefaultWikiContext#setEngine(WikiEngine)}
on
-     *  the DefaultWikiContext delegate.
-     */
-    public void setWikiSession( WikiSession wikiSession )
-    {
-        m_delegate.setWikiSession( wikiSession );
-    }
-    
-    /**
      *  {@inheritDoc}
      */
     public Object clone()
     {
         WikiActionBeanContext copy = new WikiActionBeanContext();
         copy.m_delegate = (DefaultWikiContext)m_delegate.clone();
-        copy.setEngine( getEngine() );
         copy.setEventName( getEventName() );
         copy.setRequest( getRequest() );
         copy.setResponse( getResponse() );
@@ -185,7 +158,6 @@
     {
         WikiActionBeanContext copy = new WikiActionBeanContext();
         copy.m_delegate = (DefaultWikiContext) m_delegate.deepClone();
-        copy.setEngine( getEngine() );
         copy.setEventName( getEventName() );
         copy.setRequest( getRequest() );
         copy.setResponse( getResponse() );

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiInterceptor.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiInterceptor.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiInterceptor.java Fri Jan
22 03:59:38 2010
@@ -39,8 +39,8 @@
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.WikiSession;
 import org.apache.wiki.action.*;
+import org.apache.wiki.api.WikiException;
 import org.apache.wiki.auth.AuthorizationManager;
-import org.apache.wiki.auth.SessionMonitor;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
 import org.apache.wiki.preferences.Preferences;
@@ -267,12 +267,12 @@
     /**
      * After the Stripes
      * {@link net.sourceforge.stripes.controller.LifecycleStage#ActionBeanResolution}
-     * executes, this method injects the current WikiEngine, WikiSession and
-     * WikiActionBean into request scope, and returns <code>null</code>. After
-     * the objects are injected, downstream classes like WikiTagBase can use
-     * them. The attribute can also be accessed as variables using the JSP
-     * Expression Language (example: <code>${wikiPage}</code>). User preferences
-     * are also set up.
+     * executes, this method runs the login stack to check for user authentication,
+     * injects the current WikiEngine, WikiSession and WikiActionBean into
+     * request scope, and returns <code>null</code>. After the objects are
+     * injected, downstream classes like WikiTagBase can use them. The attribute
+     * can also be accessed as variables using the JSP Expression Language
+     * (example: <code>${wikiPage}</code>). User preferences are also set up.
      * 
      * @param context the execution context
      * @return a Resolution if the
@@ -290,34 +290,28 @@
         {
             return r;
         }
-
+        
         // Retrieve the ActionBean, its ActionBeanContext, and HTTP request
         WikiActionBean actionBean = (WikiActionBean) context.getActionBean();
         WikiActionBeanContext actionBeanContext = actionBean.getContext();
         HttpServletRequest request = actionBeanContext.getRequest();
 
-        // Set the WikiSession, if not set yet
+        // If no WikiSession, we have a problem
         if( actionBeanContext.getWikiSession() == null )
         {
-            WikiEngine engine = actionBeanContext.getEngine();
-            WikiSession wikiSession = SessionMonitor.getInstance( engine ).find( request.getSession()
);
-            actionBeanContext.setWikiSession( wikiSession );
-
-            // Stash WikiEngine as a request attribute (can be
-            // used later as ${wikiEngine} in EL markup)
-            request.setAttribute( WikiContextFactory.ATTR_WIKIENGINE, engine );
-
-            // Stash the WikiSession as a request attribute
-            request.setAttribute( WikiContextFactory.ATTR_WIKISESSION, wikiSession );
+            throw new WikiException( "No WikiSession found!" );
         }
 
-        // Stash the ActionBean as request attribute, if not saved yet
-        if( request.getAttribute( ATTR_ACTIONBEAN ) == null )
-        {
-            request.setAttribute( ATTR_ACTIONBEAN, actionBean );
-        }
+        // Run the login stack
+        WikiEngine engine = actionBeanContext.getEngine();
+        engine.getAuthenticationManager().login( request );
+
+        // Stash the WikiEngine, WikiSession and ActionBean
+        request.setAttribute( WikiContextFactory.ATTR_WIKIENGINE, actionBeanContext.getEngine()
);
+        request.setAttribute( WikiContextFactory.ATTR_WIKISESSION, actionBeanContext.getWikiSession()
);
+        request.setAttribute( ATTR_ACTIONBEAN, actionBean );
 
-        // Stash it as a PageContext attribute too
+        // Stash the ActionBean as a PageContext attribute too
         PageContext pageContext = DispatcherHelper.getPageContext();
         if( pageContext != null )
         {

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=901980&r1=901979&r2=901980&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 22 03:59:38
2010
@@ -21,24 +21,21 @@
 
 package org.apache.wiki;
 import java.io.*;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 import javax.jcr.RepositoryException;
 import javax.security.auth.login.LoginException;
-import javax.servlet.ServletContext;
+import javax.servlet.*;
+import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 
-import net.sourceforge.stripes.controller.DispatcherServlet;
+import net.sourceforge.stripes.action.UrlBinding;
+import net.sourceforge.stripes.controller.DynamicMappingFilter;
 import net.sourceforge.stripes.controller.StripesFilter;
-import net.sourceforge.stripes.mock.MockHttpServletRequest;
-import net.sourceforge.stripes.mock.MockHttpSession;
-import net.sourceforge.stripes.mock.MockRoundtrip;
-import net.sourceforge.stripes.mock.MockServletContext;
+import net.sourceforge.stripes.mock.*;
 import net.sourceforge.stripes.util.CryptoUtil;
 
+import org.apache.wiki.action.ViewActionBean;
 import org.apache.wiki.action.WikiActionBean;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
@@ -57,7 +54,6 @@
 import org.apache.wiki.providers.AbstractFileProvider;
 import org.apache.wiki.providers.ProviderException;
 import org.apache.wiki.tags.SpamProtectTag;
-import org.apache.wiki.ui.WikiServletFilter;
 import org.apache.wiki.ui.stripes.SpamInterceptor;
 import org.apache.wiki.util.FileUtil;
 import org.apache.wiki.util.TextUtil;
@@ -154,12 +150,14 @@
     
     /**
      * Creates a correctly-instantiated mock HttpServletRequest with an associated
-     * HttpSession.
+     * HttpSession. The servlet path will be for ViewActionBean.
      * @return the new request
      */
     public MockHttpServletRequest newHttpRequest()
     {
-        return newHttpRequest( "/Wiki.jsp" );
+        UrlBinding binding = ViewActionBean.class.getAnnotation( UrlBinding.class );
+        String url = binding == null ? "/Wiki.action" : binding.value();
+        return newHttpRequest( url );
     }
 
     /**
@@ -456,7 +454,7 @@
         MockServletContext servletContext = (MockServletContext)getServletContext();
         if ( servletContext.getFilters().size() == 0 )
         {
-            initStripesServletContext();
+            initMockContext( servletContext );
         }
         return new MockRoundtrip( servletContext, beanClass );
     }
@@ -475,7 +473,7 @@
         MockServletContext servletContext = (MockServletContext)getServletContext();
         if ( servletContext.getFilters().size() == 0 )
         {
-            initStripesServletContext();
+            initMockContext( servletContext );
         }
         return new MockRoundtrip( servletContext, url );
     }
@@ -496,7 +494,7 @@
         MockServletContext servletContext = (MockServletContext)getServletContext();
         if ( servletContext.getFilters().size() == 0 )
         {
-            initStripesServletContext();
+            initMockContext( servletContext );
         }
         MockRoundtrip trip = new MockRoundtrip( servletContext, beanClass );
         WikiSession session = WikiSession.getWikiSession( this, trip.getRequest() );
@@ -505,24 +503,73 @@
     }
     
     /**
-     * Initializes the TestEngine's MockServletContext, with the Stripes filters and servlets
added
+     * Initializes a supplied MockServletContext with the Stripes filters and
+     * dummy servlet added.
+     * @param servletContext the mock context
+     * @return a configured MockFilterChain appropriate for the servlet context
      */
-    private void initStripesServletContext()
+    public static MockFilterChain initMockContext( MockServletContext servletContext )
     {
-        // Configure the filter and servlet
-        MockServletContext servletContext = (MockServletContext)getServletContext();
-        servletContext.addFilter( WikiServletFilter.class, "WikiServletFilter", new HashMap<String,String>()
);
-        servletContext.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
-        
-        // Add extension classes
+        // Configure the StripesFilter
         Map<String,String> filterParams = new HashMap<String,String>();
-        filterParams.put("ActionResolver.Packages", "org.apache.wiki.action");
-        filterParams.put("Extension.Packages", "org.apache.wiki.ui.stripes");
-        
-        // Add the exception handler class
+        filterParams.put( "ActionResolver.Packages", "org.apache.wiki.action" );
+        filterParams.put( "Extension.Packages", "org.apache.wiki.ui.stripes" );
         filterParams.put( "ExceptionHandler.Class", "org.apache.wiki.ui.stripes.WikiExceptionHandler"
);
+        servletContext.addFilter( StripesFilter.class, "StripesFilter", filterParams );
+        
+        // Configure the DynamicMappingFilter and dummy servlet
+        filterParams = new HashMap<String,String>();
+        servletContext.addFilter( DynamicMappingFilter.class, "DynamicMappingFilter", filterParams
);
+        servletContext.setServlet( MockServlet.class, "MockServlet", new HashMap<String,String>()
);
+        
+        // Create FilterConfig
+        MockFilterConfig filterConfig = new MockFilterConfig();
+        filterConfig.setFilterName( "TestFilterConfig" );
+        filterConfig.setServletContext( servletContext );
+        
+        // Create and return the FilterChain
+        MockFilterChain chain = new MockFilterChain();
+        List<Filter> filters = servletContext.getFilters();
+        for ( Filter f : filters )
+        {
+            chain.addFilter( f );
+        }
+        chain.setServlet( new MockServlet() );
+        return chain;
+    }
+
+    /**
+     * Dummy servlet that returns a {@link java.io.FileNotFoundException}
+     * when its {@link javax.servlet.Servlet#service(ServletRequest, ServletResponse)}
+     * method is called. This is very useful when used with
+     * {@link net.sourceforge.stripes.controller.DynamicMappingFilter}. 
+     */
+    public static class MockServlet extends HttpServlet
+    {
+        private static final long serialVersionUID = 1L;
+
+        private ServletConfig m_config;
         
-        // Return the configured servlet context
-        servletContext.addFilter(StripesFilter.class, "StripesFilter", filterParams);
+        public void destroy() { }
+
+        public ServletConfig getServletConfig()
+        {
+            return m_config;
+        }
+
+        public String getServletInfo()
+        {
+            return "Mock servlet";
+        }
+
+        public void init( ServletConfig config ) throws ServletException
+        {
+            m_config = config;
+        }
+
+        public void service( ServletRequest request, ServletResponse response ) throws ServletException,
IOException
+        {
+            throw new FileNotFoundException( "File not found: required for DynamicMappingFilter."
);
+        }
     }
 }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiSessionTest.java Fri Jan 22 03:59:38
2010
@@ -26,19 +26,19 @@
 import java.util.Properties;
 import java.util.Set;
 
-import javax.servlet.*;
+import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
-
-import net.sourceforge.stripes.mock.*;
+import net.sourceforge.stripes.mock.MockFilterChain;
+import net.sourceforge.stripes.mock.MockHttpServletRequest;
+import net.sourceforge.stripes.mock.MockHttpServletResponse;
+import net.sourceforge.stripes.mock.MockServletContext;
 
 import org.apache.commons.lang.ArrayUtils;
-import org.apache.wiki.WikiEngine;
-import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.auth.AuthenticationManager;
 import org.apache.wiki.auth.Users;
@@ -46,7 +46,6 @@
 import org.apache.wiki.auth.authorize.Role;
 import org.apache.wiki.auth.login.CookieAssertionLoginModule;
 import org.apache.wiki.auth.login.CookieAuthenticationLoginModule;
-import org.apache.wiki.ui.WikiServletFilter;
 
 
 public class WikiSessionTest extends TestCase
@@ -137,9 +136,9 @@
         // A naked HTTP request without userPrincipal/remoteUser should be anonymous
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( null );
-        runSecurityFilter(m_engine, request);
+        runSecurityFilter( m_engine, request );
         wikiSession = WikiSession.getWikiSession( m_engine, request );
-        assertTrue( wikiSession.isAnonymous());
+        assertTrue( wikiSession.isAnonymous() );
     }
     
     public void testUserPrincipal() throws ServletException, IOException
@@ -150,9 +149,9 @@
         // Changing the UserPrincipal value should cause the user to be authenticated...
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( new WikiPrincipal( "Fred Flintstone") );
-        runSecurityFilter(m_engine, request);
+        runSecurityFilter( m_engine, request );
         wikiSession = WikiSession.getWikiSession( m_engine, request );
-        assertTrue( wikiSession.isAuthenticated());
+        assertTrue( wikiSession.isAuthenticated() );
         assertEquals( "Fred Flintstone", wikiSession.getUserPrincipal().getName() );
     }
         
@@ -166,9 +165,9 @@
         request.setUserPrincipal( null );
         String cookieName = CookieAssertionLoginModule.PREFS_COOKIE_NAME;
         request.setCookies( new Cookie[] { new Cookie( cookieName, "FredFlintstone" ) } );
-        runSecurityFilter(m_engine, request);
+        runSecurityFilter( m_engine, request );
         wikiSession = WikiSession.getWikiSession( m_engine, request );
-        assertTrue( wikiSession.isAsserted());
+        assertTrue( wikiSession.isAsserted() );
         assertEquals( "FredFlintstone", wikiSession.getUserPrincipal().getName() );
     }
 
@@ -181,7 +180,7 @@
         MockHttpServletResponse response = new MockHttpServletResponse();
         CookieAuthenticationLoginModule.setLoginCookie( m_engine, response, "Fred Flintstone"
);
         Cookie[] cookies = response.getCookies();
-        assertEquals(1, cookies.length);
+        assertEquals( 1, cookies.length );
         String uid = cookies[0].getValue();
         
         // Adding the magic "authentication cookie" should NOT count as authenticated in
the default case
@@ -189,10 +188,10 @@
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( null );
         request.setCookies( new Cookie[] { new Cookie( "JSPWikiUID", uid ) } );
-        runSecurityFilter(m_engine, request);
+        runSecurityFilter( m_engine, request );
         wikiSession = WikiSession.getWikiSession( m_engine, request );
-        assertTrue( wikiSession.isAnonymous());
-        assertFalse( wikiSession.isAuthenticated());
+        assertTrue( wikiSession.isAnonymous() );
+        assertFalse( wikiSession.isAuthenticated() );
         assertEquals( "127.0.0.1", wikiSession.getUserPrincipal().getName() );
         
         // Clear the authentication cookie
@@ -216,17 +215,17 @@
         MockHttpServletResponse response = new MockHttpServletResponse();
         CookieAuthenticationLoginModule.setLoginCookie( m_engine, response, "Fred Flintstone"
);
         Cookie[] cookies = response.getCookies();
-        assertEquals(1, cookies.length);
+        assertEquals( 1, cookies.length );
         String uid = cookies[0].getValue();
         
         // Adding the magic "authentication cookie" should count as authenticated
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( null );
         request.setCookies( new Cookie[] { new Cookie( "JSPWikiUID", uid ) } );
-        runSecurityFilter(m_engine, request);
+        runSecurityFilter( m_engine, request );
         wikiSession = WikiSession.getWikiSession( m_engine, request );
-        assertFalse( wikiSession.isAnonymous());
-        assertTrue( wikiSession.isAuthenticated());
+        assertFalse( wikiSession.isAnonymous() );
+        assertTrue( wikiSession.isAuthenticated() );
         assertEquals( "Fred Flintstone", wikiSession.getUserPrincipal().getName() );
         
         // Clear the authentication cookie
@@ -284,7 +283,7 @@
         request.setCookies( new Cookie[] { cookie } );
         
         // Log in
-        runSecurityFilter(engine, request);
+        runSecurityFilter( engine, request );
         
         // Make sure the user is actually asserted
         WikiSession session = WikiSession.getWikiSession( engine, request );
@@ -302,7 +301,7 @@
         MockHttpServletRequest request = engine.newHttpRequest();
         
         // Log in as anon
-        runSecurityFilter(engine, request);
+        runSecurityFilter( engine, request );
         
         // Log in the user with credentials
         WikiSession session = WikiSession.getWikiSession( engine, request );
@@ -344,55 +343,21 @@
      * "Scaffolding" method that runs the session security filter on a mock request. We do
this by creating a
      * complete mock servlet context and filter chain, and running the request through it.

      * @param engine the wiki engine
-     * @param request the mock request to pass itnto the 
+     * @param request the mock request to pass into the chain
      * @throws ServletException
      * @throws IOException
      */
     private static void runSecurityFilter(WikiEngine engine, HttpServletRequest request)
throws ServletException, IOException
     {
         // Create a mock servlet context and stash the wiki engine in it
-        ServletContext servletCtx = new MockServletContext( "JSPWiki" );
+        MockServletContext servletCtx = new MockServletContext( "JSPWiki" );
         servletCtx.setAttribute( "org.apache.wiki.WikiEngine", engine );
         
-        // Create a mock filter configuration and add the servlet context we just created
-        MockFilterConfig filterConfig = new MockFilterConfig();
-        filterConfig.setFilterName( "WikiServletFilter" );
-        filterConfig.setServletContext( servletCtx );
-        
-        // Create the security filter and run the request  through it
-        Filter filter = new WikiServletFilter();
-        MockFilterChain chain = new MockFilterChain();
-        chain.addFilter( filter );
-        Servlet servlet = new MockServlet();
-        chain.setServlet( servlet );
-        filter.init(filterConfig);
-        filter.doFilter(request, null, chain );
+        // Init the mock filter configuration
+        MockFilterChain chain = TestEngine.initMockContext( servletCtx );
+        chain.doFilter( request, new MockHttpServletResponse() );
     }
 
-    private static class MockServlet implements Servlet
-    {
-        private ServletConfig m_config;
-        
-        public void destroy() { }
-
-        public ServletConfig getServletConfig()
-        {
-            return m_config;
-        }
-
-        public String getServletInfo()
-        {
-            return "Mock servlet";
-        }
-
-        public void init( ServletConfig config ) throws ServletException
-        {
-            m_config = config;
-        }
-
-        public void service( ServletRequest request, ServletResponse response ) throws ServletException,
IOException { }
-    }
-    
     public static Test suite() 
     {
         return new TestSuite( WikiSessionTest.class );

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java?rev=901980&r1=901979&r2=901980&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
(original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/stripes/ShortUrlRedirectFilterTest.java
Fri Jan 22 03:59:38 2010
@@ -20,17 +20,13 @@
  */
 package org.apache.wiki.ui.stripes;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
-import net.sourceforge.stripes.controller.DispatcherServlet;
-import net.sourceforge.stripes.controller.StripesFilter;
 import net.sourceforge.stripes.mock.MockRoundtrip;
 import net.sourceforge.stripes.mock.MockServletContext;
 
+import org.apache.wiki.TestEngine;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.action.ViewActionBean;
 
@@ -43,14 +39,7 @@
     {
         // Configure the filter and servlet
         MockServletContext servletContext = new MockServletContext( "test" );
-        servletContext.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
-        
-        // Add extension classes
-        Map<String,String> filterParams = new HashMap<String,String>();
-        filterParams.put("ActionResolver.Packages", "org.apache.wiki.action");
-        filterParams.put("Extension.Packages", "org.apache.wiki.ui.stripes");
-        filterParams.put( "ExceptionHandler.Class", "org.apache.wiki.ui.stripes.WikiExceptionHandler"
);
-        servletContext.addFilter(StripesFilter.class, "StripesFilter", filterParams);
+        TestEngine.initMockContext( servletContext );
         servletContext.addFilter( ShortUrlRedirectFilter.class, "Redirect filter", null );
 
         // Set the configured servlet context



Mime
View raw message