[jboss-cvs] JBossAS SVN: r59233 - in projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test: . securitycontext

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 26 16:09:03 EST 2006


Author: anil.saldhana at jboss.com
Date: 2006-12-26 16:09:02 -0500 (Tue, 26 Dec 2006)
New Revision: 59233

Added:
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/MappingContextTestCase.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextBaseTest.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextTestCase.java
Log:
Security Context tests

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/MappingContextTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/MappingContextTestCase.java	2006-12-26 21:08:07 UTC (rev 59232)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/MappingContextTestCase.java	2006-12-26 21:09:02 UTC (rev 59233)
@@ -0,0 +1,70 @@
+/*
+  * 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.securitycontext; 
+
+import java.security.acl.Group;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SimpleGroup;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.security.mapping.MappingContext;
+
+//$Id$
+
+/**
+ *  Test the various mapping providers
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Dec 26, 2006 
+ *  @version $Revision$
+ */
+public class MappingContextTestCase extends SecurityContextBaseTest
+{ 
+   public void testDeploymentRolesProvider()
+   {
+      SecurityConfiguration.addApplicationPolicy(securityDomain,
+            createApplicationPolicy(securityDomain));
+      SecurityContext sc= getSC(securityDomain);
+      HashSet hs = new HashSet();
+      hs.add("t1");
+      hs.add("t2");
+      
+      HashMap rolesMap = new HashMap();
+      rolesMap.put(principal.getName(), hs );
+      
+      HashMap map = new HashMap();
+      map.put(SecurityConstants.PRINCIPAL_IDENTIFIER, principal);
+      map.put(SecurityConstants.DEPLOYMENT_PRINCIPAL_ROLES_MAP, rolesMap);
+      
+      Group grp = new SimpleGroup(SecurityConstants.ROLES_IDENTIFIER);
+      grp.addMember(new SimplePrincipal("oldRole"));
+      MappingContext mc = sc.getMappingContext(Group.class);
+      mc.performMapping(map, grp);
+      
+      assertFalse("oldRole does not exist", grp.isMember(new SimplePrincipal("oldRole")));
+      assertTrue("t1 exists?",grp.isMember(new SimplePrincipal("t1")));
+      assertTrue("t2 exists?",grp.isMember(new SimplePrincipal("t2")));
+   }
+}

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextBaseTest.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextBaseTest.java	2006-12-26 21:08:07 UTC (rev 59232)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextBaseTest.java	2006-12-26 21:09:02 UTC (rev 59233)
@@ -0,0 +1,97 @@
+/*
+  * 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.securitycontext;
+ 
+import java.security.Principal;
+import java.util.List;
+
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.Util;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.RoleMappingInfo;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.security.mapping.config.MappingModuleEntry;
+import org.jboss.security.plugins.JBossSecurityContext;
+
+import junit.framework.TestCase;
+
+//$Id$
+
+/**
+ *  Base test class with common methods
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Dec 26, 2006 
+ *  @version $Revision$
+ */
+public class SecurityContextBaseTest extends TestCase
+{ 
+   protected Principal principal = new SimplePrincipal("anil");
+   protected Object cred = "hello";
+   protected String securityDomain = "other";
+   
+   private String mappingModule = "org.jboss.security.mapping.providers.DeploymentRolesMappingProvider";
+   
+   public void testSecurityConfiguration()
+   {
+      ApplicationPolicy ap = createApplicationPolicy(null);
+      SecurityConfiguration.addApplicationPolicy(securityDomain, ap);
+      assertEquals(Util.getApplicationPolicy(securityDomain), ap);
+   }
+   
+   protected JBossSecurityContext getSC(String domain)
+   {
+      if(domain == null)
+         domain = securityDomain;
+      return new JBossSecurityContext(securityDomain);
+   }
+   
+   protected ApplicationPolicy createApplicationPolicy(String domain)
+   {
+      ApplicationPolicy ap = new ApplicationPolicy(domain);
+      ap.setRoleMappingInfo(createRoleMappingInfo(domain));
+      return ap; 
+   }
+   
+   protected ApplicationPolicy createApplicationPolicy(String domain, RoleMappingInfo rmi)
+   {
+      ApplicationPolicy ap = new ApplicationPolicy(domain);
+      ap.setRoleMappingInfo(rmi);
+      return ap; 
+   }
+   
+   protected RoleMappingInfo createRoleMappingInfo(String domain)
+   { 
+      RoleMappingInfo rmi = new RoleMappingInfo(domain);
+      rmi.add(new MappingModuleEntry(this.mappingModule));
+      return rmi;
+   }
+   
+   protected RoleMappingInfo createRoleMappingInfo(String domain, List<String> moduleNames)
+   {
+      RoleMappingInfo rmi = new RoleMappingInfo(domain);
+      for(String mod:moduleNames)
+      { 
+         rmi.add(new MappingModuleEntry(mod));
+      }
+      return rmi;
+   }
+}

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextTestCase.java	2006-12-26 21:08:07 UTC (rev 59232)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextTestCase.java	2006-12-26 21:09:02 UTC (rev 59233)
@@ -0,0 +1,86 @@
+/*
+  * 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.securitycontext;
+
+import java.security.acl.Group;
+import java.util.List;
+
+import javax.security.auth.Subject;
+
+import org.jboss.security.SubjectInfo;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.security.mapping.MappingContext;
+import org.jboss.security.mapping.providers.DeploymentRolesMappingProvider;
+import org.jboss.security.plugins.JBossSecurityContext;
+
+//$Id$
+
+/**
+ *  Test the Security Context
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Dec 26, 2006 
+ *  @version $Revision$
+ */
+public class SecurityContextTestCase extends SecurityContextBaseTest
+{
+   public void setUp()
+   { 
+      SecurityConfiguration.addApplicationPolicy(securityDomain, createApplicationPolicy(securityDomain));
+   }
+   
+   public void testSecurityDomain()
+   { 
+      assertEquals("Security Domain == other", getSC(securityDomain).getSecurityDomain()
+            ,securityDomain);
+   }
+   
+   public void testSubjectInfo()
+   {
+      Subject sub = new Subject();
+      SubjectInfo si = new SubjectInfo(); 
+      si.setAuthenticationPrincipal(principal);
+      si.setAuthenticationCredential(cred);
+      sub.getPrincipals().add(principal);
+      si.setAuthenticatedSubject(sub); 
+      
+      JBossSecurityContext sc = getSC(securityDomain);
+      sc.setSubjectInfo(si);
+      
+      assertEquals("SubjectInfo is equal",sc.getSubjectInfo(),si); 
+      assertEquals("Subject is equal",sc.getSubjectInfo().getAuthenticatedSubject(),sub);
+      assertEquals("Principal is equal",sc.getSubjectInfo().getAuthenticationPrincipal(),principal);
+      assertEquals("Credential is equal",sc.getSubjectInfo().getAuthenticationCredential(),cred);
+   } 
+   
+   public void testMappingContext()
+   {
+      JBossSecurityContext sc = getSC(securityDomain);
+      MappingContext mc = sc.getMappingContext(Group.class);
+      assertNotNull("Mapping Context is not null", mc); 
+      List modules = mc.getModules();
+      assertNotNull("Mapping modules not null", modules);
+      assertEquals("Module size == 1", modules.size(),1);
+      assertTrue("Deployment Roles Provider is present", 
+            modules.get(0) instanceof DeploymentRolesMappingProvider);
+   }
+   
+}




More information about the jboss-cvs-commits mailing list