[jboss-cvs] JBossAS SVN: r79943 - projects/security/security-spi/trunk/spi/src/tests/org/jboss/test/security/securitycontext.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 22 17:30:48 EDT 2008
Author: anil.saldhana at jboss.com
Date: 2008-10-22 17:30:48 -0400 (Wed, 22 Oct 2008)
New Revision: 79943
Modified:
projects/security/security-spi/trunk/spi/src/tests/org/jboss/test/security/securitycontext/SecurityContextAssociationUnitTestCase.java
Log:
SECURITY-253: test updated to test client side SecurityContextAssociation
Modified: projects/security/security-spi/trunk/spi/src/tests/org/jboss/test/security/securitycontext/SecurityContextAssociationUnitTestCase.java
===================================================================
--- projects/security/security-spi/trunk/spi/src/tests/org/jboss/test/security/securitycontext/SecurityContextAssociationUnitTestCase.java 2008-10-22 21:11:49 UTC (rev 79942)
+++ projects/security/security-spi/trunk/spi/src/tests/org/jboss/test/security/securitycontext/SecurityContextAssociationUnitTestCase.java 2008-10-22 21:30:48 UTC (rev 79943)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.security.securitycontext;
+import org.jboss.security.SecurityContext;
import org.jboss.security.SecurityContextAssociation;
import junit.framework.TestCase;
@@ -31,10 +32,48 @@
*/
public class SecurityContextAssociationUnitTestCase extends TestCase
{
- public void testClientSide()
+ private SecurityContext sc = new TestSecurityContext("test");
+
+ public void testClientSide() throws Exception
{
assertFalse("SCA is not client", SecurityContextAssociation.isClient());
SecurityContextAssociation.setClient();
assertTrue("SCA is client", SecurityContextAssociation.isClient());
+
+ //Test the VMwide association
+ SecurityContextAssociation.setSecurityContext(sc);
+
+ //Spawn two threads and see that the same sc is there
+ Thread p = new Thread(new SCThread(1));
+ p.start();
+
+ Thread q = new Thread(new SCThread(2));
+ q.start();
+
+ Thread.sleep(1000);
+ p = q = null;
}
+
+ class SCThread implements Runnable
+ {
+ int num = 0;
+
+ public SCThread(int n)
+ {
+ this.num = n;
+ }
+
+ public void run()
+ {
+ System.out.println("Inside Thread:" + num);
+
+ SecurityContext secCtx = SecurityContextAssociation.getSecurityContext();
+ if(secCtx == null)
+ throw new RuntimeException("Security Context is null:" + num);
+ if(!(secCtx == sc))
+ throw new RuntimeException("Not the same sec ctx:" + num);
+
+ System.out.println("Thread " + num + " passed SC test");
+ }
+ }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list