[jboss-cvs] JBossAS SVN: r103592 - in projects/security/security-jboss-sx/branches/Branch_2_0/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 Apr 6 15:57:21 EDT 2010
Author: anil.saldhana at jboss.com
Date: 2010-04-06 15:57:20 -0400 (Tue, 06 Apr 2010)
New Revision: 103592
Modified:
projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java
projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
Log:
SECURITY-481: add the two methods for backwards compat
Modified: projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java
===================================================================
--- projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java 2010-04-06 19:32:19 UTC (rev 103591)
+++ projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/SecurityAssociation.java 2010-04-06 19:57:20 UTC (rev 103592)
@@ -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,
@@ -509,9 +525,21 @@
return contextInfo != null ? contextInfo.get(key) : null;
}
- public static Object getContextInfo(Object key)
+ /**
+ * 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)
{
- return getContextInfo((String) key);
+ if(key instanceof String == false)
+ throw new IllegalArgumentException("key should be of type String");
+ String keyStr = (String) key;
+ return setContextInfo(keyStr, value);
}
/**
@@ -530,14 +558,13 @@
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);
}
-
- public static Object setContextInfo(Object key, Object value)
- {
- return setContextInfo((String) key, value);
- }
/**
* Push the current authenticated context. This sets the authenticated subject
@@ -881,7 +908,7 @@
local = new ArrayListInheritableLocal();
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "unused"})
int size()
{
ArrayList stack = (ArrayList) local.get();
@@ -895,7 +922,7 @@
stack.add(runAs);
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "unused"})
RunAsIdentity pop()
{
ArrayList stack = (ArrayList) local.get();
@@ -911,7 +938,7 @@
* with the value at depth.
* @return The run-as identity if one exists, null otherwise.
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "unused"})
RunAsIdentity peek(int depth)
{
ArrayList stack = (ArrayList) local.get();
@@ -1018,6 +1045,7 @@
local = new ArrayListInheritableLocal();
}
+ @SuppressWarnings("unused")
int size()
{
ArrayList stack = (ArrayList) local.get();
@@ -1132,6 +1160,7 @@
* @param parentValue - the parent HashMap
* @return a copy of the parent thread map
*/
+ @SuppressWarnings("unused")
protected HashMap<String,Object> childValue(Object parentValue)
{
HashMap<String,Object> map = (HashMap<String,Object>) parentValue;
Modified: projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java
===================================================================
--- projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java 2010-04-06 19:32:19 UTC (rev 103591)
+++ projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/test/java/org/jboss/test/securityassociation/LegacySecurityAssociationTestCase.java 2010-04-06 19:57:20 UTC (rev 103592)
@@ -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