[jboss-cvs] JBossAS SVN: r62989 - in projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test: audit and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 11 10:32:10 EDT 2007


Author: anil.saldhana at jboss.com
Date: 2007-05-11 10:32:10 -0400 (Fri, 11 May 2007)
New Revision: 62989

Added:
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditTestAssociation.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditUnitTestCase.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/TestAuditProvider.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java
Modified:
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/EJBXACMLUnitTestCase.java
   projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/WebXACMLUnitTestCase.java
   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:
tests 

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditTestAssociation.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditTestAssociation.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditTestAssociation.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -0,0 +1,35 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, 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.audit;
+
+//$Id$
+
+/**
+ *  A test class that stores a static thread local
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  May 11, 2007 
+ *  @version $Revision$
+ */
+public class AuditTestAssociation
+{
+   public static ThreadLocal auditEventLocal = new ThreadLocal();
+}

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditUnitTestCase.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/AuditUnitTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -0,0 +1,85 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, 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.audit; 
+
+import org.jboss.security.SecurityContext; 
+import org.jboss.security.audit.AuditEvent;
+import org.jboss.security.audit.AuditLevel;
+import org.jboss.security.audit.AuditManager;  
+import org.jboss.security.audit.config.AuditProviderEntry;
+import org.jboss.security.config.ApplicationPolicy;
+import org.jboss.security.config.AuditInfo;
+import org.jboss.security.config.SecurityConfiguration;
+import org.jboss.security.plugins.SecurityContextFactory;
+
+import junit.framework.TestCase;
+
+//$Id$
+
+/**
+ *  Tests for the Auditing Layer
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  May 10, 2007 
+ *  @version $Revision$
+ */
+public class AuditUnitTestCase extends TestCase
+{ 
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      setUpSecurityConfiguration();
+   }
+   
+   /**
+    * We invoke the AuditManager on the security context to audit
+    * a particular AuditEvent. The AuditManager is configured with a 
+    * test logging provider that basically places the event on a 
+    * thread local of a static class. The test then checks the 
+    * thread local for the audit event.
+    */
+   public void testAuditConfiguration()
+   {
+      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+      AuditManager am = sc.getAuditManager();
+      AuditEvent ae = new AuditEvent(AuditLevel.ERROR);
+      am.audit(ae);
+      
+      //Now check that the Audit Event has been placed on the thread local
+      //by our TestAuditProvider
+      AuditEvent aev = (AuditEvent) AuditTestAssociation.auditEventLocal.get();
+      assertEquals("Audit events are the same", ae, aev);
+   }
+   
+   
+   private void setUpSecurityConfiguration()
+   {
+      String p = TestAuditProvider.class.getName();
+      
+      ApplicationPolicy ap = new ApplicationPolicy("test");
+      AuditInfo auditInfo = new AuditInfo("test");
+      AuditProviderEntry ape = new AuditProviderEntry(p);
+      auditInfo.add(ape); 
+      ap.setAuditInfo(auditInfo);
+      SecurityConfiguration.addApplicationPolicy(ap);
+   } 
+}

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/TestAuditProvider.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/TestAuditProvider.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/audit/TestAuditProvider.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, 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.audit;
+
+import org.jboss.security.audit.AbstractAuditProvider;
+import org.jboss.security.audit.AuditEvent;
+
+//$Id$
+
+/**
+ *  Test Audit Provider that places the Audit Event on the
+ *  thread local of AuditTestAssociation
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  May 11, 2007 
+ *  @version $Revision$
+ */
+public class TestAuditProvider extends AbstractAuditProvider
+{
+   public TestAuditProvider()
+   {   
+   }
+
+   @Override
+   public void audit(AuditEvent ae)
+   {
+      AuditTestAssociation.auditEventLocal.set(ae);
+   } 
+}

Added: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authentication/JBossAuthenticationManagerUnitTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -0,0 +1,98 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2007, 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.authentication;
+
+import java.security.Principal;
+import java.util.HashMap;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
+
+import org.jboss.security.AuthenticationManager;
+import org.jboss.security.SimplePrincipal;
+import org.jboss.security.auth.callback.AppCallbackHandler;
+import org.jboss.security.plugins.JBossAuthenticationManager;
+
+import junit.framework.TestCase;
+
+//$Id$
+
+/**
+ *  Unit tests for the JBossAuthenticationManager
+ *  @author Anil.Saldhana at redhat.com
+ *  @since  May 10, 2007 
+ *  @version $Revision$
+ */
+public class JBossAuthenticationManagerUnitTestCase extends TestCase
+{ 
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      establishSecurityConfiguration();
+   }
+
+   public void testSecurityDomain() throws Exception
+   {
+      AuthenticationManager am = new JBossAuthenticationManager("test1", 
+            new AppCallbackHandler("a","b".toCharArray()));
+      assertEquals("test1", am.getSecurityDomain());
+   }
+   
+   public void testLogin() throws Exception
+   {
+      Principal p = new SimplePrincipal("jduke");
+      AppCallbackHandler acbh = new AppCallbackHandler("jduke","theduke".toCharArray());
+      AuthenticationManager am = new JBossAuthenticationManager("test",acbh);
+      assertTrue(am.isValid(p, "theduke")); 
+      assertNotNull("Subject is valid",am.getActiveSubject());
+      assertTrue("Principal is present",
+            am.getActiveSubject().getPrincipals().contains(p));
+   }  
+   
+   private void establishSecurityConfiguration()
+   { 
+      Configuration.setConfiguration(new TestConfig());
+   }
+   
+   public class TestConfig extends Configuration
+   { 
+      @Override
+      public AppConfigurationEntry[] getAppConfigurationEntry(String name)
+      {
+         HashMap map = new HashMap();
+         map.put("usersProperties", "users.properties"); 
+         map.put("rolesProperties", "roles.properties");
+         String moduleName = "org.jboss.security.auth.spi.UsersRolesLoginModule";
+         AppConfigurationEntry ace = new AppConfigurationEntry(moduleName,
+               LoginModuleControlFlag.REQUIRED, map);
+         
+         return new AppConfigurationEntry[]{ace};
+      }
+
+      @Override
+      public void refresh()
+      {
+      } 
+   }
+}

Modified: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/EJBXACMLUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/EJBXACMLUnitTestCase.java	2007-05-11 14:31:21 UTC (rev 62988)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/EJBXACMLUnitTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -129,7 +129,7 @@
    
    private void setSecurityConfiguration() throws Exception
    {
-      SecurityConfiguration.addApplicationPolicy("other", new ApplicationPolicy("other"));
+      SecurityConfiguration.addApplicationPolicy(new ApplicationPolicy("other"));
    }
    
    public class StatelessSession

Modified: projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/WebXACMLUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/WebXACMLUnitTestCase.java	2007-05-11 14:31:21 UTC (rev 62988)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/authorization/xacml/WebXACMLUnitTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -128,6 +128,6 @@
    
    private void setSecurityConfiguration() throws Exception
    {
-      SecurityConfiguration.addApplicationPolicy("other", new ApplicationPolicy("other"));
+      SecurityConfiguration.addApplicationPolicy(new ApplicationPolicy("other"));
    } 
 }

Modified: 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	2007-05-11 14:31:21 UTC (rev 62988)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/MappingContextTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -44,8 +44,7 @@
 { 
    public void testDeploymentRolesProvider()
    {
-      SecurityConfiguration.addApplicationPolicy(securityDomain,
-            createApplicationPolicy(securityDomain));
+      SecurityConfiguration.addApplicationPolicy(createApplicationPolicy(securityDomain));
       SecurityContext sc= getSC(securityDomain);
       HashSet hs = new HashSet();
       hs.add("t1");

Modified: 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	2007-05-11 14:31:21 UTC (rev 62988)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextBaseTest.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -51,8 +51,8 @@
    
    public void testSecurityConfiguration()
    {
-      ApplicationPolicy ap = createApplicationPolicy(null);
-      SecurityConfiguration.addApplicationPolicy(securityDomain, ap);
+      ApplicationPolicy ap = createApplicationPolicy(securityDomain);
+      SecurityConfiguration.addApplicationPolicy(ap);
       assertEquals(SecurityConfiguration.getApplicationPolicy(securityDomain), ap);
    }
    

Modified: 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	2007-05-11 14:31:21 UTC (rev 62988)
+++ projects/security/security-jboss-sx/trunk/src/tests/org/jboss/test/securitycontext/SecurityContextTestCase.java	2007-05-11 14:32:10 UTC (rev 62989)
@@ -25,8 +25,7 @@
 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;
@@ -44,7 +43,7 @@
 {
    public void setUp()
    { 
-      SecurityConfiguration.addApplicationPolicy(securityDomain, createApplicationPolicy(securityDomain));
+      SecurityConfiguration.addApplicationPolicy(createApplicationPolicy(securityDomain));
    }
    
    public void testSecurityDomain()




More information about the jboss-cvs-commits mailing list