[Jboss-cvs] JBossAS SVN: r56363 - in trunk/testsuite/src/main/org/jboss/test/security/test: . mapping

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 28 17:00:23 EDT 2006


Author: anil.saldhana at jboss.com
Date: 2006-08-28 17:00:23 -0400 (Mon, 28 Aug 2006)
New Revision: 56363

Added:
   trunk/testsuite/src/main/org/jboss/test/security/test/mapping/
   trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingConfigUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingWebTestCase.java
Log:
JBAS-3577: Role Mapping + Mapping Framework

Added: trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingConfigUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingConfigUnitTestCase.java	2006-08-28 20:52:55 UTC (rev 56362)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingConfigUnitTestCase.java	2006-08-28 21:00:23 UTC (rev 56363)
@@ -0,0 +1,96 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., 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.security.test.mapping;
+ 
+import java.util.Map;
+
+import org.jboss.security.auth.container.config.AuthModuleEntry;
+import org.jboss.security.auth.login.BaseAuthenticationInfo;
+import org.jboss.security.auth.login.JASPIAuthenticationInfo;
+import org.jboss.security.authorization.config.SecurityConfigObjectModelFactory;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.MappingInfo;
+import org.jboss.security.config.PolicyConfig;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+import org.jboss.test.security.container.auth.config.JASPIConfigurationTestCase;
+
+//$Id: RoleMappingConfigUnitTestCase.java 45690 2006-06-20 04:53:17Z asaldhana $
+
+/**
+ *  Test the RoleMapping Framework Configuration
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  August 24, 2006 
+ *  @version $Revision: 45690 $
+ */
+public class RoleMappingConfigUnitTestCase extends JASPIConfigurationTestCase
+{ 
+   public RoleMappingConfigUnitTestCase(String name)
+   {
+      super(name); 
+   } 
+   
+   public void testRoleMappingInfo() throws Exception
+   {
+      String loc = "security/authorization/config/rolemapping-config.xml";
+      PolicyConfig config = getPolicyConfig(loc,new SecurityConfigObjectModelFactory());
+      assertNotNull("Returned PolicyConfig is != null ?", config);
+      
+      ApplicationPolicy aPolicy = config.get("TestRoleMapping"); 
+      //Test Authentication
+      BaseAuthenticationInfo infoBase = aPolicy.getAuthenticationInfo();
+      assertTrue("infoBase==AuthenticationJaspiInfo", infoBase instanceof JASPIAuthenticationInfo);
+      JASPIAuthenticationInfo info = (JASPIAuthenticationInfo)infoBase; 
+      assertTrue("jaspi != null", info != null); 
+      AuthModuleEntry[] authEntry = info.getAuthModuleEntry();
+      //Get the first AuthModule
+      AuthModuleEntry aEntry1 = authEntry[0];
+      validateAuthModule1(aEntry1); 
+      //Get the second AuthModule
+      AuthModuleEntry aEntry2 = authEntry[1];
+      validateAuthModule2(aEntry2);
+      
+      //Test RoleMapping 
+      MappingInfo authzInfo = aPolicy.getRoleMappingInfo();
+      MappingModuleEntry[] authzEntries = authzInfo.getMappingModuleEntry();
+      assertTrue("AuthzInfo != null", authzInfo != null);
+      assertTrue("authzEntries has 1 element", authzEntries.length == 1);
+      // Get the first AuthorizationModuleEntry
+      MappingModuleEntry azEntry1 = authzEntries[0];
+      validateRoleMappingModuleEntry(azEntry1);  
+   }
+   
+   private void validateRoleMappingModuleEntry(MappingModuleEntry ame)
+   {
+      assertEquals("policy.module1.class.name", ame.getMappingModuleName());
+      Map aEntry1Options = ame.getOptions();
+      assertNotNull("Options in the first AuthModule != null", aEntry1Options);
+      assertTrue( "Length of options == 3", aEntry1Options.size() == 3); 
+      String usersProperties = (String) aEntry1Options.get("usersProperties");
+      assertNotNull("options.usersProperties exists", usersProperties);
+      assertTrue("options.usersProperties == props/jbossws-users.properties",
+            usersProperties.equals("props/jbossws-users.properties"));
+      String rolesProperties = (String) aEntry1Options.get("rolesProperties");
+      assertNotNull("options.rolesProperties exists", rolesProperties);
+      assertTrue("options.rolesProperties == props/jbossws-roles.properties",
+            rolesProperties.equals("props/jbossws-roles.properties"));
+   } 
+}

Added: trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingWebTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingWebTestCase.java	2006-08-28 20:52:55 UTC (rev 56362)
+++ trunk/testsuite/src/main/org/jboss/test/security/test/mapping/RoleMappingWebTestCase.java	2006-08-28 21:00:23 UTC (rev 56363)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */ 
+package org.jboss.test.security.test.mapping;
+
+import java.net.HttpURLConnection; 
+
+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.jboss.test.JBossTestCase;
+import org.jboss.test.JBossTestSetup; 
+
+/**
+ *  Test role mapping logic for the web layer
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @version $Revision$
+ *  @since  Aug 27, 2006
+ */
+public class RoleMappingWebTestCase extends JBossTestCase
+{ 
+   private String baseURLNoAuth = "http://" + getServerHost() 
+            + ":" + Integer.getInteger("web.port", 8080) + "/"; 
+   private HttpClient httpConn = new HttpClient();
+
+   public RoleMappingWebTestCase(String name)
+   {
+      super(name); 
+   }
+   
+   /**
+    * Test a FORM auth simple webapp. A role of "testRole" will
+    * be mapped to Authorized User via the role mapping logic
+    */
+   public void testWebAccess() throws Exception
+   {
+      GetMethod indexGet = new GetMethod(baseURLNoAuth+"web-role-map/Secured.jsp");
+      int responseCode = httpConn.executeMethod(indexGet);
+      String body = indexGet.getResponseBodyAsString();
+      assertTrue("Get OK("+responseCode+")", responseCode == HttpURLConnection.HTTP_OK);
+      assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
+
+      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);
+
+      // Submit the login form
+      PostMethod formPost = new PostMethod(baseURLNoAuth+"web-role-map/j_security_check");
+      formPost.addRequestHeader("Referer", baseURLNoAuth+"web-role-map/login.html");
+      formPost.addParameter("j_username", "user");
+      formPost.addParameter("j_password", "pass");
+      responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
+         formPost, state); 
+      String response = formPost.getStatusText();
+      log.debug("responseCode="+responseCode+", response="+response);
+      assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
+
+      //  Follow the redirect to the SecureServlet
+      Header location = formPost.getResponseHeader("Location");
+      String indexURI = location.getValue();
+      GetMethod war1Index = new GetMethod(indexURI);
+      responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
+         war1Index, state);
+      response = war1Index.getStatusText();
+      log.debug("responseCode="+responseCode+", response="+response);
+      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");
+   } 
+    
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      suite.addTest(new TestSuite(RoleMappingWebTestCase.class));
+
+      // Create an initializer for the test suite
+      Test wrapper = new JBossTestSetup(suite)
+      {
+         protected void setUp() throws Exception
+         {
+            super.setUp();
+            deploy(getResourceURL("security-spi/rolemapping/rolemapping-test-service.xml")); 
+            deploy("web-role-map.war");
+         }
+         protected void tearDown() throws Exception
+         {
+            undeploy(getResourceURL("security-spi/rolemapping/rolemapping-test-service.xml"));
+            undeploy("web-role-map.war");
+            super.tearDown();
+         }
+      };
+      return wrapper;
+   }
+}




More information about the jboss-cvs-commits mailing list