[jboss-cvs] JBossAS SVN: r74813 - projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 18 16:19:13 EDT 2008
Author: anil.saldhana at jboss.com
Date: 2008-06-18 16:19:13 -0400 (Wed, 18 Jun 2008)
New Revision: 74813
Added:
projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/SAThreadLocalUnitTestCase.java
Log:
SECURITY-246: test for SA threadlocal
Added: projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/SAThreadLocalUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/SAThreadLocalUnitTestCase.java (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/tests/org/jboss/test/securityassociation/SAThreadLocalUnitTestCase.java 2008-06-18 20:19:13 UTC (rev 74813)
@@ -0,0 +1,122 @@
+/*
+ * 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.securityassociation;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import junit.framework.TestCase;
+
+import org.jboss.security.SecurityAssociation;
+import org.jboss.security.SimplePrincipal;
+
+/**
+ * Test that the security context thread locals do NOT propagate to child threads
+ *
+ @author Scott.Stark at jboss.org
+ @version $Revision: 37406 $
+ */
+public class SAThreadLocalUnitTestCase extends TestCase
+{
+ private Principal authPrincipal;
+ private Subject authSubject;
+
+ public SAThreadLocalUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the order of PermissionNames
+ */
+ public void testSecurityContext()
+ {
+ authPrincipal = new SimplePrincipal("jduke");
+ authSubject = new Subject();
+ authSubject.getPrincipals().add(authPrincipal);
+ SecurityAssociation.pushSubjectContext(authSubject, authPrincipal, "theduke");
+ validateSettings(false);
+ }
+ public void testThreadLocal() throws Exception
+ {
+ testSecurityContext();
+ TestThread t = new TestThread("testThreadLocal", true);
+ t.start();
+ t.join();
+ if( t.error != null )
+ {
+ t.error.printStackTrace();
+ fail("TestThread saw an error");
+ }
+ }
+
+ /**
+ * SecurityAssociation.getSubject() == authSubject
+ * SecurityAssociation.getPrincipal() == authPrincipal
+ */
+ private void validateSettings(boolean expectNull)
+ {
+ Subject s = SecurityAssociation.getSubject();
+ Principal p = SecurityAssociation.getPrincipal();
+
+ if( expectNull )
+ {
+ assertNull("getSubject() == null", s);
+ assertNull("getPrincipal() == null", p);
+ }
+ else
+ {
+ assertTrue("getSubject() == authSubject", authSubject.equals(s));
+ assertTrue("getPrincipal() == authPrincipal", authPrincipal.equals(p));
+ }
+ }
+
+ class TestThread extends Thread
+ {
+ Throwable error;
+ boolean expectNull;
+ TestThread(String name, boolean expectNull)
+ {
+ super(name);
+ this.expectNull = expectNull;
+ }
+
+ public void run()
+ {
+ try
+ {
+ validateSettings(expectNull);
+ }
+ catch(Throwable e)
+ {
+ error = e;
+ }
+ }
+ }
+
+ protected void setUp()
+ {
+ System.setProperty("org.jboss.security.SecurityAssociation.ThreadLocal", "true");
+ SecurityAssociation.setServer();
+ }
+}
More information about the jboss-cvs-commits
mailing list