jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r682151 [2/4] - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki: ./ action/ attachment/ auth/ auth/acl/ auth/authorize/ auth/login/ auth/user/ content/ diff/ parser/ plugin/ providers/ render/ rss/ search/ ...
Date Sun, 03 Aug 2008 12:28:11 GMT
Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/WikiActionBeanFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/WikiActionBeanFactoryTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/WikiActionBeanFactoryTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/WikiActionBeanFactoryTest.java Sun Aug  3 05:28:09 2008
@@ -16,7 +16,6 @@
 import net.sourceforge.stripes.mock.MockRoundtrip;
 
 import com.ecyrd.jspwiki.*;
-import com.ecyrd.jspwiki.action.*;
 
 public class WikiActionBeanFactoryTest extends TestCase
 {
@@ -39,40 +38,54 @@
         testEngine.deletePage( "TestPage" );
     }
     
-    public void testGetUrlPatterns()
-    {
-        // If we look for action with "edit" request context, we get EDIT action
-        assertEquals( WikiContext.EDIT, EditActionBean.class.getAnnotation(WikiRequestContext.class).value() );
-        
-        // Ditto for prefs context
-        assertEquals( WikiContext.PREFS, UserPreferencesActionBean.class.getAnnotation(WikiRequestContext.class).value() );
-        
-        // Ditto for group view context
-        assertEquals( WikiContext.VIEW_GROUP, GroupActionBean.class.getAnnotation(WikiRequestContext.class).value() );
-    }
-    
-    public void testActionBeansNoParams() throws WikiException
+    public void testNewActionBean() throws WikiException
     {
         WikiActionBean bean;
         MockRoundtrip trip = testEngine.guestTrip( ViewActionBean.class );
         MockHttpServletRequest request = trip.getRequest();
         MockHttpServletResponse response = trip.getResponse();
-        MockHttpSession session = (MockHttpSession)request.getSession();
         
-        // Passing an EDIT request with no explicit page params means the EDIT action
+        // Supplying an EditActionBean means the EDIT action
         bean = resolver.newActionBean( request, response, EditActionBean.class );
         assertEquals( WikiContext.EDIT, bean.getRequestContext() );
         assertNull( ((WikiContext)bean).getPage() );
         
-        // Ditto for prefs context
+        // Change the context to "preview"
+        bean.setRequestContext( WikiContext.PREVIEW );
+        assertEquals( WikiContext.PREVIEW, bean.getRequestContext() );
+        
+        // Change the context to "diff"
+        bean.setRequestContext( WikiContext.DIFF);
+        assertEquals( WikiContext.DIFF, bean.getRequestContext() );
+        
+        // Try changing the context to "comment" (but, this is an error)
+        try
+        {
+            bean.setRequestContext( WikiContext.COMMENT);
+        }
+        catch ( IllegalArgumentException e )
+        {
+            // Excellent. This what we expect.
+        }
+        
+        // Supplying the PrefsActionBean means the PREFS context
         bean = resolver.newActionBean( request, response, UserPreferencesActionBean.class );
         assertEquals( WikiContext.PREFS, bean.getRequestContext() );
         
-        // Ditto for group view context
+        // Supplying the GroupActionBean means the VIEW_GROUP context
         bean = resolver.newActionBean( request, response, GroupActionBean.class );
         assertEquals( WikiContext.VIEW_GROUP, bean.getRequestContext() );
-        assertNull( ((GroupContext)bean).getGroup() );
-        
+        assertNull( ((GroupActionBean)bean).getGroup() );
+    }
+    
+    public void testNewActionBeanByJSP() throws WikiException
+    {
+        WikiActionBean bean;
+        MockRoundtrip trip = testEngine.guestTrip( ViewActionBean.class );
+        MockHttpServletRequest request = trip.getRequest();
+        MockHttpServletResponse response = trip.getResponse();
+        MockHttpSession session = (MockHttpSession)request.getSession();
+
         // Request for "UserPreference.jsp" should resolve to PREFS action
         request = new MockHttpServletRequest( testEngine.getServletContext().getServletContextName(), "/UserPreferences.jsp");
         request.setSession( session );
@@ -119,7 +132,7 @@
         request.getParameterMap().put( "group", new String[]{"Art"} );
         bean = resolver.newActionBean( request, response, GroupActionBean.class );
         assertEquals( WikiContext.VIEW_GROUP, bean.getRequestContext() );
-        assertEquals( "/Group.action", bean.getClass().getAnnotation(UrlBinding.class).value() );
+        assertEquals( "/Group.jsp", bean.getClass().getAnnotation(UrlBinding.class).value() );
     }
     
     public void testFinalPageName() throws Exception

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java Sun Aug  3 05:28:09 2008
@@ -1,11 +1,19 @@
 
 package com.ecyrd.jspwiki.attachment;
 
-import junit.framework.*;
 import java.io.*;
-import java.util.*;
+import java.util.Collection;
+import java.util.Properties;
 
-import com.ecyrd.jspwiki.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.FileUtil;
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.providers.ProviderException;
 
 public class AttachmentManagerTest extends TestCase
 {
@@ -77,7 +85,7 @@
         m_manager.storeAttachment( att, makeAttachmentFile() );
 
         Attachment att2 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                       new WikiPage(m_engine, NAME1)), 
+                                                       null, null, new WikiPage(m_engine, NAME1)), 
                                                        "test1.txt" );
 
         assertNotNull( "attachment disappeared", att2 );
@@ -108,7 +116,7 @@
         m_manager.storeAttachment( att, makeAttachmentFile() );
 
         Attachment att2 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                                          new WikiPage(m_engine, NAME1)), 
+                                                                          null, null, new WikiPage(m_engine, NAME1)), 
                                                        "test file.txt" );
 
         assertNotNull( "attachment disappeared", att2 );
@@ -139,7 +147,7 @@
         m_manager.storeAttachment( att, makeAttachmentFile() );
 
         Attachment att2 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                                          new WikiPage(m_engine, NAME1)), 
+                                                                          null, null, new WikiPage(m_engine, NAME1)), 
                                                        "test1.txt", 1 );
 
         assertNotNull( "attachment disappeared", att2 );
@@ -174,7 +182,7 @@
         m_manager.storeAttachment( att, makeAttachmentFile() );        
 
         Attachment att2 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                                          new WikiPage(m_engine, NAME1)), 
+                                                                          null, null, new WikiPage(m_engine, NAME1)), 
                                                        "test1.txt" );
 
         assertNotNull( "attachment disappeared", att2 );
@@ -200,7 +208,7 @@
         //
 
         Attachment att3 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                                          new WikiPage(m_engine, NAME1)), 
+                                                                          null, null, new WikiPage(m_engine, NAME1)), 
                                                        "test1.txt",
                                                        1 );
         assertEquals( "version of v1", 1, att3.getVersion() );
@@ -235,7 +243,7 @@
         m_manager.storeAttachment( att, makeAttachmentFile() );
 
         Attachment att2 = m_manager.getAttachmentInfo( m_engine.getWikiActionBeanFactory().newViewActionBean(
-                                                                          new WikiPage(m_engine, NAME1)),
+                                                                          null, null, new WikiPage(m_engine, NAME1)),
                                                        "test1" );
 
         assertNotNull( "attachment disappeared", att2 );
@@ -318,6 +326,36 @@
                     m_engine.pageExists( att.getName() ) );
     }
 
+    public void testNonexistantPage() throws Exception
+    {
+        try
+        {
+            m_engine.saveText( "TestPage", "xx" );
+        
+            Attachment att = new Attachment( m_engine, "TestPages", "foo.bin" );
+        
+            att.setAuthor("MonicaBellucci");
+            m_manager.storeAttachment( att, makeAttachmentFile() );
+        
+            fail("Attachment was stored even when the page does not exist");
+        }
+        catch( ProviderException ex )
+        {
+            // This is the intended exception
+        }
+        finally
+        {
+            m_engine.deletePage("TestPage");
+        }
+    }
+    
+    public void testValidateFileName() throws Exception
+    {
+        assertEquals( "foo.jpg", "foo.jpg", AttachmentManager.validateFileName( "foo.jpg" ) );
+        
+        assertEquals( "C:\\Windows\\test.jpg", "test.jpg", AttachmentManager.validateFileName( "C:\\Windows\\test.jpg" ));
+    }
+    
     public static Test suite()
     {
         return new TestSuite( AttachmentManagerTest.class );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AllTests.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AllTests.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AllTests.java Sun Aug  3 05:28:09 2008
@@ -1,9 +1,9 @@
 
 package com.ecyrd.jspwiki.auth;
 
-import com.ecyrd.jspwiki.TextUtil;
-
-import junit.framework.*;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
 
 public class AllTests extends TestCase
 {
@@ -16,20 +16,15 @@
     {
         TestSuite suite = new TestSuite("AAA package tests");
 
-        String runTests = System.getProperty( "jspwiki.tests.auth", "false" );
-        
-        if( TextUtil.isPositive(runTests) )
-        {
-            suite.addTest( AuthenticationManagerTest.suite() );
-            suite.addTest( AuthorizationManagerTest.suite() );
-            suite.addTest( GroupManagerTest.suite() );
-            suite.addTest( com.ecyrd.jspwiki.auth.acl.AllTests.suite() );
-            suite.addTest( com.ecyrd.jspwiki.auth.authorize.AllTests.suite() );
-            suite.addTest( com.ecyrd.jspwiki.auth.login.AllTests.suite() );
-            suite.addTest( com.ecyrd.jspwiki.auth.permissions.AllTests.suite() );
-            suite.addTest( com.ecyrd.jspwiki.auth.user.AllTests.suite() );
-            suite.addTestSuite( com.ecyrd.jspwiki.auth.UserManagerTest.class );
-        }
+        suite.addTest( AuthenticationManagerTest.suite() );
+        suite.addTest( AuthorizationManagerTest.suite() );
+        suite.addTest( GroupManagerTest.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.acl.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.authorize.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.login.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.permissions.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.user.AllTests.suite() );
+        suite.addTestSuite( com.ecyrd.jspwiki.auth.UserManagerTest.class );
         
         return suite;
     }

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthenticationManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthenticationManagerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthenticationManagerTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthenticationManagerTest.java Sun Aug  3 05:28:09 2008
@@ -1,6 +1,27 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth;
 
 import java.security.Principal;
+import java.util.Map;
 import java.util.Properties;
 
 import junit.framework.Test;
@@ -8,11 +29,13 @@
 import junit.framework.TestSuite;
 
 import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiEngine;
 import com.ecyrd.jspwiki.WikiSession;
 import com.ecyrd.jspwiki.WikiSessionTest;
 import com.ecyrd.jspwiki.auth.authorize.Group;
 import com.ecyrd.jspwiki.auth.authorize.GroupManager;
 import com.ecyrd.jspwiki.auth.authorize.Role;
+import com.ecyrd.jspwiki.auth.login.CookieAssertionLoginModule;
 
 /**
  * Tests the AuthorizationManager class.
@@ -51,6 +74,43 @@
         assertFalse( AuthenticationManager.isUserPrincipal( Role.ANONYMOUS ) );
     }
     
+    public void testCustomJAASLoginModule() throws Exception
+    {
+        Properties props = new Properties();
+        props.load( TestEngine.findTestProperties() );
+
+        // Supply a custom LoginModule class
+        props.put( "jspwiki.loginModule.class", "com.ecyrd.jspwiki.auth.login.CookieAssertionLoginModule" );
+
+        // Init the engine and verify that we initialized with a custom auth login module
+        WikiEngine engine = new TestEngine( props );
+        AuthenticationManager authMgr= engine.getAuthenticationManager();
+        assertEquals( CookieAssertionLoginModule.class, authMgr.m_loginModuleClass );
+    }
+
+    public void testCustomJAASLoginModuleOptions() throws Exception
+    {
+        Properties props = new Properties();
+        props.load( TestEngine.findTestProperties() );
+        
+        // Supply a custom LoginModule options
+        props.put( "jspwiki.loginModule.options.key1", "value1" );
+        props.put( "jspwiki.loginModule.options.key2", "value2" );
+        props.put( "jspwiki.loginModule.options.key3", "value3" );
+        
+        // Init the engine and verify that we initialized with the correct options
+        WikiEngine engine = new TestEngine( props );
+        AuthenticationManager authMgr= engine.getAuthenticationManager();
+        Map<String,String> options = authMgr.m_loginModuleOptions;
+        assertEquals( 3, options.size() );
+        assertTrue( options.containsKey( "key1" ) );
+        assertTrue( options.containsKey( "key2" ) );
+        assertTrue( options.containsKey( "key3" ) );
+        assertEquals( "value1", options.get( "key1") );
+        assertEquals( "value2", options.get( "key2") );
+        assertEquals( "value3", options.get( "key3") );
+    }
+
     public void testLoginCustom() throws Exception
     {
         WikiSession session = WikiSessionTest.authenticatedSession( m_engine, Users.JANNE, Users.JANNE_PASS );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java Sun Aug  3 05:28:09 2008
@@ -11,11 +11,7 @@
 
 import org.apache.commons.lang.ArrayUtils;
 
-import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.WikiException;
-import com.ecyrd.jspwiki.WikiPage;
-import com.ecyrd.jspwiki.WikiSession;
-import com.ecyrd.jspwiki.WikiSessionTest;
+import com.ecyrd.jspwiki.*;
 import com.ecyrd.jspwiki.attachment.Attachment;
 import com.ecyrd.jspwiki.auth.acl.UnresolvedPrincipal;
 import com.ecyrd.jspwiki.auth.authorize.Group;
@@ -25,7 +21,6 @@
 import com.ecyrd.jspwiki.auth.permissions.PagePermission;
 import com.ecyrd.jspwiki.auth.permissions.PermissionFactory;
 import com.ecyrd.jspwiki.auth.permissions.WikiPermission;
-import com.ecyrd.jspwiki.auth.user.DefaultUserProfile;
 import com.ecyrd.jspwiki.auth.user.UserProfile;
 import com.ecyrd.jspwiki.providers.ProviderException;
 
@@ -505,7 +500,7 @@
     public void testResolveUsers() throws WikiException
     {
         // We should be able to resolve a user by login, user, or wiki name
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = m_engine.getUserManager().getUserDatabase().newProfile();
         profile.setEmail( "authmanagertest@tester.net" );
         profile.setFullname( "AuthorizationManagerTest User" );
         profile.setLoginName( "authmanagertest" );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/GroupManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/GroupManagerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/GroupManagerTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/GroupManagerTest.java Sun Aug  3 05:28:09 2008
@@ -81,12 +81,12 @@
     {
         String members = "Biff";
         Group group = m_groupMgr.parseGroup( "Group1", members, true );
-        assertEquals( 1, group.getMembers().size() );
+        assertEquals( 1, group.members().length );
         assertTrue ( group.isMember( new WikiPrincipal( "Biff" ) ) );
 
         members = "Biff \n SteveAustin \n FredFlintstone";
         group = m_groupMgr.parseGroup( "Group2", members, true );
-        assertEquals( 3, group.getMembers().size() );
+        assertEquals( 3, group.members().length );
         assertTrue ( group.isMember( new WikiPrincipal( "Biff" ) ) );
         assertTrue ( group.isMember( new WikiPrincipal( "SteveAustin" ) ) );
         assertTrue ( group.isMember( new WikiPrincipal( "FredFlintstone" ) ) );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/SecurityEventTrap.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/SecurityEventTrap.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/SecurityEventTrap.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/SecurityEventTrap.java Sun Aug  3 05:28:09 2008
@@ -15,7 +15,7 @@
 public class SecurityEventTrap implements WikiEventListener
 {
     private WikiSecurityEvent m_lastEvent = null;
-    private List<WikiSecurityEvent> m_events = new ArrayList<WikiSecurityEvent>();
+    private List<WikiSecurityEvent> m_events    = new ArrayList<WikiSecurityEvent>();
 
     public void actionPerformed( WikiEvent event )
     {

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java Sun Aug  3 05:28:09 2008
@@ -1,3 +1,23 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth;
 import java.security.Principal;
 import java.util.Collection;
@@ -26,6 +46,7 @@
   private TestEngine m_engine;
   private UserManager m_mgr;
   private UserDatabase m_db;
+  private String m_groupName;
   
   /**
    * @see junit.framework.TestCase#setUp()
@@ -44,8 +65,18 @@
     m_engine  = new TestEngine( props );
     m_mgr = m_engine.getUserManager();
     m_db = m_mgr.getUserDatabase();
+    m_groupName = "Group" + System.currentTimeMillis();
   }
   
+  protected void tearDown() throws Exception
+  {
+    GroupManager groupManager = m_engine.getGroupManager();
+    if ( groupManager.findRole( m_groupName ) != null )
+    {
+        groupManager.removeGroup( m_groupName );
+    }
+  }
+
   /** Call this setup program to use the save-profile workflow. */
   protected void setUpWithWorkflow() throws Exception
   {
@@ -79,22 +110,22 @@
       String oldName      = "Test User " + now;
       String newLogin     = "RenamedLogin" + now;
       String newName      = "Renamed User " + now;
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "testuser@testville.com" );
       profile.setLoginName( oldLogin );
       profile.setFullname ( oldName );
       profile.setPassword ( "password" );
       m_mgr.setUserProfile( session, profile );
       
-      // 1a. Make sure the profile saved successfully
+      // 1a. Make sure the profile saved successfully and that we're logged in
       profile = m_mgr.getUserProfile( session );
       assertEquals( oldLogin, profile.getLoginName() );
       assertEquals( oldName, profile.getFullname() );
       assertEquals( oldUserCount+1, m_db.getWikiNames().length );
+      assertTrue( session.isAuthenticated() );
       
       // Setup Step 2: create a new group with our test user in it
-      String groupName = "Group"+now;
-      Group group = groupManager.parseGroup( groupName, "Alice \n Bob \n Charlie \n " + oldLogin + "\n" + oldName, true );
+      Group group = groupManager.parseGroup( m_groupName, "Alice \n Bob \n Charlie \n " + oldLogin + "\n" + oldName, true );
       groupManager.setGroup( session, group );
       
       // 2a. Make sure the group is created with the user in it, and the role is added to the Subject
@@ -121,7 +152,7 @@
       assertFalse  ( "Bob !view page", authManager.checkPermission( bobSession, PermissionFactory.getPagePermission( p, "view" ) ) );
       
       // Setup Step 4: change the user name in the profile and see what happens
-      profile = new DefaultUserProfile();
+      profile = m_db.newProfile();
       profile.setEmail    ( "testuser@testville.com" );
       profile.setLoginName( oldLogin );
       profile.setFullname ( newName );
@@ -137,7 +168,7 @@
       
       // Test 2: our group should not contain the old name OR login name any more
       // (the full name is always used)
-      group = groupManager.getGroup( groupName );
+      group = groupManager.getGroup( m_groupName );
       assertFalse( group.isMember( new WikiPrincipal( oldLogin ) ) );
       assertFalse( group.isMember( new WikiPrincipal( oldName  ) ) );
       assertFalse( group.isMember( new WikiPrincipal( newLogin ) ) );
@@ -163,7 +194,7 @@
       m_engine.deletePage( pageName );
       
       // Setup Step 6: re-create the group with our old test user names in it
-      group = groupManager.parseGroup( groupName, "Alice \n Bob \n Charlie \n " + oldLogin + "\n" + oldName, true );
+      group = groupManager.parseGroup( m_groupName, "Alice \n Bob \n Charlie \n " + oldLogin + "\n" + oldName, true );
       groupManager.setGroup( session, group );
       
       // Setup Step 7: Save a new page with the old login/wiki names in the ACL again
@@ -180,7 +211,7 @@
       assertFalse  ( "Bob !view page", authManager.checkPermission( bobSession, PermissionFactory.getPagePermission( p, "view" ) ) );
       
       // Setup Step 8: re-save the profile with the new login name
-      profile = new DefaultUserProfile();
+      profile = m_db.newProfile();
       profile.setEmail    ( "testuser@testville.com" );
       profile.setLoginName( newLogin );
       profile.setFullname ( oldName );
@@ -196,7 +227,7 @@
       
       // Test 6: our group should not contain the old name OR login name any more
       // (the full name is always used)
-      group = groupManager.getGroup( groupName );
+      group = groupManager.getGroup( m_groupName );
       assertFalse( group.isMember( new WikiPrincipal( oldLogin ) ) );
       assertTrue ( group.isMember( new WikiPrincipal( oldName  ) ) );
       assertFalse( group.isMember( new WikiPrincipal( newLogin ) ) );
@@ -237,7 +268,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "testuser@testville.com" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -264,7 +295,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "testuser@testville.com" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -318,7 +349,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "testuser@testville.com" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -366,7 +397,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "testuser@testville.com" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclEntryImplTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclEntryImplTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclEntryImplTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclEntryImplTest.java Sun Aug  3 05:28:09 2008
@@ -1,21 +1,22 @@
 /*
     JSPWiki - a JSP-based WikiWiki clone.
 
-    Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU Lesser General Public License as published by
-    the Free Software Foundation; either version 2.1 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    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 com.ecyrd.jspwiki.auth.acl;
 

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclImplTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclImplTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclImplTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclImplTest.java Sun Aug  3 05:28:09 2008
@@ -1,24 +1,26 @@
 /*
     JSPWiki - a JSP-based WikiWiki clone.
 
-    Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU Lesser General Public License as published by
-    the Free Software Foundation; either version 2.1 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+    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 com.ecyrd.jspwiki.auth.acl;
 
+import java.io.*;
 import java.security.Principal;
 import java.util.HashMap;
 import java.util.Map;
@@ -29,7 +31,6 @@
 import junit.framework.TestSuite;
 
 import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.WikiEngine;
 import com.ecyrd.jspwiki.WikiSession;
 import com.ecyrd.jspwiki.WikiSessionTest;
 import com.ecyrd.jspwiki.auth.GroupPrincipal;
@@ -47,7 +48,7 @@
 
     private AclImpl      m_aclGroup;
 
-    private Map<String,Group>          m_groups;
+    private Map<String, Group>          m_groups;
 
     private GroupManager m_groupMgr;
 
@@ -74,7 +75,7 @@
 
         m_acl = new AclImpl();
         m_aclGroup = new AclImpl();
-        m_groups = new HashMap<String,Group>();
+        m_groups = new HashMap<String, Group>();
         Principal uAlice = new WikiPrincipal( "Alice" );
         Principal uBob = new WikiPrincipal( "Bob" );
         Principal uCharlie = new WikiPrincipal( "Charlie" );
@@ -232,6 +233,25 @@
         assertFalse( "Dave delete", inGroup( m_aclGroup.findPrincipals( PagePermission.DELETE ), wup ) );
     }
 
+    public void testSerialization() throws IOException, ClassNotFoundException
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        
+        ObjectOutputStream out2 = new ObjectOutputStream(out);
+        
+        out2.writeObject( m_acl );
+        
+        out2.close();
+        
+        byte[] stuff = out.toByteArray();
+        
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(stuff) );
+        
+        AclImpl newacl = (AclImpl) in.readObject();
+        
+        assert( newacl.equals(m_acl) );
+    }
+    
     public static Test suite()
     {
         return new TestSuite( AclImplTest.class );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabaseTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabaseTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabaseTest.java Sun Aug  3 05:28:09 2008
@@ -4,7 +4,6 @@
 import java.security.Principal;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.util.List;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -112,23 +111,23 @@
         // Group TV has 3 members
         group = backendGroup( "TV" );
         assertEquals("TV", group.getName() );
-        assertEquals( 3, group.getMembers().size() );
+        assertEquals( 3, group.members().length );
 
         // Group Literature has 2 members
         group = backendGroup( "Literature" );
         assertEquals("Literature", group.getName() );
-        assertEquals( 2, group.getMembers().size() );
+        assertEquals( 2, group.members().length );
 
         // Group Art has no members
         group = backendGroup( "Art" );
         assertEquals("Art", group.getName() );
-        assertEquals( 0, group.getMembers().size() );
+        assertEquals( 0, group.members().length );
 
         // Group Admin has 1 member (Administrator)
         group = backendGroup( "Admin" );
         assertEquals("Admin", group.getName() );
-        assertEquals( 1, group.getMembers().size() );
-        assertEquals( "Administrator", group.getMembers().get(0).getName() );
+        assertEquals( 1, group.members().length );
+        assertEquals( "Administrator", group.members()[0].getName() );
 
         // Group Archaeology doesn't exist
         try
@@ -159,7 +158,7 @@
         // Make sure the profile saved successfully
         group = backendGroup( name );
         assertEquals( name, group.getName() );
-        assertEquals( 3, group.getMembers().size() );
+        assertEquals( 3, group.members().length );
         assertTrue( group.isMember( new WikiPrincipal( "Al" ) ) );
         assertTrue( group.isMember( new WikiPrincipal( "Bob" ) ) );
         assertTrue( group.isMember( new WikiPrincipal( "Cookie" ) ) );
@@ -201,8 +200,8 @@
         m_db.save(group, new WikiPrincipal( "SecondTester" ) );
 
         // We should see 4 members and new timestamp info
-        List<Principal> members = group.getMembers();
-        assertEquals( 4, members.size() );
+        Principal[] members = group.members();
+        assertEquals( 4, members.length );
         assertNotNull( group.getCreator() );
         assertEquals( "Tester", group.getCreator() );
         assertNotNull( group.getCreated() );
@@ -212,8 +211,8 @@
 
         // Check the back-end; We should see the same thing
         group = backendGroup( name );
-        members = group.getMembers();
-        assertEquals( 4, members.size() );
+        members = group.members();
+        assertEquals( 4, members.length );
         assertNotNull( group.getCreator() );
         assertEquals( "Tester", group.getCreator() );
         assertNotNull( group.getCreated() );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabaseTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabaseTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabaseTest.java Sun Aug  3 05:28:09 2008
@@ -1,6 +1,25 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth.authorize;
 import java.security.Principal;
-import java.util.List;
 import java.util.Properties;
 
 import junit.framework.TestCase;
@@ -73,23 +92,23 @@
       // Group TV has 3 members
       group = backendGroup( "TV" );
       assertEquals("TV", group.getName() );
-      assertEquals( 3, group.getMembers().size() );
+      assertEquals( 3, group.members().length );
 
       // Group Literature has 2 members
       group = backendGroup( "Literature" );
       assertEquals("Literature", group.getName() );
-      assertEquals( 2, group.getMembers().size() );
+      assertEquals( 2, group.members().length );
 
       // Group Art has no members
       group = backendGroup( "Art" );
       assertEquals("Art", group.getName() );
-      assertEquals( 0, group.getMembers().size() );
+      assertEquals( 0, group.members().length );
 
       // Group Admin has 1 member (Administrator)
       group = backendGroup( "Admin" );
       assertEquals("Admin", group.getName() );
-      assertEquals( 1, group.getMembers().size() );
-      assertEquals( "Administrator", group.getMembers().get(0).getName() );
+      assertEquals( 1, group.members().length );
+      assertEquals( "Administrator", group.members()[0].getName() );
 
       // Group Archaeology doesn't exist
       try
@@ -120,7 +139,7 @@
       // Make sure the profile saved successfully
       group = backendGroup( name );
       assertEquals( name, group.getName() );
-      assertEquals( 3, group.getMembers().size() );
+      assertEquals( 3, group.members().length );
       assertTrue( group.isMember( new WikiPrincipal( "Al" ) ) );
       assertTrue( group.isMember( new WikiPrincipal( "Bob" ) ) );
       assertTrue( group.isMember( new WikiPrincipal( "Cookie" ) ) );
@@ -162,8 +181,8 @@
       m_db.save(group, new WikiPrincipal( "SecondTester" ) );
 
       // We should see 4 members and new timestamp info
-      List<Principal> members = group.getMembers();
-      assertEquals( 4, members.size() );
+      Principal[] members = group.members();
+      assertEquals( 4, members.length );
       assertNotNull( group.getCreator() );
       assertEquals( "Tester", group.getCreator() );
       assertNotNull( group.getCreated() );
@@ -173,8 +192,8 @@
 
       // Check the back-end; We should see the same thing
       group = backendGroup( name );
-      members = group.getMembers();
-      assertEquals( 4, members.size() );
+      members = group.members();
+      assertEquals( 4, members.length );
       assertNotNull( group.getCreator() );
       assertEquals( "Tester", group.getCreator() );
       assertNotNull( group.getCreated() );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AnonymousLoginModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AnonymousLoginModuleTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AnonymousLoginModuleTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AnonymousLoginModuleTest.java Sun Aug  3 05:28:09 2008
@@ -1,20 +1,40 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth.login;
 
+import java.util.HashMap;
 import java.util.Properties;
 import java.util.Set;
 
 import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
+import javax.servlet.http.HttpServletRequest;
 
 import junit.framework.TestCase;
-import net.sourceforge.stripes.mock.MockHttpServletRequest;
 
 import com.ecyrd.jspwiki.NoRequiredPropertyException;
 import com.ecyrd.jspwiki.TestAuthorizer;
 import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.action.ViewActionBean;
 import com.ecyrd.jspwiki.auth.Authorizer;
 import com.ecyrd.jspwiki.auth.WikiPrincipal;
 import com.ecyrd.jspwiki.auth.authorize.Role;
@@ -36,18 +56,20 @@
 
     public final void testLogin()
     {
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        HttpServletRequest request = m_engine.newHttpRequest();
         try
         {
             // Test using IP address (AnonymousLoginModule succeeds)
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new AnonymousLoginModule();
+            module.initialize(subject, handler, new HashMap<String, Object>(), new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
+            assertEquals( 1, principals.size() );
             assertTrue( principals.contains( new WikiPrincipal( "127.0.0.1" ) ) );
-            assertTrue( principals.contains( Role.ANONYMOUS ) );
-            assertTrue( principals.contains( Role.ALL ) );
+            assertFalse( principals.contains( Role.ANONYMOUS ) );
+            assertFalse( principals.contains( Role.ALL ) );
         }
         catch( LoginException e )
         {
@@ -58,18 +80,22 @@
 
     public final void testLogout()
     {
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        HttpServletRequest request = m_engine.newHttpRequest();
         try
         {
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new AnonymousLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
+            assertEquals( 1, principals.size() );
             assertTrue( principals.contains( new WikiPrincipal( "127.0.0.1" ) ) );
-            assertTrue( principals.contains( Role.ANONYMOUS ) );
-            assertTrue( principals.contains( Role.ALL ) );
-            context.logout();
+            assertFalse( principals.contains( Role.ANONYMOUS ) );
+            assertFalse( principals.contains( Role.ALL ) );
+            module.logout();
             assertEquals( 0, principals.size() );
         }
         catch( LoginException e )

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/CookieAssertionLoginModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/CookieAssertionLoginModuleTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/CookieAssertionLoginModuleTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/CookieAssertionLoginModuleTest.java Sun Aug  3 05:28:09 2008
@@ -1,22 +1,42 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth.login;
 
+import java.util.HashMap;
 import java.util.Properties;
 import java.util.Set;
 
 import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
 import javax.servlet.http.Cookie;
 
-import junit.framework.TestCase;
 import net.sourceforge.stripes.mock.MockHttpServletRequest;
 
+import junit.framework.TestCase;
+
 import com.ecyrd.jspwiki.NoRequiredPropertyException;
 import com.ecyrd.jspwiki.TestAuthorizer;
 import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.action.ViewActionBean;
-import com.ecyrd.jspwiki.auth.AuthenticationManager;
 import com.ecyrd.jspwiki.auth.Authorizer;
 import com.ecyrd.jspwiki.auth.WikiPrincipal;
 import com.ecyrd.jspwiki.auth.authorize.Role;
@@ -38,25 +58,28 @@
 
     public final void testLogin()
     {
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        MockHttpServletRequest request = m_engine.newHttpRequest();
         try
         {
             // We can use cookies right?
-            assertTrue( AuthenticationManager.allowsCookieAssertions() );
+            assertTrue( m_engine.getAuthenticationManager().allowsCookieAssertions() );
 
             // Test using Cookie and IP address (AnonymousLoginModule succeeds)
             Cookie cookie = new Cookie( CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle" );
-            request.setCookies( new Cookie[]
-            { cookie } );
+            request.setCookies( new Cookie[] { cookie } );
             subject = new Subject();
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new CookieAssertionLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
+            assertEquals( 1, principals.size() );
             assertTrue( principals.contains( new WikiPrincipal( "Bullwinkle" ) ) );
-            assertTrue( principals.contains( Role.ASSERTED ) );
-            assertTrue( principals.contains( Role.ALL ) );
+            assertFalse( principals.contains( Role.ASSERTED ) );
+            assertFalse( principals.contains( Role.ALL ) );
         }
         catch( LoginException e )
         {
@@ -67,18 +90,24 @@
 
     public final void testLogout()
     {
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        MockHttpServletRequest request = m_engine.newHttpRequest();
+        Cookie cookie = new Cookie( CookieAssertionLoginModule.PREFS_COOKIE_NAME, "Bullwinkle" );
+        request.setCookies( new Cookie[] { cookie } );
         try
         {
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new CookieAssertionLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue( principals.contains( new WikiPrincipal( "127.0.0.1" ) ) );  // Stripes mock requests always return this
-            assertTrue( principals.contains( Role.ANONYMOUS ) );
-            assertTrue( principals.contains( Role.ALL ) );
-            context.logout();
+            assertEquals( 1, principals.size() );
+            assertTrue( principals.contains( new WikiPrincipal( "Bullwinkle" ) ) );
+            assertFalse( principals.contains( Role.ANONYMOUS ) );
+            assertFalse( principals.contains( Role.ALL ) );
+            module.logout();
             assertEquals( 0, principals.size() );
         }
         catch( LoginException e )

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java Sun Aug  3 05:28:09 2008
@@ -1,12 +1,33 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth.login;
 
+import java.util.HashMap;
 import java.util.Properties;
 import java.util.Set;
 
 import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
 
 import junit.framework.TestCase;
 
@@ -33,24 +54,32 @@
         {
             // Log in with a user that isn't in the database
             CallbackHandler handler = new WikiCallbackHandler( db, "user", "password" );
-            LoginContext context = new LoginContext( "JSPWiki-custom", subject, handler );
-            context.login();
+            LoginModule module = new UserDatabaseLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue( principals.contains( new PrincipalWrapper( new WikiPrincipal( "user", WikiPrincipal.LOGIN_NAME ) ) ) );
-            assertTrue( principals.contains( Role.AUTHENTICATED ) );
-            assertTrue( principals.contains( Role.ALL ) );
+            assertEquals( 1, principals.size() );
+            assertTrue( principals.contains( new WikiPrincipal( "user", WikiPrincipal.LOGIN_NAME ) ) );
+            assertFalse( principals.contains( Role.AUTHENTICATED ) );
+            assertFalse( principals.contains( Role.ALL ) );
             
-            // Login with a user that IS in the databasse
+            // Login with a user that IS in the database
             subject = new Subject();
             handler = new WikiCallbackHandler( db, "janne", "myP@5sw0rd" );
-            context = new LoginContext( "JSPWiki-custom", subject, handler );
-            context.login();
+            module = new UserDatabaseLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue( principals.contains( new PrincipalWrapper( new WikiPrincipal( "janne", WikiPrincipal.LOGIN_NAME ) ) ) );
-            assertTrue( principals.contains( Role.AUTHENTICATED ) );
-            assertTrue( principals.contains( Role.ALL ) );            
+            assertEquals( 1, principals.size() );
+            assertTrue( principals.contains( new WikiPrincipal( "janne", WikiPrincipal.LOGIN_NAME ) ) );
+            assertFalse( principals.contains( Role.AUTHENTICATED ) );
+            assertFalse( principals.contains( Role.ALL ) );            
         }
         catch( LoginException e )
         {
@@ -64,14 +93,18 @@
         try
         {
             CallbackHandler handler = new WikiCallbackHandler( db, "user", "password" );
-            LoginContext context = new LoginContext( "JSPWiki-custom", subject, handler );
-            context.login();
+            LoginModule module = new UserDatabaseLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue( principals.contains( new PrincipalWrapper( new WikiPrincipal( "user",  WikiPrincipal.LOGIN_NAME ) ) ) );
-            assertTrue( principals.contains( Role.AUTHENTICATED ) );
-            assertTrue( principals.contains( Role.ALL ) );
-            context.logout();
+            assertEquals( 1, principals.size() );
+            assertTrue( principals.contains( new WikiPrincipal( "user",  WikiPrincipal.LOGIN_NAME ) ) );
+            assertFalse( principals.contains( Role.AUTHENTICATED ) );
+            assertFalse( principals.contains( Role.ALL ) );
+            module.logout();
             assertEquals( 0, principals.size() );
         }
         catch( LoginException e )

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/WebContainerLoginModuleTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/WebContainerLoginModuleTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/WebContainerLoginModuleTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/WebContainerLoginModuleTest.java Sun Aug  3 05:28:09 2008
@@ -1,22 +1,43 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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 com.ecyrd.jspwiki.auth.login;
 
 import java.security.Principal;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
 
 import javax.security.auth.Subject;
 import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
+import javax.security.auth.spi.LoginModule;
 
-import junit.framework.TestCase;
 import net.sourceforge.stripes.mock.MockHttpServletRequest;
 
+import junit.framework.TestCase;
+
 import com.ecyrd.jspwiki.NoRequiredPropertyException;
 import com.ecyrd.jspwiki.TestAuthorizer;
 import com.ecyrd.jspwiki.TestEngine;
-import com.ecyrd.jspwiki.action.ViewActionBean;
 import com.ecyrd.jspwiki.auth.Authorizer;
 import com.ecyrd.jspwiki.auth.WikiPrincipal;
 import com.ecyrd.jspwiki.auth.authorize.Role;
@@ -39,51 +60,25 @@
     public final void testLogin()
     {
         Principal principal = new WikiPrincipal( "Andrew Jaquith" );
-        Principal wrapper = new PrincipalWrapper( principal );
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        MockHttpServletRequest request = m_engine.newHttpRequest();
         request.setUserPrincipal( principal );
         try
         {
             // Test using Principal (WebContainerLoginModule succeeds)
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new WebContainerLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue(  principals.contains( wrapper ) );
+            assertEquals( 1, principals.size() );
+            assertTrue(  principals.contains( principal ) );
             assertFalse( principals.contains( Role.ANONYMOUS ) );
             assertFalse( principals.contains( Role.ASSERTED ) );
-            assertTrue(  principals.contains( Role.AUTHENTICATED ) );
-            assertTrue(  principals.contains( Role.ALL ) );
-
-            // Test using remote user (WebContainerLoginModule succeeds)
-            subject = new Subject();
-            request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
-            request.setUserPrincipal( new WikiPrincipal( "Andrew Jaquith" ) );
-            handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
-            principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue(  principals.contains( wrapper ) );
-            assertFalse( principals.contains( Role.ANONYMOUS ) );
-            assertFalse( principals.contains( Role.ASSERTED ) );
-            assertTrue(  principals.contains( Role.AUTHENTICATED ) );
-            assertTrue(  principals.contains( Role.ALL ) );
-
-            // Test using IP address (AnonymousLoginModule succeeds)
-            subject = new Subject();
-            request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
-            handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
-            principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertFalse( principals.contains( principal ) );
-            assertTrue(  principals.contains( Role.ANONYMOUS ) );
-            assertFalse( principals.contains( Role.ASSERTED ) );
             assertFalse( principals.contains( Role.AUTHENTICATED ) );
-            assertTrue(  principals.contains( Role.ALL ) );
+            assertFalse( principals.contains( Role.ALL ) );
         }
         catch( LoginException e )
         {
@@ -96,8 +91,7 @@
     {
         // Create user with 2 container roles; TestAuthorizer knows about these
         Principal principal = new WikiPrincipal( "Andrew Jaquith" );
-        Principal wrapper = new PrincipalWrapper( principal );
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        MockHttpServletRequest request = m_engine.newHttpRequest();
         request.setUserPrincipal( principal );
         Set<String> roles = new HashSet<String>();
         roles.add( "IT" );
@@ -106,15 +100,19 @@
 
         // Test using Principal (WebContainerLoginModule succeeds)
         CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-        LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-        context.login();
+        LoginModule module = new WebContainerLoginModule();
+        module.initialize(subject, handler, 
+                          new HashMap<String, Object>(), 
+                          new HashMap<String, Object>());
+        module.login();
+        module.commit();
         Set principals = subject.getPrincipals();
-        assertEquals( 5, principals.size() );
-        assertTrue( principals.contains( wrapper ) );
+        assertEquals( 3, principals.size() );
+        assertTrue( principals.contains( principal ) );
         assertFalse( principals.contains( Role.ANONYMOUS ) );
         assertFalse( principals.contains( Role.ASSERTED ) );
-        assertTrue(  principals.contains( Role.AUTHENTICATED ) );
-        assertTrue(  principals.contains( Role.ALL ) );
+        assertFalse( principals.contains( Role.AUTHENTICATED ) );
+        assertFalse( principals.contains( Role.ALL ) );
         assertTrue(  principals.contains( new Role( "IT" ) ) );
         assertTrue(  principals.contains( new Role( "Engineering" ) ) );
     }
@@ -122,20 +120,23 @@
     public final void testLogout()
     {
         Principal principal = new WikiPrincipal( "Andrew Jaquith" );
-        Principal wrapper = new PrincipalWrapper( principal );
-        MockHttpServletRequest request = m_engine.guestTrip( ViewActionBean.class ).getRequest();
+        MockHttpServletRequest request = m_engine.newHttpRequest();
         request.setUserPrincipal( principal );
         try
         {
             CallbackHandler handler = new WebContainerCallbackHandler( m_engine, request, authorizer );
-            LoginContext context = new LoginContext( "JSPWiki-container", subject, handler );
-            context.login();
+            LoginModule module = new WebContainerLoginModule();
+            module.initialize(subject, handler, 
+                              new HashMap<String, Object>(), 
+                              new HashMap<String, Object>());
+            module.login();
+            module.commit();
             Set principals = subject.getPrincipals();
-            assertEquals( 3, principals.size() );
-            assertTrue( principals.contains( wrapper ) );
-            assertTrue( principals.contains( Role.AUTHENTICATED ) );
-            assertTrue( principals.contains( Role.ALL ) );
-            context.logout();
+            assertEquals( 1, principals.size() );
+            assertTrue( principals.contains( principal ) );
+            assertFalse( principals.contains( Role.AUTHENTICATED ) );
+            assertFalse( principals.contains( Role.ALL ) );
+            module.logout();
             assertEquals( 0, principals.size() );
         }
         catch( LoginException e )

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java Sun Aug  3 05:28:09 2008
@@ -1,11 +1,13 @@
 package com.ecyrd.jspwiki.auth.user;
 
 import java.io.File;
+import java.io.Serializable;
 import java.security.Principal;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Timestamp;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -18,6 +20,7 @@
 import com.ecyrd.jspwiki.TestJNDIContext;
 import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
 import com.ecyrd.jspwiki.auth.WikiSecurityException;
+import com.ecyrd.jspwiki.util.CryptoUtil;
 
 /**
  * @author Andrew Jaquith
@@ -25,25 +28,31 @@
 public class JDBCUserDatabaseTest extends TestCase
 {
     private JDBCUserDatabase m_db   = null;
+    
+    private static final String TEST_ATTRIBUTES = "rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAACdAAKYXR0cmlidXRlMXQAEXNvbWUgcmFuZG9tIHZhbHVldAAKYXR0cmlidXRlMnQADWFub3RoZXIgdmFsdWV4";
 
     private static final String INSERT_JANNE = "INSERT INTO users (" +
+          JDBCUserDatabase.DEFAULT_DB_UID + "," +
           JDBCUserDatabase.DEFAULT_DB_EMAIL + "," +
           JDBCUserDatabase.DEFAULT_DB_FULL_NAME + "," +
           JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," +
           JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," +
           JDBCUserDatabase.DEFAULT_DB_WIKI_NAME + "," +
-          JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES (" +
-          "'janne@ecyrd.com'," + "'Janne Jalkanen'," + "'janne'," +
+          JDBCUserDatabase.DEFAULT_DB_CREATED + "," +
+          JDBCUserDatabase.DEFAULT_DB_ATTRIBUTES + ") VALUES (" +
+          "'-7739839977499061014'," + "'janne@ecyrd.com'," + "'Janne Jalkanen'," + "'janne'," +
           "'{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee'," +
           "'JanneJalkanen'," +
-          "'" + new Timestamp( new Timestamp( System.currentTimeMillis() ).getTime() ).toString() + "'" + ");";
+          "'" + new Timestamp( new Timestamp( System.currentTimeMillis() ).getTime() ).toString() + "'," +
+          "'" + TEST_ATTRIBUTES +"'" + ");";
 
     private static final String INSERT_USER = "INSERT INTO users (" +
+        JDBCUserDatabase.DEFAULT_DB_UID + "," +
         JDBCUserDatabase.DEFAULT_DB_EMAIL + "," +
         JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," +
         JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," +
         JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES (" +
-        "'user@example.com'," + "'user'," +
+        "'-8629747547991531672'," + "'user@example.com'," + "'user'," +
         "'{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'," +
         "'" + new Timestamp( new Timestamp( System.currentTimeMillis() ).getTime() ).toString() + "'" + ");";
 
@@ -102,7 +111,7 @@
 
         // Create a new user with random name
         String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = m_db.newProfile();
         profile.setEmail("testuser@testville.com");
         profile.setLoginName( loginName );
         profile.setFullname( "FullName"+loginName );
@@ -119,11 +128,45 @@
         assertEquals( oldUserCount, m_db.getWikiNames().length );
     }
 
+    public void testAttributes() throws Exception
+    {
+        UserProfile profile = m_db.findByEmail( "janne@ecyrd.com" );
+        
+        Map<String,Serializable> attributes = profile.getAttributes();
+        assertEquals( 2, attributes.size() );
+        assertTrue( attributes.containsKey( "attribute1" ) );
+        assertTrue( attributes.containsKey( "attribute2" ) );
+        assertEquals( "some random value", attributes.get( "attribute1" ) );
+        assertEquals( "another value", attributes.get( "attribute2" ) );
+        
+        // Change attribute 1, and add another one
+        attributes.put( "attribute1", "replacement value" );
+        attributes.put( "attribute the third", "some value" );
+        m_db.save( profile );
+        
+        // Retrieve the profile again and make sure our values got saved
+        profile = m_db.findByEmail( "janne@ecyrd.com" );
+        attributes = profile.getAttributes();
+        assertEquals( 3, attributes.size() );
+        assertTrue( attributes.containsKey( "attribute1" ) );
+        assertTrue( attributes.containsKey( "attribute2" ) );
+        assertTrue( attributes.containsKey( "attribute the third" ) );
+        assertEquals( "replacement value", attributes.get( "attribute1" ) );
+        assertEquals( "another value", attributes.get( "attribute2" ) );
+        assertEquals( "some value", attributes.get( "attribute the third" ) );
+        
+        // Restore the original attributes and re-save
+        attributes.put( "attribute1", "some random value" );
+        attributes.remove( "attribute the third" );
+        m_db.save( profile );
+    }
+    
     public void testFindByEmail()
     {
         try
         {
             UserProfile profile = m_db.findByEmail( "janne@ecyrd.com" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -153,6 +196,7 @@
         try
         {
             UserProfile profile = m_db.findByFullName( "Janne Jalkanen" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -177,11 +221,42 @@
         }
     }
 
+    public void testFindByUid()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByUid( -7739839977499061014L );
+            assertEquals( -7739839977499061014L, profile.getUid() );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword() );
+            assertEquals( "janne@ecyrd.com", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "foo@bar.org" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+    
     public void testFindByWikiName()
     {
         try
         {
             UserProfile profile = m_db.findByWikiName( "JanneJalkanen" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -211,6 +286,7 @@
         try
         {
             UserProfile profile = m_db.findByLoginName( "janne" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -255,7 +331,7 @@
         }
 
         // Create new user & verify it saved ok
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = m_db.newProfile();
         profile.setEmail( "renamed@example.com" );
         profile.setFullname( "Renamed User" );
         profile.setLoginName( "olduser" );
@@ -294,18 +370,18 @@
         assertEquals( "renamed@example.com", profile.getEmail() );
         assertEquals( "Renamed User", profile.getFullname() );
         assertEquals( "renameduser", profile.getLoginName() );
-        assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+        assertTrue( CryptoUtil.verifySaltedPassword( "password".getBytes(), profile.getPassword() ) );
 
         // Delete the user
         m_db.deleteByLoginName( "renameduser" );
     }
 
-    public void testSave()
+    public void testSave() throws Exception
     {
         try
         {
             // Overwrite existing user
-            UserProfile profile = new DefaultUserProfile();
+            UserProfile profile = m_db.newProfile();
             profile.setEmail( "user@example.com" );
             profile.setFullname( "Test User" );
             profile.setLoginName( "user" );
@@ -315,14 +391,14 @@
             assertEquals( "user@example.com", profile.getEmail() );
             assertEquals( "Test User", profile.getFullname() );
             assertEquals( "user", profile.getLoginName() );
-            assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+            assertTrue( CryptoUtil.verifySaltedPassword( "password".getBytes(), profile.getPassword() ) );
             assertEquals( "TestUser", profile.getWikiName() );
             assertNotNull( profile.getCreated() );
             assertNotNull( profile.getLastModified() );
             assertNotSame( profile.getCreated(), profile.getLastModified() );
 
             // Create new user
-            profile = new DefaultUserProfile();
+            profile = m_db.newProfile();
             profile.setEmail( "user2@example.com" );
             profile.setFullname( "Test User 2" );
             profile.setLoginName( "user2" );
@@ -332,7 +408,7 @@
             assertEquals( "user2@example.com", profile.getEmail() );
             assertEquals( "Test User 2", profile.getFullname() );
             assertEquals( "user2", profile.getLoginName() );
-            assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+            assertTrue( CryptoUtil.verifySaltedPassword( "password".getBytes(), profile.getPassword() ) );
             assertEquals( "TestUser2", profile.getWikiName() );
             assertNotNull( profile.getCreated() );
             assertNotNull( profile.getLastModified() );

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java Sun Aug  3 05:28:09 2008
@@ -1,6 +1,6 @@
 package com.ecyrd.jspwiki.auth.user;
 
-import java.io.IOException;
+import java.util.Date;
 import java.util.Properties;
 
 import junit.framework.Test;
@@ -10,6 +10,7 @@
 import org.apache.log4j.PropertyConfigurator;
 
 import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiEngine;
 
 /**
  *  Tests the DefaultUserProfile class.
@@ -17,31 +18,79 @@
  */
 public class UserProfileTest extends TestCase
 {
-    public UserProfileTest( String s )
+    private UserDatabase m_db;
+    
+    public void setUp()
+        throws Exception
     {
-        super( s );
-        Properties props = new Properties();
-        try
-        {
+            Properties props = new Properties();
             props.load( TestEngine.findTestProperties() );
             PropertyConfigurator.configure(props);
-        }
-        catch( IOException e ) {}
+            WikiEngine engine  = new TestEngine(props);
+            m_db = engine.getUserManager().getUserDatabase();
     }
 
-    public void setUp()
-        throws Exception
+    public void tearDown()
     {
     }
-
-    public void tearDown()
+    
+    public void testSetAttribute()
     {
+        UserProfile p = m_db.newProfile();
+        assertEquals( 0, p.getAttributes().size() );
+        
+        p.getAttributes().put( "MyAttribute", "some arbitrary value." );
+        assertEquals( 1, p.getAttributes().size() );
+        
+        p.getAttributes().put( "YourAttribute", "another arbitrary value." );
+        assertEquals( 2, p.getAttributes().size() );
+        assertTrue( p.getAttributes().containsKey( "MyAttribute" ) );
+        assertTrue( p.getAttributes().containsKey( "YourAttribute" ) );
+        
+        p.getAttributes().remove( "MyAttribute" );
+        assertEquals( 1, p.getAttributes().size() );
+    }
+    
+    public void testSetLockExpiry()
+    {
+        UserProfile p = m_db.newProfile();
+        assertNull( p.getLockExpiry() );
+        assertFalse( p.isLocked() );
+        
+        // Set a lock expiry for 1 second in the past; should cause lock to report as null
+        p.setLockExpiry( new Date( System.currentTimeMillis() - 1000 ) );
+        assertNull( p.getLockExpiry() );
+        assertFalse( p.isLocked() );
+        
+        // Set a lock expiry for 1 second in the past; should say it's not locked
+        p.setLockExpiry( new Date( System.currentTimeMillis() - 1000 ) );
+        assertFalse( p.isLocked() );
+        assertNull( p.getLockExpiry() );
+        
+        // Now set a lock for 100 seconds in the future; lock should be reported correctly
+        Date future = new Date( System.currentTimeMillis() + 100000 );
+        p.setLockExpiry( future );
+        assertTrue( p.isLocked() );
+        assertEquals( future, p.getLockExpiry() );
+        
+        // Clear the lock
+        p.setLockExpiry( null );
+        assertFalse( p.isLocked() );
+        assertNull( p.getLockExpiry() );
+    }
+    
+    public void testSetUid()
+    {
+        UserProfile p = m_db.newProfile();
+        assertNotSame( 1234567890, p.getUid() );
+        p.setUid( 1234567890 );
+        assertEquals( 1234567890, p.getUid() );
     }
 
     public void testEquals()
     {
-        UserProfile p = new DefaultUserProfile();
-        UserProfile p2 = new DefaultUserProfile();
+        UserProfile p = m_db.newProfile();
+        UserProfile p2 = m_db.newProfile();
 
         p.setFullname("Alice");
         p2.setFullname("Bob");
@@ -51,8 +100,8 @@
 
     public void testEquals2()
     {
-        UserProfile p = new DefaultUserProfile();
-        UserProfile p2 = new DefaultUserProfile();
+        UserProfile p = m_db.newProfile();
+        UserProfile p2 = m_db.newProfile();
 
         p.setFullname("Alice");
         p2.setFullname("Alice");



Mime
View raw message