[jboss-cvs] Picketbox SVN: r61 - in trunk/security-jboss-sx/jbosssx/src: test/java/org/jboss/test/securityassociation and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 9 15:22:15 EST 2010


Author: anil.saldhana at jboss.com
Date: 2010-03-09 15:22:15 -0500 (Tue, 09 Mar 2010)
New Revision: 61

Modified:
   trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java
   trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
Log:
SECURITY-459: SecurityAssociation.getContextInfo will use current security context data

Modified: trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java	2010-03-08 15:43:33 UTC (rev 60)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java	2010-03-09 20:22:15 UTC (rev 61)
@@ -499,6 +499,12 @@
 
       if(key == null)
          throw new IllegalArgumentException("key is null");
+      //SECURITY-459 get it from the current security context
+      SecurityContext sc = SecurityAssociationActions.getSecurityContext();
+      if(sc != null)
+         return sc.getData().get(key); 
+      
+      //fall back
       HashMap<String,Object> contextInfo = (HashMap<String,Object>) threadContextMap.get();
       return contextInfo != null ? contextInfo.get(key) : null;
    }
@@ -851,6 +857,7 @@
     * and implements push, pop and peek stack operations on the thread local
     * ArrayList.
     */
+   @SuppressWarnings("unused")
    private static class RunAsThreadLocalStack
    {
       @SuppressWarnings("unchecked")
@@ -988,7 +995,7 @@
       }
    }
 
-   @SuppressWarnings("unchecked")
+   @SuppressWarnings({"unchecked", "unused"})
    private static class SubjectThreadLocalStack
    {
       ThreadLocal local;
@@ -1106,7 +1113,7 @@
       
    }
 
-   @SuppressWarnings("unchecked")
+   @SuppressWarnings({"unchecked","unused"})
    private static class HashMapInheritableLocal<T> 
    extends InheritableThreadLocal<HashMap<String,Object>>
    {

Modified: trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
===================================================================
--- trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java	2010-03-08 15:43:33 UTC (rev 60)
+++ trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java	2010-03-09 20:22:15 UTC (rev 61)
@@ -28,6 +28,7 @@
 import org.jboss.security.SecurityAssociation;
 import org.jboss.security.SecurityContext;
 import org.jboss.security.SecurityContextAssociation;
+import org.jboss.security.SecurityContextFactory;
 import org.jboss.security.SimplePrincipal;
 import org.jboss.security.SecurityAssociation.SubjectContext;
 import org.jboss.security.plugins.JBossSecurityContext;
@@ -170,7 +171,29 @@
       subjectContext = SecurityAssociation.peekSubjectContext();
       assertTrue("SubjectContext is not null", subjectContext != null);
    }
-
+   
+   /**
+    * SECURITY-459: {@code SecurityAssociation#getContextInfo(String)} 
+    * should return what is there on the current security context
+    * @throws Exception
+    */
+   public void testGetContextAPI() throws Exception
+   {
+      String contextKey = "SomeContextKey"; 
+      assertNull("SecurityAssociation.getContextInfo should return null", SecurityAssociation.getContextInfo(contextKey));
+      SecurityContext sc = SecurityContextFactory.createSecurityContext("test");
+      SecurityContextAssociation.setSecurityContext(sc);
+      
+      //Let us just put a principal object in the context map
+      Principal somePrincipal = new SimplePrincipal("someprincipal");
+      sc.getData().put(contextKey, somePrincipal);
+      
+      Object contextObject = SecurityAssociation.getContextInfo(contextKey);
+      
+      assertEquals("Context Object is the principal?", contextObject, somePrincipal); 
+      assertEquals("Principal name matches", "someprincipal", ((Principal)contextObject).getName());
+   }
+   
    private void checkSA(boolean threaded)
    {
       SecurityAssociation.setPrincipal(new SimplePrincipal("Anil"));




More information about the jboss-cvs-commits mailing list