[jboss-cvs] JBossAS SVN: r58020 - in branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite: imports src/main/org/jboss/test src/main/org/jboss/test/web/test src/resources/test-configs/tomcat-sso-cluster/deploy/jbossweb-tomcat55.sar src/resources/web/sso/war
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 2 15:44:44 EST 2006
Author: bstansberry at jboss.com
Date: 2006-11-02 15:44:41 -0500 (Thu, 02 Nov 2006)
New Revision: 58020
Modified:
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/imports/test-jars.xml
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossClusteredTestCase.java
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossTestClusteredServices.java
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SSOBaseCase.java
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/test-configs/tomcat-sso-cluster/deploy/jbossweb-tomcat55.sar/server.xml
branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/web/sso/war/web-sso-expire.xml
Log:
[JBAS-3808] Prevent clustered SSO invalidation upon webapp undeploy and server shutdown
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/imports/test-jars.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/imports/test-jars.xml 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/imports/test-jars.xml 2006-11-02 20:44:41 UTC (rev 58020)
@@ -5035,6 +5035,7 @@
</classes>
<fileset dir="${build.resources}/web/sso/war">
<include name="**/*.html"/>
+ <include name="**/*.jsp"/>
</fileset>
</war>
<war destfile="${build.lib}/sso-expire.war"
@@ -5048,6 +5049,7 @@
</classes>
<fileset dir="${build.resources}/web/sso/war">
<include name="**/*.html"/>
+ <include name="**/*.jsp"/>
</fileset>
</war>
<zip destfile="${build.lib}/web-sso.ear">
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossClusteredTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossClusteredTestCase.java 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossClusteredTestCase.java 2006-11-02 20:44:41 UTC (rev 58020)
@@ -63,6 +63,16 @@
return clusterServices.getHttpURLs();
}
+ protected void deploy(RMIAdaptor server, String name) throws Exception
+ {
+ clusterServices.deploy(server, name);
+ }
+
+ protected void undeploy(RMIAdaptor server, String name) throws Exception
+ {
+ clusterServices.undeploy(server, name);
+ }
+
public static Test getDeploySetup(final Test test, final String jarName)
throws Exception
{
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossTestClusteredServices.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossTestClusteredServices.java 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/JBossTestClusteredServices.java 2006-11-02 20:44:41 UTC (rev 58020)
@@ -6,6 +6,7 @@
*/
package org.jboss.test;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -133,6 +134,53 @@
}
+ /**
+ * Deploy a package on the given server with the main deployer. The supplied
+ * name is interpreted as a url, or as a filename in jbosstest.deploy.lib or
+ * ../lib.
+ *
+ * @param server server on which the package should be deployed
+ * @param name filename/url of package to deploy.
+ * @exception Exception Description of Exception
+ */
+ public void deploy(RMIAdaptor server, String name) throws Exception
+ {
+ if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+ {
+ log.debug("Skipping deployment of: " + name);
+ return;
+ }
+
+ URL deployURL = new URL(getDeployURL(name));
+ log.debug("Deploying " + name + ", url=" + deployURL + " to " + server);
+ invoke(server,
+ getDeployerName(),
+ "deploy",
+ new Object[]{deployURL},
+ new String[]{"java.net.URL"});
+ }
+
+ /**
+ * Undeploy a package from the given server with the main deployer.
+ * The supplied name is interpreted as a url, or as a filename in
+ * jbosstest.deploy.lib or ../lib.
+ *
+ * @param server server on which the package should be deployed
+ * @param name filename/url of package to undeploy.
+ * @exception Exception Description of Exception
+ */
+ public void undeploy(RMIAdaptor server, String name) throws Exception
+ {
+ if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+ return;
+
+ URL deployURL = new URL(getDeployURL(name));
+ log.debug("Undeploying " + name + ", url=" + deployURL);
+ Object[] args = {deployURL};
+ String[] sig = {"java.net.URL"};
+ invoke(server, getDeployerName(), "undeploy", args, sig);
+ }
+
public void init() throws Exception
{
if (initialContext == null)
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/ClusteredSingleSignOnUnitTestCase.java 2006-11-02 20:44:41 UTC (rev 58020)
@@ -1,23 +1,37 @@
/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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 software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
package org.jboss.test.web.test;
-import java.net.HttpURLConnection;
+import java.util.Set;
+import javax.management.ObjectName;
+
import junit.framework.Test;
+import junit.framework.TestSuite;
-import org.apache.commons.httpclient.Cookie;
-import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.log4j.Category;
+import org.jboss.cache.Fqn;
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.test.JBossClusteredTestCase;
@@ -29,6 +43,13 @@
public class ClusteredSingleSignOnUnitTestCase
extends JBossClusteredTestCase
{
+ // NOTE: these variables must be static as apparently a separate instance
+ // of this class is created for each test
+ private static boolean deployed0 = true;
+ private static boolean deployed1 = true;
+
+ private RMIAdaptor[] adaptors = null;
+
public ClusteredSingleSignOnUnitTestCase(String name)
{
super(name);
@@ -38,11 +59,119 @@
*/
public static Test suite() throws Exception
{
- Test t1 = JBossClusteredTestCase.getDeploySetup(ClusteredSingleSignOnUnitTestCase.class,
- "web-sso.ear");
- return t1;
+ // Have to build the suite in detail, as testSessionExpiration must come first
+ TestSuite suite = new TestSuite();
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testSessionExpiration"));
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testFormAuthSingleSignOn"));
+ suite.addTest(new ClusteredSingleSignOnUnitTestCase("testWebappUndeploy"));
+
+// return JBossClusteredTestCase.getDeploySetup(suite, "web-sso-clustered.ear");
+
+ return JBossClusteredTestCase.getDeploySetup(suite, "web-sso.ear");
}
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ log.debug("deployed0 = " + deployed0);
+ log.debug("deployed1 = " + deployed1);
+
+ adaptors = getAdaptors();
+ if (!deployed0)
+ {
+// deploy(adaptors[0], "web-sso-clustered.ear");
+ deploy(adaptors[0], "web-sso.ear");
+ deployed0 = true;
+ }
+ if (!deployed1)
+ {
+// deploy(adaptors[1], "web-sso-clustered.ear");
+ deploy(adaptors[1], "web-sso.ear");
+ deployed1 = true;
+ }
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ log.debug("deployed0 = " + deployed0);
+ log.debug("deployed1 = " + deployed1);
+ }
+
+ /**
+ * Tests that undeploying a webapp on one server doesn't kill an sso
+ * that also has a session from another webapp associated with it.
+ * See JBAS-2429.
+ *
+ * TODO create an independently deployable war so we can test this in
+ * a non-clustered environment as well; this isn't a clustering issue
+ *
+ * @throws Exception
+ */
+ public void testWebappUndeploy() throws Exception
+ {
+ log.info("+++ testWebappUndeploy");
+
+ String[] httpURLs = super.getHttpURLs();
+
+ String serverA = httpURLs[0];
+ String serverB = httpURLs[1];
+
+ String warA1 = serverA + "/war1/";
+ String warB1 = serverB + "/war1/";
+ String warB2 = serverB + "/war2/";
+
+ // Start by accessing the secured index.html of war1
+ HttpClient httpConn = new HttpClient();
+ SSOBaseCase.checkAccessDenied(httpConn, warA1 + "index.html");
+
+ HttpState state = httpConn.getState();
+
+ String sessionID = SSOBaseCase.getSessionIdFromState(state);
+ log.debug("Saw JSESSIONID="+sessionID);
+
+ // Submit the login form
+ SSOBaseCase.executeFormLogin(httpConn, warA1);
+
+ String ssoID = SSOBaseCase.processSSOCookie(state, serverA, serverB);
+ log.debug("Saw JSESSIONIDSSO="+ssoID);
+
+ // Pause a moment before switching wars to better simulate real life
+ // use cases. Otherwise, the test case can "outrun" the async
+ // replication in the TreeCache used by the clustered SSO
+ // 500 ms is a long time, but this isn't a test of replication speed
+ // and we don't want spurious failures.
+ if (!serverA.equals(serverB))
+ Thread.sleep(500);
+
+ // Now try getting the war2 index using the JSESSIONIDSSO cookie
+ log.debug("Prepare /war2/index.html get");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB2 + "index.html");
+
+ // Sleep some more to allow the updated sso to propagate back to serverA
+ if (!serverA.equals(serverB))
+ Thread.sleep(500);
+
+ // We now have a clustered sso context, plus a war1 session on
+ // serverA and a war2 session on serverB. No war1 session on serverB,
+ // so the only way to access war1 on B without a login is through sso.
+
+ //Undeploy the ear from serverA and confirm that it doesn't kill the sso
+// undeploy(adaptors[0], "web-sso-clustered.ear");
+ undeploy(adaptors[0], "web-sso.ear");
+ deployed0 = false;
+
+ // Sleep some more to allow the updated sso to propagate back to serverB
+ if (!serverA.equals(serverB))
+ Thread.sleep(500);
+
+ // Now try getting the war1 index using the JSESSIONIDSSO cookie
+ log.debug("Prepare /war1/index.html get");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB1 + "index.html");
+ }
+
/** Test single sign-on across two web apps using form based auth
*
* @throws Exception
@@ -64,81 +193,83 @@
* Tests that use of transactions in ClusteredSSO does not interfere
* with session expiration thread. See JBAS-2212.
*
- * TODO this is a quick-and-dirty test to get JBoss 4.0.3 out;
- * clearly needs to be refactored
- *
* @throws Exception
*/
public void testSessionExpiration()
throws Exception
{
- log.info("+++ testFormAuthSingleSignOn");
+ log.info("+++ testSessionExpiration");
String[] httpURLs = super.getHttpURLs();
String serverA = httpURLs[0];
+ String serverB = httpURLs[1];
log.info(System.getProperties());
log.info("serverA: "+serverA);
+ log.info("serverB: "+serverB);
- // Start by accessing the secured index.html of war1
+ String warA3 = serverA + "/war3/";
+ String warB3 = serverB + "/war3/";
+
+ // First create an SSO that we won't use again -- we later test that it
+ // gets cleaned up from the cache
+ HttpClient httpConn1 = new HttpClient();
+ SSOBaseCase.checkAccessDenied(httpConn1, warA3 + "index.jsp");
+ SSOBaseCase.executeFormLogin(httpConn1, warA3);
+
+ // Now the standard SSO tests
HttpClient httpConn = new HttpClient();
- GetMethod indexGet = new GetMethod(serverA+"/war3/index.html");
- int responseCode = httpConn.executeMethod(indexGet);
- String body = indexGet.getResponseBodyAsString();
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+ SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
+ HttpState state = httpConn.getState();
+ String sessionID = SSOBaseCase.getSessionIdFromState(state);
+ log.debug("Saw JSESSIONID="+sessionID);
+ SSOBaseCase.executeFormLogin(httpConn, warA3);
+ String ssoID = SSOBaseCase.processSSOCookie(state, serverA, serverB);
+ log.debug("Saw JSESSIONIDSSO="+ssoID);
- HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
+ // Wait more than 15 secs to let session time out
+ // It's life is 5 secs and the processor runs every 10
+ try {
+ Thread.sleep(15500);
+ }
+ catch (InterruptedException ie)
{
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
+ log.debug("Interrupted while waiting for session expiration");
}
- log.debug("Saw JSESSIONID="+sessionID);
+
+ // Try accessing war3 again on both nodes -- should succeed
+ SSOBaseCase.checkAccessAllowed(httpConn, warA3 + "index.jsp");
+ SSOBaseCase.checkAccessAllowed(httpConn, warB3 + "index.jsp");
- // Submit the login form
- PostMethod formPost = new PostMethod(serverA+"/war3/j_security_check");
- formPost.addRequestHeader("Referer", serverA+"/war3/login.html");
- formPost.addParameter("j_username", "jduke");
- formPost.addParameter("j_password", "theduke");
- responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
- formPost, state);
- String response = formPost.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
- responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
-
- // Follow the redirect to the index.html page
- Header location = formPost.getResponseHeader("Location");
- String indexURI = location.getValue();
- GetMethod war1Index = new GetMethod(indexURI);
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- if( body.indexOf("j_security_check") > 0 )
- fail("get of "+indexURI+" redirected to login page");
-
- // Wait more than 1 minute to let session time out
+ // Wait more than 30 secs to let SSO time out -- 15 for the sessions
+ // (as above) and 15 for the SSOs maxEmptyLife
try {
- Thread.sleep(75000);
+ Thread.sleep(30500);
}
catch (InterruptedException ie)
{
- log.debug("Interrupted while waiting for session expiration");
+ log.debug("Interrupted while waiting for SSO expiration");
}
- // Try accessing war1 again
- war1Index = new GetMethod(serverA+"/war3/index.html");
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- log.debug("body: " + body);
- if( body.indexOf("j_security_check") < 0 )
- fail("get of /war1/index.html not redirected to login page");
+ // Try accessing war3 again on both nodes -- should fail
+ SSOBaseCase.checkAccessDenied(httpConn, warA3 + "index.jsp");
+ SSOBaseCase.checkAccessDenied(httpConn, warB3 + "index.jsp");
+ // Confirm that the SSO we created at the start was removed from
+ // the cache
+ Set ssoIds = getSSOIds(adaptors[0]);
+ log.info("node0 sso ids are " + ssoIds);
+ assertEquals("node0 cache has no SSOs", 0, ssoIds.size());
+ ssoIds = getSSOIds(adaptors[1]);
+ log.info("node1 sso ids are " + ssoIds);
+ assertEquals("node1 cache has no SSOs", 0, ssoIds.size());
}
+
+ private Set getSSOIds(RMIAdaptor adaptor) throws Exception
+ {
+ Fqn ssoRoot = new Fqn(new Object[] {"SSO"});
+ ObjectName oname = new ObjectName("jboss.cache:service=TomcatClusteringCache");
+ return (Set) adaptor.invoke(oname, "getChildrenNames",
+ new Object[]{ ssoRoot },
+ new String[]{ Fqn.class.getName() });
+ }
}
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SSOBaseCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SSOBaseCase.java 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SSOBaseCase.java 2006-11-02 20:44:41 UTC (rev 58020)
@@ -1,18 +1,34 @@
/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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 software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
package org.jboss.test.web.test;
+import java.io.IOException;
import java.net.HttpURLConnection;
import junit.framework.TestCase;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -35,132 +51,137 @@
Category log)
throws Exception
{
+ String warA1 = serverA + "/war1/";
+ String warB2 = serverB + "/war2/";
+
// Start by accessing the secured index.html of war1
HttpClient httpConn = new HttpClient();
- GetMethod indexGet = new GetMethod(serverA+"/war1/index.html");
- int responseCode = httpConn.executeMethod(indexGet);
- String body = indexGet.getResponseBodyAsString();
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+
+ checkAccessDenied(httpConn, warA1 + "index.html");
HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
- }
+
+ String sessionID = getSessionIdFromState(state);
log.debug("Saw JSESSIONID="+sessionID);
// Submit the login form
- PostMethod formPost = new PostMethod(serverA+"/war1/j_security_check");
- formPost.addRequestHeader("Referer", serverA+"/war1/login.html");
+ executeFormLogin(httpConn, warA1);
+
+ String ssoID = processSSOCookie(state, serverA, serverB);
+ log.debug("Saw JSESSIONIDSSO="+ssoID);
+
+ // Pause a moment before switching wars to better simulate real life
+ // use cases. Otherwise, the test case can "outrun" the async
+ // replication in the TreeCache used by the clustered SSO
+ // 500 ms is a long time, but this isn't a test of replication speed
+ // and we don't want spurious failures.
+ if (!serverA.equals(serverB))
+ Thread.sleep(500);
+
+ // Now try getting the war2 index using the JSESSIONIDSSO cookie
+ log.debug("Prepare /war2/index.html get");
+ checkAccessAllowed(httpConn, warB2 + "index.html");
+
+ /* Access a secured servlet that calls a secured ejb in war2 to test
+ propagation of the SSO identity to the ejb container. */
+ checkAccessAllowed(httpConn, warB2 + "EJBServlet");
+
+ // Now try logging out of war2
+ executeLogout(httpConn, warB2);
+
+ // Again, pause before switching wars
+ if (!serverA.equals(serverB))
+ Thread.sleep(500);
+
+ // Try accessing war1 again
+ checkAccessDenied(httpConn, warA1 + "index.html");
+
+ // Try accessing war2 again
+ checkAccessDenied(httpConn, warB2 + "index.html");
+
+ }
+
+ public static void executeLogout(HttpClient httpConn, String warURL) throws IOException, HttpException
+ {
+ GetMethod logout = new GetMethod(warURL + "Logout");
+ logout.setFollowRedirects(false);
+ int responseCode = httpConn.executeMethod(logout.getHostConfiguration(),
+ logout, httpConn.getState());
+ assertTrue("Logout: Saw HTTP_MOVED_TEMP("+responseCode+")",
+ responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
+ Header location = logout.getResponseHeader("Location");
+ String indexURI = location.getValue();
+ if( indexURI.indexOf("index.html") < 0 )
+ fail("get of " + warURL + "Logout not redirected to login page");
+ }
+
+ public static void checkAccessAllowed(HttpClient httpConn, String url) throws IOException, HttpException
+ {
+ GetMethod war2Index = new GetMethod(url);
+ int responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
+ war2Index, httpConn.getState());
+ assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
+ String body = war2Index.getResponseBodyAsString();
+ if( body.indexOf("j_security_check") > 0 )
+ fail("get of " + url + " redirected to login page");
+ }
+
+ public static void executeFormLogin(HttpClient httpConn, String warURL) throws IOException, HttpException
+ {
+ PostMethod formPost = new PostMethod(warURL + "j_security_check");
+ formPost.addRequestHeader("Referer", warURL + "login.html");
formPost.addParameter("j_username", "jduke");
formPost.addParameter("j_password", "theduke");
- responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
- formPost, state);
- String response = formPost.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
+ int responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
+ formPost, httpConn.getState());
assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
// Follow the redirect to the index.html page
Header location = formPost.getResponseHeader("Location");
String indexURI = location.getValue();
- GetMethod war1Index = new GetMethod(indexURI);
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
+ GetMethod warIndex = new GetMethod(indexURI);
+ responseCode = httpConn.executeMethod(warIndex.getHostConfiguration(),
+ warIndex, httpConn.getState());
assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
+ String body = warIndex.getResponseBodyAsString();
if( body.indexOf("j_security_check") > 0 )
fail("get of "+indexURI+" redirected to login page");
+ }
- cookies = state.getCookies();
+ public static void checkAccessDenied(HttpClient httpConn, String url) throws IOException, HttpException
+ {
+ GetMethod indexGet = new GetMethod(url);
+ int responseCode = httpConn.executeMethod(indexGet);
+ String body = indexGet.getResponseBodyAsString();
+ assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
+ assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+ }
+
+ public static String processSSOCookie(HttpState state, String serverA, String serverB)
+ {
+ Cookie[] cookies = state.getCookies();
String ssoID = null;
for(int c = 0; c < cookies.length; c ++)
{
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONIDSSO") )
+ if( "JSESSIONIDSSO".equalsIgnoreCase(cookies[c].getName()) )
{
- ssoID = k.getValue();
+ ssoID = cookies[c].getValue();
if (serverA.equals(serverB) == false)
{
// Make an sso cookie to send to serverB
- Cookie copy = copyCookie(k, serverB);
+ Cookie copy = copyCookie(cookies[c], serverB);
state.addCookie(copy);
- log.debug("Added state cookie: "+copy);
}
}
}
- assertTrue("Saw JSESSIONIDSSO", ssoID != null);
- log.debug("Saw JSESSIONIDSSO="+ssoID);
-
- // Now try getting the war2 index using the JSESSIONIDSSO cookie
- log.debug("Prepare /war2/index.html get");
- GetMethod war2Index = new GetMethod(serverB+"/war2/index.html");
- responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
- war2Index, state);
- response = war2Index.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Index.getResponseBodyAsString();
- log.debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war2/index.html redirected to login page");
-
- /* Access a secured servlet that calls a secured ejb in war2 to test
- propagation of the SSO identity to the ejb container.
- */
- GetMethod war2Servlet = new GetMethod(serverB+"/war2/EJBServlet");
- responseCode = httpConn.executeMethod(war2Servlet.getHostConfiguration(),
- war2Servlet, state);
- response = war2Servlet.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Servlet.getResponseBodyAsString();
- log.debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war2/EJBServlet redirected to login page");
-
- // Now try logging out of war2
- GetMethod war2Logout = new GetMethod(serverB+"/war2/Logout");
- war2Logout.setFollowRedirects(false);
- responseCode = httpConn.executeMethod(war2Logout.getHostConfiguration(),
- war2Logout, state);
- response = war2Logout.getStatusText();
- log.debug("responseCode="+responseCode+", response="+response);
- assertTrue("Logout: Saw HTTP_MOVED_TEMP("+responseCode+")",
- responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
- location = war2Logout.getResponseHeader("Location");
- indexURI = location.getValue();
- if( indexURI.indexOf("index.html") < 0 )
- fail("get of /war2/Logout not redirected to login page");
- // Try accessing war1 again
- war1Index = new GetMethod(serverA+"/war1/index.html");
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- log.debug("body: " + body);
- if( body.indexOf("j_security_check") < 0 )
- fail("get of /war1/index.html not redirected to login page");
+ assertNotNull("Saw JSESSIONIDSSO", ssoID);
- // Try accessing war2 again
- war2Index = new GetMethod(serverB+"/war2/index.html");
- responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
- war2Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Index.getResponseBodyAsString();
- log.debug("body: " + body);
- if( body.indexOf("j_security_check") < 0 )
- fail("get of /war2/index.html not redirected to login page");
-
+ return ssoID;
}
- private static Cookie copyCookie(Cookie toCopy, String targetServer)
+ public static Cookie copyCookie(Cookie toCopy, String targetServer)
{
// Parse the target server down to a domain name
int index = targetServer.indexOf("://");
@@ -187,4 +208,17 @@
false);
return copy;
}
+
+ public static String getSessionIdFromState(HttpState state)
+ {
+ Cookie[] cookies = state.getCookies();
+ String sessionID = null;
+ for(int c = 0; c < cookies.length; c ++)
+ {
+ if( "JSESSIONID".equalsIgnoreCase(cookies[c].getName()) )
+ sessionID = cookies[c].getName();
+ }
+ return sessionID;
+
+ }
}
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/main/org/jboss/test/web/test/SingleSignOnUnitTestCase.java 2006-11-02 20:44:41 UTC (rev 58020)
@@ -1,20 +1,26 @@
/*
- * JBoss, the OpenSource J2EE webOS
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This 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 software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
package org.jboss.test.web.test;
-import java.net.HttpURLConnection;
-
-import org.apache.commons.httpclient.Cookie;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
import org.jboss.test.JBossTestCase;
import org.jboss.test.JBossTestSetup;
import junit.framework.Test;
@@ -27,7 +33,7 @@
*/
public class SingleSignOnUnitTestCase extends JBossTestCase
{
- private String baseURLNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/";
+ private String baseURLNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080);
public SingleSignOnUnitTestCase(String name)
{
@@ -40,86 +46,12 @@
*/
public void testFormAuthSingleSignOn() throws Exception
{
- // Start by accessing the secured index.html of war1
- HttpClient httpConn = new HttpClient();
- GetMethod indexGet = new GetMethod(baseURLNoAuth+"war1/index.html");
- int responseCode = httpConn.executeMethod(indexGet);
- String body = indexGet.getResponseBodyAsString();
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+ log.info("+++ testFormAuthSingleSignOn");
- HttpState state = httpConn.getState();
- Cookie[] cookies = state.getCookies();
- String sessionID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONID") )
- sessionID = k.getValue();
- }
- getLog().debug("Saw JSESSIONID="+sessionID);
+ SSOBaseCase.executeFormAuthSingleSignOnTest(baseURLNoAuth, baseURLNoAuth, getLog());
- // Submit the login form
- PostMethod formPost = new PostMethod(baseURLNoAuth+"war1/j_security_check");
- formPost.addRequestHeader("Referer", baseURLNoAuth+"war1/login.html");
- formPost.addParameter("j_username", "jduke");
- formPost.addParameter("j_password", "theduke");
- responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
- formPost, state);
- String response = formPost.getStatusText();
- getLog().debug("responseCode="+responseCode+", response="+response);
- assertTrue("Saw HTTP_MOVED_TEMP("+responseCode+")",
- responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
-
- // Follow the redirect to the index.html page
- Header location = formPost.getResponseHeader("Location");
- String indexURI = location.getValue();
- GetMethod war1Index = new GetMethod(indexURI);
- responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
- war1Index, state);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war1Index.getResponseBodyAsString();
- if( body.indexOf("j_security_check") > 0 )
- fail("get of "+indexURI+" redirected to login page");
-
- cookies = state.getCookies();
- String ssoID = null;
- for(int c = 0; c < cookies.length; c ++)
- {
- Cookie k = cookies[c];
- if( k.getName().equalsIgnoreCase("JSESSIONIDSSO") )
- ssoID = k.getValue();
}
- assertTrue("Saw JSESSIONIDSSO", ssoID != null);
- getLog().debug("Saw JSESSIONIDSSO="+ssoID);
- // Now try getting the war2 index using the JSESSIONIDSSO cookie
- GetMethod war2Index = new GetMethod(baseURLNoAuth+"war2/index.html");
- responseCode = httpConn.executeMethod(war2Index.getHostConfiguration(),
- war2Index, state);
- response = war2Index.getStatusText();
- getLog().debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Index.getResponseBodyAsString();
- getLog().debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war2/index.html redirected to login page");
-
- /* Access a secured servlet that calls a secured ejb in war2 to test
- propagation of the SSO identity to the ejb container.
- */
- GetMethod war2Servlet = new GetMethod(baseURLNoAuth+"war2/EJBServlet");
- responseCode = httpConn.executeMethod(war2Servlet.getHostConfiguration(),
- war2Servlet, state);
- response = war2Servlet.getStatusText();
- getLog().debug("responseCode="+responseCode+", response="+response);
- assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
- body = war2Servlet.getResponseBodyAsString();
- getLog().debug("body: "+body);
- if( body.indexOf("j_security_check") > 0 )
- fail("get of /war2/EJBServlet redirected to login page");
- }
-
/** One time setup for all SingleSignOnUnitTestCase unit tests
*/
public static Test suite() throws Exception
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/test-configs/tomcat-sso-cluster/deploy/jbossweb-tomcat55.sar/server.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/test-configs/tomcat-sso-cluster/deploy/jbossweb-tomcat55.sar/server.xml 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/test-configs/tomcat-sso-cluster/deploy/jbossweb-tomcat55.sar/server.xml 2006-11-02 20:44:41 UTC (rev 58020)
@@ -14,7 +14,7 @@
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
- <Engine name="jboss.web" defaultHost="localhost">
+ <Engine name="jboss.web" defaultHost="localhost" backgroundProcessorDelay="10">
<!-- The JAAS based authentication and authorization realm implementation
- certificatePrincipal : the class name of the
@@ -32,7 +32,7 @@
deployed to this host. Provides SSO across a cluster.
-->
<Valve className="org.jboss.web.tomcat.tc5.sso.ClusteredSingleSignOn"
- debug="2" />
+ debug="2" maxEmptyLife="11" processExpiresInterval="5"/>
<!-- Default context parameters -->
<DefaultContext cookies="true" crossContext="true" override="true"/>
Modified: branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/web/sso/war/web-sso-expire.xml
===================================================================
--- branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/web/sso/war/web-sso-expire.xml 2006-11-02 18:57:08 UTC (rev 58019)
+++ branches/JBoss_4_0_3_SP1_JBAS-3808/testsuite/src/resources/web/sso/war/web-sso-expire.xml 2006-11-02 20:44:41 UTC (rev 58020)
@@ -5,7 +5,7 @@
<web-app>
<description>WebApp Integration Tests</description>
- <distributable/>
+ <!--distributable/-->
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>org.jboss.test.web.servlets.LogoutServlet</servlet-class>
@@ -16,6 +16,10 @@
<url-pattern>/Logout</url-pattern>
</servlet-mapping>
+ <session-config>
+ <session-timeout>1</session-timeout>
+ </session-config>
+
<security-constraint>
<web-resource-collection>
<web-resource-name>Restricted</web-resource-name>
@@ -28,10 +32,6 @@
</auth-constraint>
</security-constraint>
- <session-config>
- <session-timeout>1</session-timeout>
- </session-config>
-
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
More information about the jboss-cvs-commits
mailing list