geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: incubator-geronimo/specs/j2ee-jacc/src/java/javax/security/jacc EJBMethodPermissionCollection.java
Date Sun, 25 Jul 2004 00:57:00 GMT
adc         2004/07/24 17:57:00

  Modified:    specs/j2ee-jacc/src/java/javax/security/jacc
                        EJBMethodPermissionCollection.java
  Log:
  Changed WILDCARD to String.
  
  Revision  Changes    Path
  1.4       +168 -148  incubator-geronimo/specs/j2ee-jacc/src/java/javax/security/jacc/EJBMethodPermissionCollection.java
  
  Index: EJBMethodPermissionCollection.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/j2ee-jacc/src/java/javax/security/jacc/EJBMethodPermissionCollection.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EJBMethodPermissionCollection.java	10 Mar 2004 09:59:53 -0000	1.3
  +++ EJBMethodPermissionCollection.java	25 Jul 2004 00:57:00 -0000	1.4
  @@ -21,151 +21,171 @@
   // DO NOT add / change / or delete method signatures!
   //
   
  -package javax.security.jacc;
  -
  -import java.security.PermissionCollection;
  -import java.security.Permission;
  -import java.util.LinkedList;
  -import java.util.HashMap;
  -import java.util.Enumeration;
  -import java.util.Collections;
  -
  -
  -/**
  - *
  - * @version $Revision$ $Date$
  - */
  -public final class EJBMethodPermissionCollection extends PermissionCollection {
  -
  -    private LinkedList collection = new LinkedList();
  -    private HashMap permissions = new HashMap();
  -    private static final Object WILDCARD = new Object();
  -
  -    /**
  -     * Adds a permission object to the current collection of permission objects.
  -     *
  -     * @param permission the Permission object to add.
  -     *
  -     * @exception SecurityException -  if this PermissionCollection object
  -     *                                 has been marked readonly
  -     */
  -    public void add(Permission permission) {
  -        if (isReadOnly()) throw new IllegalArgumentException("Read only collection");
  -
  -        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 (test instanceof Boolean) return;
  -
  -        if (spec.methodName == null && spec.methodInterface == null &&
spec.methodParams == null) {
  -            permissions.put(p.getName(), new Boolean(true));
  -            return;
  -        }
  -
  -        HashMap methods = (HashMap)test;
  -        if (methods == null) {
  -            methods = new HashMap();
  -            permissions.put(p.getName(), methods);
  -        }
  -
  -        Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
  -        HashMap interfaces = (HashMap)methods.get(methodKey);
  -        if (interfaces == null) {
  -            interfaces = new HashMap();
  -            methods.put(methodKey, interfaces);
  -        }
  -
  -        Object interfaceKey = (spec.methodInterface == null || spec.methodInterface.length()
== 0? WILDCARD:spec.methodInterface);
  -        HashMap parameters = (HashMap)interfaces.get(interfaceKey);
  -        if (parameters == null) {
  -            parameters = new HashMap();
  -            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);
  -        }
  -    }
  -
  -    /**
  -     * Checks to see if the specified permission is implied by
  -     * the collection of Permission objects held in this PermissionCollection.
  -     *
  -     * @param permission the Permission object to compare.
  -     *
  -     * @return true if "permission" is implied by the  permissions in
  -     * the collection, false if not.
  -     */
  -    public boolean implies(Permission permission) {
  -        if (!(permission instanceof EJBMethodPermission)) return false;
  -
  -        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 methods = (HashMap)test;
  -
  -        Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
  -        HashMap interfaces = (HashMap)methods.get(methodKey);
  -
  -        if (methodImplies(interfaces, spec)) return true;
  -        if (methodKey != WILDCARD) {
  -            return methodImplies((HashMap)methods.get(WILDCARD), spec);
  -        }
  -
  -        return false;
  -    }
  -
  -    protected boolean methodImplies(HashMap 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);
  -
  -        if (interfaceImplies(parameters, spec)) return true;
  -        if (interfaceKey != WILDCARD) {
  -            return interfaceImplies((HashMap)interfaces.get(WILDCARD), spec);
  -        }
  -
  -        return false;
  -    }
  -
  -    protected boolean interfaceImplies(HashMap 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);
  -
  -        if (parameter != null) return true;
  -        if (parametersKey != WILDCARD) {
  -            return parameters.containsKey(WILDCARD);
  -        }
  -
  -        return false;
  -    }
  -
  -    /**
  -     * Returns an enumeration of all the Permission objects in the collection.
  -     *
  -     * @return an enumeration of all the Permissions.
  -     */
  -    public Enumeration elements() {
  -        return Collections.enumeration(collection);
  -    }
  -}
  +package javax.security.jacc;
  +
  +import java.security.PermissionCollection;
  +
  +import java.security.Permission;
  +
  +import java.util.LinkedList;
  +
  +import java.util.HashMap;
  +
  +import java.util.Enumeration;
  +
  +import java.util.Collections;
  +
  +
  +/**
  + *
  + * @version $Revision$ $Date$
  + */
  +public final class EJBMethodPermissionCollection extends PermissionCollection {
  +
  +    private LinkedList collection = new LinkedList();
  +    private HashMap permissions = new HashMap();
  +    private static final String WILDCARD = new String();
  +
  +    /**
  +     * Adds a permission object to the current collection of permission objects.
  +     *
  +     * @param permission the Permission object to add.
  +     *
  +     * @exception SecurityException -  if this PermissionCollection object
  +     *                                 has been marked readonly
  +     */
  +
  +    public void add(Permission permission) {
  +
  +        if (isReadOnly()) throw new IllegalArgumentException("Read only collection");
  +
  +        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 (test instanceof Boolean) return;
  +
  +        if (spec.methodName == null && spec.methodInterface == null &&
spec.methodParams == null) {
  +            permissions.put(p.getName(), new Boolean(true));
  +            return;
  +        }
  +
  +        HashMap methods = (HashMap)test;
  +        if (methods == null) {
  +            methods = new HashMap();
  +            permissions.put(p.getName(), methods);
  +        }
  +
  +        Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
  +        HashMap interfaces = (HashMap)methods.get(methodKey);
  +        if (interfaces == null) {
  +            interfaces = new HashMap();
  +            methods.put(methodKey, interfaces);
  +        }
  +
  +        Object interfaceKey = (spec.methodInterface == null || spec.methodInterface.length()
== 0? WILDCARD:spec.methodInterface);
  +        HashMap parameters = (HashMap)interfaces.get(interfaceKey);
  +        if (parameters == null) {
  +            parameters = new HashMap();
  +            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);
  +        }
  +
  +    }
  +
  +    /**
  +     * Checks to see if the specified permission is implied by
  +     * the collection of Permission objects held in this PermissionCollection.
  +     *
  +     * @param permission the Permission object to compare.
  +     *
  +     * @return true if "permission" is implied by the  permissions in
  +     * the collection, false if not.
  +     */
  +    public boolean implies(Permission permission) {
  +
  +        if (!(permission instanceof EJBMethodPermission)) return false;
  +
  +        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 methods = (HashMap)test;
  +
  +        Object methodKey = (spec.methodName == null || spec.methodName.length() == 0? WILDCARD:spec.methodName);
  +        HashMap interfaces = (HashMap)methods.get(methodKey);
  +
  +        if (methodImplies(interfaces, spec)) return true;
  +        if (methodKey != WILDCARD) {
  +            return methodImplies((HashMap)methods.get(WILDCARD), spec);
  +        }
  +
  +        return false;
  +    }
  +
  +
  +
  +    protected boolean methodImplies(HashMap 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);
  +
  +        if (interfaceImplies(parameters, spec)) return true;
  +        if (interfaceKey != WILDCARD) {
  +            return interfaceImplies((HashMap)interfaces.get(WILDCARD), spec);
  +        }
  +
  +        return false;
  +    }
  +
  +
  +
  +    protected boolean interfaceImplies(HashMap 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);
  +
  +        if (parameter != null) return true;
  +        if (parametersKey != WILDCARD) {
  +            return parameters.containsKey(WILDCARD);
  +        }
  +
  +        return false;
  +    }
  +
  +
  +
  +    /**
  +     * Returns an enumeration of all the Permission objects in the collection.
  +     *
  +     * @return an enumeration of all the Permissions.
  +     */
  +    public Enumeration elements() {
  +        return Collections.enumeration(collection);
  +    }
  +}
  +
  
  
  

Mime
View raw message