This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit dd84c1ab39555fc2d0aa3e9ef31fad738ec2188a
Author: juanpablo <[email protected]>
AuthorDate: Fri Mar 27 18:45:29 2020 +0100

    JSPWIKI-303: add session spi and use it throughout the code
---
 .../java/org/apache/wiki/api/spi/SessionDSL.java   | 76 ++++++++++++++++++++++
 .../java/org/apache/wiki/api/spi/SessionSPI.java   | 64 ++++++++++++++++++
 .../main/java/org/apache/wiki/api/spi/Wiki.java    |  8 +++
 .../wiki/auth/DefaultAuthenticationManager.java    |  6 +-
 .../java/org/apache/wiki/auth/SessionMonitor.java  |  6 +-
 .../auth/login/WebContainerCallbackHandler.java    |  2 +-
 .../org/apache/wiki/spi/SessionSPIDefaultImpl.java | 60 +++++++++++++++++
 .../java/org/apache/wiki/tags/UserNameTag.java     | 11 ++--
 .../java/org/apache/wiki/tags/UserProfileTag.java  | 10 +--
 .../services/org.apache.wiki.api.spi.SessionSPI    |  1 +
 .../test/java/org/apache/wiki/WikiSessionTest.java | 21 +++---
 11 files changed, 238 insertions(+), 27 deletions(-)

diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionDSL.java 
b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionDSL.java
new file mode 100644
index 0000000..fe57ce0
--- /dev/null
+++ b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionDSL.java
@@ -0,0 +1,76 @@
+/*
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+ */
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Session;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * SPI used to locate and provide {@link Session} instances.
+ */
+public class SessionDSL {
+
+    private final SessionSPI sessionSPI;
+
+    SessionDSL( final SessionSPI sessionSPI ) {
+        this.sessionSPI = sessionSPI;
+    }
+
+    /**
+     * Removes the wiki session associated with the user's HTTP request from 
the cache of wiki sessions, typically as part of a logout process.
+     *
+     * @param engine the wiki engine
+     * @param request the users's HTTP request
+     */
+    public void remove( final Engine engine, final HttpServletRequest request 
) {
+        sessionSPI.remove( engine, request );
+    }
+
+    /**
+     * <p>Returns the Session object associated with the current HTTP request. 
If not found, one is created.
+     * This method is guaranteed to always return a Session, although the 
authentication status is unpredictable until the user
+     * attempts to log in. If the servlet request parameter is 
<code>null</code>, a synthetic {@link #guest(Engine)} is
+     * returned.</p>
+     * <p>When a session is created, this method attaches a WikiEventListener 
to the GroupManager, UserManager and AuthenticationManager,
+     * so that changes to users, groups, logins, etc. are detected 
automatically.</p>
+     *
+     * @param engine the engine
+     * @param request the servlet request object
+     * @return the existing (or newly created) session
+     */
+    public Session find( final Engine engine, final HttpServletRequest request 
) {
+        return sessionSPI.find( engine, request );
+    }
+
+    /**
+     * Creates a new "guest" session containing a single user Principal {@code 
org.apache.wiki.auth.WikiPrincipal#GUEST}, plus the role
+     * principals {@code Role#ALL} and {@code Role#ANONYMOUS}. This method 
also adds the session as a listener for GroupManager,
+     * AuthenticationManager and UserManager events.
+     *
+     * @param engine the wiki engine
+     * @return the guest wiki session
+     */
+    public Session guest( final Engine engine ) {
+        return sessionSPI.guest( engine );
+    }
+
+}
diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionSPI.java 
b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionSPI.java
new file mode 100644
index 0000000..f0c5f15
--- /dev/null
+++ b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/SessionSPI.java
@@ -0,0 +1,64 @@
+/*
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+ */
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Session;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * SPI used to locate and provide {@link Session} instances.
+ */
+public interface SessionSPI {
+
+    /**
+     * Removes the wiki session associated with the user's HTTP request from 
the cache of wiki sessions, typically as part of a logout process.
+     *
+     * @param engine the wiki engine
+     * @param request the users's HTTP request
+     */
+    void remove( Engine engine, HttpServletRequest request );
+
+    /**
+     * <p>Returns the Session object associated with the current HTTP request. 
If not found, one is created.
+     * This method is guaranteed to always return a Session, although the 
authentication status is unpredictable until the user
+     * attempts to log in. If the servlet request parameter is 
<code>null</code>, a synthetic {@link #guest(Engine)} is
+     * returned.</p>
+     * <p>When a session is created, this method attaches a WikiEventListener 
to the GroupManager, UserManager and AuthenticationManager,
+     * so that changes to users, groups, logins, etc. are detected 
automatically.</p>
+     *
+     * @param engine the engine
+     * @param request the servlet request object
+     * @return the existing (or newly created) session
+     */
+    Session find( Engine engine, HttpServletRequest request );
+
+    /**
+     * Creates a new "guest" session containing a single user Principal {@code 
org.apache.wiki.auth.WikiPrincipal#GUEST}, plus the role
+     * principals {@code Role#ALL} and {@code Role#ANONYMOUS}. This method 
also adds the session as a listener for GroupManager,
+     * AuthenticationManager and UserManager events.
+     *
+     * @param engine the wiki engine
+     * @return the guest wiki session
+     */
+    Session guest( Engine engine );
+
+}
diff --git a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/Wiki.java 
b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/Wiki.java
index e31732c..a0e3e6b 100644
--- a/jspwiki-api/src/main/java/org/apache/wiki/api/spi/Wiki.java
+++ b/jspwiki-api/src/main/java/org/apache/wiki/api/spi/Wiki.java
@@ -31,18 +31,22 @@ public class Wiki {
 
     private static final String PROP_PROVIDER_IMPL_CONTEXT = 
"jspwiki.provider.impl.context";
     private static final String PROP_PROVIDER_IMPL_ENGINE = 
"jspwiki.provider.impl.engine";
+    private static final String PROP_PROVIDER_IMPL_SESSION = 
"jspwiki.provider.impl.session";
     private static final String DEFAULT_PROVIDER_IMPL_CONTEXT = 
"org.apache.wiki.spi.ContextSPIDefaultImpl";
     private static final String DEFAULT_PROVIDER_IMPL_ENGINE = 
"org.apache.wiki.spi.EngineSPIDefaultImpl";
+    private static final String DEFAULT_PROVIDER_IMPL_SESSION = 
"org.apache.wiki.spi.SessionSPIDefaultImpl";
 
     // default values
     private static Properties properties = 
PropertyReader.getDefaultProperties();
     private static ContextSPI contextSPI = getSPI( ContextSPI.class, 
properties, PROP_PROVIDER_IMPL_CONTEXT, DEFAULT_PROVIDER_IMPL_CONTEXT );
     private static EngineSPI engineSPI = getSPI( EngineSPI.class, properties, 
PROP_PROVIDER_IMPL_ENGINE, DEFAULT_PROVIDER_IMPL_ENGINE );
+    private static SessionSPI sessionSPI = getSPI( SessionSPI.class, 
properties, PROP_PROVIDER_IMPL_SESSION, DEFAULT_PROVIDER_IMPL_SESSION );
 
     static void init( final ServletContext context ) {
         properties = PropertyReader.loadWebAppProps( context );
         contextSPI = getSPI( ContextSPI.class, properties, 
PROP_PROVIDER_IMPL_CONTEXT, DEFAULT_PROVIDER_IMPL_CONTEXT );
         engineSPI = getSPI( EngineSPI.class, properties, 
PROP_PROVIDER_IMPL_ENGINE, DEFAULT_PROVIDER_IMPL_ENGINE );
+        sessionSPI = getSPI( SessionSPI.class, properties, 
PROP_PROVIDER_IMPL_SESSION, DEFAULT_PROVIDER_IMPL_SESSION );
     }
 
     public static ContextDSL context() {
@@ -53,6 +57,10 @@ public class Wiki {
         return new EngineDSL( engineSPI );
     }
 
+    public static SessionDSL session() {
+        return new SessionDSL( sessionSPI );
+    }
+
     static < SPI > SPI getSPI( final Class< SPI > spi, final Properties props, 
final String prop, final String defValue ) {
         final String providerImpl = TextUtil.getStringProperty( props, prop, 
defValue );
         final ServiceLoader< SPI > loader = ServiceLoader.load( spi );
diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java
 
b/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java
index b46b227..cb60827 100644
--- 
a/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java
+++ 
b/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java
@@ -19,10 +19,10 @@
 package org.apache.wiki.auth;
 
 import org.apache.log4j.Logger;
-import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.core.Engine;
 import org.apache.wiki.api.core.Session;
 import org.apache.wiki.api.exceptions.WikiException;
+import org.apache.wiki.api.spi.Wiki;
 import org.apache.wiki.auth.authorize.WebAuthorizer;
 import org.apache.wiki.auth.authorize.WebContainerAuthorizer;
 import org.apache.wiki.auth.login.AnonymousLoginModule;
@@ -277,12 +277,12 @@ public class DefaultAuthenticationManager implements 
AuthenticationManager {
             log.debug( "Invalidating Session for session ID=" + sid );
         }
         // Retrieve the associated Session and clear the Principal set
-        final Session wikiSession = WikiSession.getWikiSession( m_engine, 
request );
+        final Session wikiSession = Wiki.session().find( m_engine, request );
         final Principal originalPrincipal = wikiSession.getLoginPrincipal();
         wikiSession.invalidate();
 
         // Remove the wikiSession from the WikiSession cache
-        WikiSession.removeWikiSession( m_engine, request );
+        Wiki.session().remove( m_engine, request );
 
         // We need to flush the HTTP session too
         if( session != null ) {
diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java 
b/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java
index 155d235..074cc3d 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java
@@ -19,9 +19,9 @@
 package org.apache.wiki.auth;
 
 import org.apache.log4j.Logger;
-import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.core.Engine;
 import org.apache.wiki.api.core.Session;
+import org.apache.wiki.api.spi.Wiki;
 import org.apache.wiki.event.WikiEventListener;
 import org.apache.wiki.event.WikiEventManager;
 import org.apache.wiki.event.WikiSecurityEvent;
@@ -110,7 +110,7 @@ public class SessionMonitor implements HttpSessionListener {
     }
     /**
      * <p>Looks up the wiki session associated with a user's Http session and 
adds it to the session cache. This method will return the
-     * "guest session" as constructed by {@link 
org.apache.wiki.WikiSession#guestSession(Engine)} if the HttpSession is not 
currently
+     * "guest session" as constructed by {@link 
org.apache.wiki.api.spi.SessionSPI#guest(Engine)} if the HttpSession is not 
currently
      * associated with a WikiSession. This method is guaranteed to return a 
non-<code>null</code> WikiSession.</p>
      * <p>Internally, the session is stored in a HashMap; keys are the 
HttpSession objects, while the values are
      * {@link java.lang.ref.WeakReference}-wrapped WikiSessions.</p>
@@ -127,7 +127,7 @@ public class SessionMonitor implements HttpSessionListener {
             if( log.isDebugEnabled() ) {
                 log.debug( "Looking up WikiSession for session ID=" + sid + 
"... not found. Creating guestSession()" );
             }
-            wikiSession = WikiSession.guestSession( m_engine );
+            wikiSession = Wiki.session().guest( m_engine );
             synchronized( m_sessions ) {
                 m_sessions.put( sid, wikiSession );
             }
diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerCallbackHandler.java
 
b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerCallbackHandler.java
index c217551..85e7f8a 100644
--- 
a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerCallbackHandler.java
+++ 
b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerCallbackHandler.java
@@ -30,7 +30,7 @@ import java.io.IOException;
 /**
  * Handles logins made from within JSPWiki.
  *
- * @see org.apache.wiki.WikiSession#getWikiSession(Engine,HttpServletRequest)
+ * @see org.apache.wiki.api.spi.SessionSPI#find(Engine, HttpServletRequest)
  * @since 2.3
  */
 public final class WebContainerCallbackHandler implements CallbackHandler {
diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/spi/SessionSPIDefaultImpl.java 
b/jspwiki-main/src/main/java/org/apache/wiki/spi/SessionSPIDefaultImpl.java
new file mode 100644
index 0000000..b05f037
--- /dev/null
+++ b/jspwiki-main/src/main/java/org/apache/wiki/spi/SessionSPIDefaultImpl.java
@@ -0,0 +1,60 @@
+/*
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+ */
+package org.apache.wiki.spi;
+
+import org.apache.wiki.WikiSession;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Session;
+import org.apache.wiki.api.spi.SessionSPI;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+/**
+ * Default implementation for {@link SessionSPI}
+ *
+ * @see SessionSPI
+ */
+public class SessionSPIDefaultImpl implements SessionSPI {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void remove( final Engine engine, final HttpServletRequest request 
) {
+        WikiSession.removeWikiSession( engine, request );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Session find( final Engine engine, final HttpServletRequest request 
) {
+        return WikiSession.getWikiSession( engine, request );
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Session guest( final Engine engine ) {
+        return WikiSession.guestSession( engine );
+    }
+
+}
diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserNameTag.java 
b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserNameTag.java
index ee06f49..88227f2 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserNameTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserNameTag.java
@@ -18,9 +18,9 @@
  */
 package org.apache.wiki.tags;
 
-import org.apache.wiki.WikiSession;
 import org.apache.wiki.api.core.Engine;
 import org.apache.wiki.api.core.Session;
+import org.apache.wiki.api.spi.Wiki;
 import org.apache.wiki.i18n.InternationalizationManager;
 import org.apache.wiki.preferences.Preferences;
 import org.apache.wiki.util.TextUtil;
@@ -40,15 +40,16 @@ public class UserNameTag extends WikiTagBase {
 
     private static final long serialVersionUID = 0L;
 
-    private static String notStartWithBlankOrColon = "^[^( |:)]";
+    private static final String notStartWithBlankOrColon = "^[^( |:)]";
 
-    private static String noColons = "[^:]*";
+    private static final String noColons = "[^:]*";
 
     private static final Pattern VALID_USER_NAME_PATTERN = 
Pattern.compile(notStartWithBlankOrColon + noColons);
 
-    @Override public final int doWikiStartTag() throws IOException {
+    @Override
+    public final int doWikiStartTag() throws IOException {
         final Engine engine = m_wikiContext.getEngine();
-        final Session wikiSession = WikiSession.getWikiSession(engine, 
(HttpServletRequest) pageContext.getRequest());
+        final Session wikiSession = Wiki.session().find( engine, ( 
HttpServletRequest )pageContext.getRequest() );
         final Principal user = wikiSession.getUserPrincipal();
 
         if( user != null ) {
diff --git 
a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java 
b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java
index f019c85..01c0f6b 100644
--- a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java
+++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java
@@ -18,10 +18,10 @@
  */
 package org.apache.wiki.tags;
 
-import org.apache.wiki.WikiContext;
-import org.apache.wiki.WikiSession;
+import org.apache.wiki.api.core.Context;
 import org.apache.wiki.api.core.Engine;
 import org.apache.wiki.api.core.Session;
+import org.apache.wiki.api.spi.Wiki;
 import org.apache.wiki.auth.AuthenticationManager;
 import org.apache.wiki.auth.GroupPrincipal;
 import org.apache.wiki.auth.UserManager;
@@ -131,7 +131,7 @@ public class UserProfileTag extends WikiTagBase {
                 //  Default back to the declared user name
                 //
                 final Engine engine = this.m_wikiContext.getEngine();
-                final Session wikiSession = WikiSession.getWikiSession( 
engine, ( HttpServletRequest )pageContext.getRequest() );
+                final Session wikiSession = Wiki.session().find( engine, ( 
HttpServletRequest )pageContext.getRequest() );
                 final Principal user = wikiSession.getUserPrincipal();
 
                 if( user != null ) {
@@ -168,7 +168,7 @@ public class UserProfileTag extends WikiTagBase {
      * and extracting those that are of type Group.
      * @return the list of groups, sorted by name
      */
-    public static String printGroups( final WikiContext context ) {
+    public static String printGroups( final Context context ) {
         final Principal[] roles = context.getWikiSession().getRoles();
         final List< String > tempRoles = new ArrayList<>();
         final ResourceBundle rb = Preferences.getBundle( context, 
InternationalizationManager.CORE_BUNDLE );
@@ -203,7 +203,7 @@ public class UserProfileTag extends WikiTagBase {
      * and extracting those that are of type Role.
      * @return the list of roles, sorted by name
      */
-    public static String printRoles( final WikiContext context ) {
+    public static String printRoles( final Context context ) {
         final Principal[] roles = context.getWikiSession().getRoles();
         final List< String > tempRoles = new ArrayList<>();
         final ResourceBundle rb = Preferences.getBundle( context, 
InternationalizationManager.CORE_BUNDLE );
diff --git 
a/jspwiki-main/src/main/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
 
b/jspwiki-main/src/main/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
new file mode 100644
index 0000000..f854a6c
--- /dev/null
+++ 
b/jspwiki-main/src/main/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
@@ -0,0 +1 @@
+org.apache.wiki.spi.SessionSPIDefaultImpl
\ No newline at end of file
diff --git a/jspwiki-main/src/test/java/org/apache/wiki/WikiSessionTest.java 
b/jspwiki-main/src/test/java/org/apache/wiki/WikiSessionTest.java
index a49ca99..6a810ca 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/WikiSessionTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/WikiSessionTest.java
@@ -26,6 +26,7 @@ import net.sourceforge.stripes.mock.MockServletContext;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.wiki.api.core.Session;
 import org.apache.wiki.api.exceptions.WikiException;
+import org.apache.wiki.api.spi.Wiki;
 import org.apache.wiki.auth.AuthenticationManager;
 import org.apache.wiki.auth.Users;
 import org.apache.wiki.auth.WikiPrincipal;
@@ -71,7 +72,7 @@ public class WikiSessionTest
         Principal[] principals;
 
         // Test roles for guest session
-        session = WikiSession.guestSession( m_engine );
+        session = Wiki.session().guest( m_engine );
         principals = session.getRoles();
         Assertions.assertTrue(  session.isAnonymous() );
         Assertions.assertFalse( session.isAuthenticated() );
@@ -124,7 +125,7 @@ public class WikiSessionTest
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( null );
         runSecurityFilter(m_engine, request);
-        wikiSession = WikiSession.getWikiSession( m_engine, request );
+        wikiSession = Wiki.session().find( m_engine, request );
         Assertions.assertTrue( wikiSession.isAnonymous());
     }
 
@@ -138,7 +139,7 @@ public class WikiSessionTest
         request = m_engine.newHttpRequest();
         request.setUserPrincipal( new WikiPrincipal( "Fred Flintstone") );
         runSecurityFilter(m_engine, request);
-        wikiSession = WikiSession.getWikiSession( m_engine, request );
+        wikiSession = Wiki.session().find( m_engine, request );
         Assertions.assertTrue( wikiSession.isAuthenticated());
         Assertions.assertEquals( "Fred Flintstone", 
wikiSession.getUserPrincipal().getName() );
     }
@@ -155,7 +156,7 @@ public class WikiSessionTest
         final String cookieName = CookieAssertionLoginModule.PREFS_COOKIE_NAME;
         request.setCookies( new Cookie[] { new Cookie( cookieName, 
"FredFlintstone" ) } );
         runSecurityFilter(m_engine, request);
-        wikiSession = WikiSession.getWikiSession( m_engine, request );
+        wikiSession = Wiki.session().find( m_engine, request );
         Assertions.assertTrue( wikiSession.isAsserted());
         Assertions.assertEquals( "FredFlintstone", 
wikiSession.getUserPrincipal().getName() );
     }
@@ -179,7 +180,7 @@ public class WikiSessionTest
         request.setUserPrincipal( null );
         request.setCookies( new Cookie[] { new Cookie( "JSPWikiUID", uid ) } );
         runSecurityFilter(m_engine, request);
-        wikiSession = WikiSession.getWikiSession( m_engine, request );
+        wikiSession = Wiki.session().find( m_engine, request );
         Assertions.assertTrue( wikiSession.isAnonymous());
         Assertions.assertFalse( wikiSession.isAuthenticated());
         Assertions.assertEquals( "127.0.0.1", 
wikiSession.getUserPrincipal().getName() );
@@ -211,7 +212,7 @@ public class WikiSessionTest
         request.setUserPrincipal( null );
         request.setCookies( new Cookie[] { new Cookie( "JSPWikiUID", uid ) } );
         runSecurityFilter(m_engine, request);
-        wikiSession = WikiSession.getWikiSession( m_engine, request );
+        wikiSession = Wiki.session().find( m_engine, request );
         Assertions.assertFalse( wikiSession.isAnonymous());
         Assertions.assertTrue( wikiSession.isAuthenticated());
         Assertions.assertEquals( "Fred Flintstone", 
wikiSession.getUserPrincipal().getName() );
@@ -236,7 +237,7 @@ public class WikiSessionTest
         runSecurityFilter( engine, request );
 
         // Make sure the user is actually anonymous
-        final Session session = WikiSession.getWikiSession( engine, request );
+        final Session session = Wiki.session().find( engine, request );
         if ( !session.isAnonymous() )
         {
             throw new IllegalStateException( "Session is not anonymous." );
@@ -274,7 +275,7 @@ public class WikiSessionTest
         runSecurityFilter(engine, request);
 
         // Make sure the user is actually asserted
-        return WikiSession.getWikiSession( engine, request );
+        return Wiki.session().find( engine, request );
     }
 
     public static Session adminSession( final TestEngine engine ) throws 
Exception
@@ -291,7 +292,7 @@ public class WikiSessionTest
         runSecurityFilter(engine, request);
 
         // Log in the user with credentials
-        final Session session = WikiSession.getWikiSession( engine, request );
+        final Session session = Wiki.session().find( engine, request );
         engine.getManager( AuthenticationManager.class ).login( session, 
request, id, password );
 
         // Make sure the user is actually authenticated
@@ -318,7 +319,7 @@ public class WikiSessionTest
         runSecurityFilter(engine,request);
 
         // Make sure the user is actually authenticated
-        final Session session = WikiSession.getWikiSession( engine, request );
+        final Session session = Wiki.session().find( engine, request );
         if ( !session.isAuthenticated() )
         {
             throw new IllegalStateException( "Could not log in authenticated 
user '" + id + "'" );

Reply via email to