You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2009/07/10 09:17:36 UTC
svn commit: r792821 - in /geronimo/specs/trunk/geronimo-jacc_1.1_spec/src:
main/java/javax/security/jacc/EJBMethodPermission.java
test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java
Author: djencks
Date: Fri Jul 10 07:17:36 2009
New Revision: 792821
URL: http://svn.apache.org/viewvc?rev=792821&view=rev
Log:
GERONIMO-4735 serialize EJBMethodPermissionCollection contents only once
Modified:
geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java
geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java
Modified: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java?rev=792821&r1=792820&r2=792821&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java (original)
+++ geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/main/java/javax/security/jacc/EJBMethodPermission.java Fri Jul 10 07:17:36 2009
@@ -38,12 +38,15 @@
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Collections;
+import java.util.HashSet;
/**
* @version $Rev$ $Date$
*/
public final class EJBMethodPermission extends Permission implements Serializable {
+ private static final long serialVersionUID = 4513173161293901832L;
+
private final static String NEW_METHOD_INTERFACES = "org.apache.security.jacc.EJBMethodPermission.methodInterfaces";
private static String[] methodInterfaces;
@@ -321,9 +324,12 @@
private static final class EJBMethodPermissionCollection extends PermissionCollection {
- private LinkedList collection = new LinkedList();
- private HashMap permissions = new HashMap();
+ private static final long serialVersionUID = -3557818912959683053L;
+
private static final String WILDCARD = "$WILDCARD";
+ private static final HashMap<String, HashMap<String, HashSet<String>>> ALL_METHODS = new HashMap<String, HashMap<String, HashSet<String>>>();
+ private LinkedList<Permission> collection = new LinkedList<Permission>();
+ private transient HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>> permissions = new HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>>();
/**
* Adds a permission object to the current collection of permission objects.
@@ -340,50 +346,58 @@
if (!(permission instanceof EJBMethodPermission)) throw new IllegalArgumentException("Wrong permission type");
- if (collection.contains(permission)) return;
- else collection.add(permission);
-
EJBMethodPermission p = (EJBMethodPermission)permission;
- EJBMethodPermission.MethodSpec spec = p.methodSpec;
- Object test = permissions.get(p.getName());
+ if (collection.contains(p)) return;
+ else collection.add(p);
+
+ addEJBMethodPermission(p);
+
+ }
- if (test instanceof Boolean) return;
+ private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ permissions = new HashMap<String, HashMap<String, HashMap<String, HashSet<String>>>>();
+ for (Permission p: collection) {
+ addEJBMethodPermission((EJBMethodPermission)p);
+ }
+ }
+
+ private void addEJBMethodPermission(EJBMethodPermission p) {
+ MethodSpec spec = p.methodSpec;
+ HashMap<String, HashMap<String, HashSet<String>>> methods = permissions.get(p.getName());
+
+ if (methods == ALL_METHODS) return;
if (spec.methodName == null && spec.methodInterface == null && spec.methodParams == null) {
- permissions.put(p.getName(), new Boolean(true));
+ permissions.put(p.getName(), ALL_METHODS);
return;
}
- HashMap methods = (HashMap)test;
if (methods == null) {
- methods = new HashMap();
+ methods = new HashMap<String, HashMap<String, HashSet<String>>>();
permissions.put(p.getName(), methods);
}
- Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
- HashMap interfaces = (HashMap)methods.get(methodKey);
+ String methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
+ HashMap<String, HashSet<String>> interfaces = methods.get(methodKey);
if (interfaces == null) {
- interfaces = new HashMap();
+ interfaces = new HashMap<String, HashSet<String>>();
methods.put(methodKey, interfaces);
}
- Object interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
- HashMap parameters = (HashMap)interfaces.get(interfaceKey);
+ String interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
+ HashSet<String> parameters = interfaces.get(interfaceKey);
if (parameters == null) {
- parameters = new HashMap();
+ parameters = new HashSet<String>();
interfaces.put(interfaceKey, parameters);
}
-
// an empty string for a parameter spec indicates a method w/ no parameters
- Object parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
- Object parameter = parameters.get(parametersKey);
- if (parameter == null) {
- parameter = new Boolean(true);
- parameters.put(parametersKey, parameter);
+ String parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
+ if (!parameters.contains(parametersKey)) {
+ parameters.add(parametersKey);
}
-
}
/**
@@ -402,19 +416,17 @@
EJBMethodPermission p = (EJBMethodPermission)permission;
EJBMethodPermission.MethodSpec spec = p.methodSpec;
- Object test = permissions.get(p.getName());
-
- if (test == null) return false;
- if (test instanceof Boolean) return true;
+ HashMap<String, HashMap<String, HashSet<String>>> methods = permissions.get(p.getName());
- HashMap methods = (HashMap)test;
+ if (methods == null) return false;
+ if (methods == ALL_METHODS) return true;
- Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
- HashMap interfaces = (HashMap)methods.get(methodKey);
+ String methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
+ HashMap<String, HashSet<String>> interfaces = methods.get(methodKey);
if (methodImplies(interfaces, spec)) return true;
if (methodKey != WILDCARD) {
- return methodImplies((HashMap)methods.get(WILDCARD), spec);
+ return methodImplies(methods.get(WILDCARD), spec);
}
return false;
@@ -422,16 +434,16 @@
- protected boolean methodImplies(HashMap interfaces, EJBMethodPermission.MethodSpec spec) {
+ protected boolean methodImplies(HashMap<String, HashSet<String>> interfaces, EJBMethodPermission.MethodSpec spec) {
if (interfaces == null) return false;
- Object interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
- HashMap parameters = (HashMap)interfaces.get(interfaceKey);
+ String interfaceKey = (spec.methodInterface == null || spec.methodInterface.length() == 0? WILDCARD:spec.methodInterface);
+ HashSet<String> parameters = interfaces.get(interfaceKey);
if (interfaceImplies(parameters, spec)) return true;
if (interfaceKey != WILDCARD) {
- return interfaceImplies((HashMap)interfaces.get(WILDCARD), spec);
+ return interfaceImplies(interfaces.get(WILDCARD), spec);
}
return false;
@@ -439,18 +451,17 @@
- protected boolean interfaceImplies(HashMap parameters, EJBMethodPermission.MethodSpec spec) {
+ protected boolean interfaceImplies(HashSet<String> parameters, EJBMethodPermission.MethodSpec spec) {
if (parameters == null) return false;
// An empty string for a parameter spec indicates a method w/ no parameters
// so we won't convert an empty string to a wildcard.
- Object parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
- Object parameter = parameters.get(parametersKey);
+ String parametersKey = (spec.methodParams == null? WILDCARD:spec.methodParams);
- if (parameter != null) return true;
+ if (parameters.contains(parametersKey)) return true;
if (parametersKey != WILDCARD) {
- return parameters.containsKey(WILDCARD);
+ return parameters.contains(WILDCARD);
}
return false;
@@ -463,7 +474,7 @@
*
* @return an enumeration of all the Permissions.
*/
- public Enumeration elements() {
+ public Enumeration<Permission> elements() {
return Collections.enumeration(collection);
}
}
Modified: geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java?rev=792821&r1=792820&r2=792821&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java (original)
+++ geronimo/specs/trunk/geronimo-jacc_1.1_spec/src/test/java/javax/security/jacc/EJBMethodPermissionCollectionTest.java Fri Jul 10 07:17:36 2009
@@ -28,6 +28,12 @@
import junit.framework.TestCase;
import java.security.PermissionCollection;
+import java.security.Permission;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.util.Enumeration;
/**
@@ -241,4 +247,23 @@
assertFalse(collection.implies(new EJBMethodPermission("GoodbyeWorld", "hello,Local,")));
}
+
+ public void testSerialization() throws Exception {
+ EJBMethodPermission p = new EJBMethodPermission("HelloWorld", "");
+ PermissionCollection collection = p.newPermissionCollection();
+ collection.add(new EJBMethodPermission("HelloWorld", ""));
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(collection);
+ oos.flush();
+ byte[] bytes = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ PermissionCollection collection2 = (PermissionCollection) ois.readObject();
+ Enumeration <Permission> ps = collection2.elements();
+ Permission p2 = ps.nextElement();
+ assertEquals(p2, p);
+ assertFalse(ps.hasMoreElements());
+ assertTrue(collection2.implies(p));
+ }
}