[jboss-cvs] Picketbox SVN: r64 - 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
Mon Mar 22 13:10:25 EDT 2010


Author: anil.saldhana at jboss.com
Date: 2010-03-22 13:10:24 -0400 (Mon, 22 Mar 2010)
New Revision: 64

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-480: maintain backward compat

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-12 19:47:13 UTC (rev 63)
+++ trunk/security-jboss-sx/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java	2010-03-22 17:10:24 UTC (rev 64)
@@ -481,6 +481,22 @@
             sctx.getUtil().createSubjectInfo(null, null, subject);
       }
    }
+   
+   /**
+    * Introduced for backward compatibility with older versions of security
+    * @deprecated
+    * @see {@code SecurityAssociation#getContextInfo(String)}
+    * @param key
+    * @return
+    * @throws IllegalArgumentException if the passed key is not of type String
+    */
+   public static Object getContextInfo(Object key)
+   {
+      if(key instanceof String ==  false)
+         throw new IllegalArgumentException("Key should be of type String");
+      
+      return getContextInfo((String)key);
+   }
 
    /**
     * Get the current thread context info. If a security manager is present,
@@ -508,6 +524,23 @@
       HashMap<String,Object> contextInfo = (HashMap<String,Object>) threadContextMap.get();
       return contextInfo != null ? contextInfo.get(key) : null;
    }
+   
+   /**
+    * Maintain backwards compatibility
+    * @deprecated
+    * @see {@code SecurityAssociation#setContextInfo(String, Object)}
+    * @param key
+    * @param value
+    * @return
+    * @throws IllegalArgumentException if the passed key is not of type String
+    */
+   public static Object setContextInfo(Object key, Object value)
+   {
+      if(key instanceof String == false)
+         throw new IllegalArgumentException("key should be of type String");
+      String keyStr = (String) key;
+      return setContextInfo(keyStr, value);
+   }
 
    /**
     * Set the current thread context info. If a security manager is present,
@@ -525,6 +558,10 @@
       if (sm != null)
          sm.checkPermission(setContextInfo);
 
+      SecurityContext sc = SecurityAssociationActions.getSecurityContext();
+      if(sc != null)
+         return sc.getData().put(key, value);
+      
       HashMap<String,Object> contextInfo = (HashMap<String,Object>) threadContextMap.get();
       return contextInfo.put(key, value);
    }

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-12 19:47:13 UTC (rev 63)
+++ trunk/security-jboss-sx/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java	2010-03-22 17:10:24 UTC (rev 64)
@@ -33,9 +33,7 @@
 import org.jboss.security.SecurityAssociation.SubjectContext;
 import org.jboss.security.plugins.JBossSecurityContext;
 import org.jboss.test.AbstractJBossSXTest;
-
-//$Id$
-
+ 
 /**
  *  Legacy SecurityAssociation deeper integration test case
  *  @author Anil.Saldhana at redhat.com
@@ -115,6 +113,29 @@
       assertEquals("CallerPrincipal=anil",p,SecurityAssociation.getCallerPrincipal()); 
    }
    
+   /**
+    * SECURITY-480 :  maintain backwards compatibility 
+    */
+   @SuppressWarnings("deprecation")
+   public void testGetContextInfo()
+   {
+      Object key = new String("testKey");
+      String val = new String("value");
+      
+      SecurityAssociation.setContextInfo(key, val);
+      
+      String returnedValue = (String) SecurityAssociation.getContextInfo(key);
+      assertEquals("Value should be the same", val, returnedValue);
+      
+      String keyStr = "key2";
+      String VAL = "value2";
+      
+      SecurityAssociation.setContextInfo(keyStr, VAL);
+      
+      returnedValue = (String) SecurityAssociation.getContextInfo(keyStr);
+      assertEquals("Value should be the same", VAL, returnedValue);
+   }
+   
    public void testSetPrincipal()
    {
       assertNull("Principal is null", SecurityAssociation.getPrincipal());




More information about the jboss-cvs-commits mailing list