< prev index next >

src/java.rmi/share/classes/com/sun/rmi/rmid/ExecOptionPermission.java

Print this page




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.rmi.rmid;
  27 
  28 import java.security.*;
  29 import java.io.*;
  30 import java.util.*;
  31 
  32 /**
  33  * The ExecOptionPermission class represents permission for rmid to use
  34  * a specific command-line option when launching an activation group.
  35  * <P>
  36  *
  37  * @author Ann Wollrath
  38  *
  39  * @serial exclude
  40  */
  41 public final class ExecOptionPermission extends Permission
  42 {
  43     /**
  44      * does this permission have a wildcard at the end?
  45      */
  46     private transient boolean wildcard;
  47 
  48     /**
  49      * the name without the wildcard on the end
  50      */
  51     private transient String name;
  52 
  53     /**
  54      * UID for serialization
  55      */
  56     private static final long serialVersionUID = 5842294756823092756L;
  57 
  58     public ExecOptionPermission(String name) {
  59         super(name);
  60         init(name);
  61     }
  62 
  63     public ExecOptionPermission(String name, String actions) {
  64         this(name);
  65     }
  66 
  67     /**
  68      * Checks if the specified permission is "implied" by
  69      * this object.
  70      * <P>
  71      * More specifically, this method returns true if:<p>
  72      * <ul>
  73      * <li> <i>p</i>'s class is the same as this object's class, and<p>
  74      * <li> <i>p</i>'s name equals or (in the case of wildcards)
  75      *      is implied by this object's
  76      *      name. For example, "a.b.*" implies "a.b.c", and
  77      *      "a.b=*" implies "a.b=c"
  78      * </ul>
  79      *
  80      * @param p the permission to check against.
  81      *
  82      * @return true if the passed permission is equal to or
  83      * implied by this permission, false otherwise.
  84      */
  85     public boolean implies(Permission p) {
  86         if (!(p instanceof ExecOptionPermission))
  87             return false;
  88 
  89         ExecOptionPermission that = (ExecOptionPermission) p;
  90 
  91         if (this.wildcard) {
  92             if (that.wildcard) {
  93                 // one wildcard can imply another
  94                 return that.name.startsWith(name);
  95             } else {
  96                 // make sure p.name is longer so a.b.* doesn't imply a.b
  97                 return (that.name.length() > this.name.length()) &&
  98                     that.name.startsWith(this.name);
  99             }
 100         } else {
 101             if (that.wildcard) {
 102                 // a non-wildcard can't imply a wildcard
 103                 return false;
 104             } else {
 105                 return this.name.equals(that.name);
 106             }
 107         }
 108     }
 109 
 110     /**
 111      * Checks two ExecOptionPermission objects for equality.
 112      * Checks that <i>obj</i>'s class is the same as this object's class
 113      * and has the same name as this object.
 114      * <P>
 115      * @param obj the object we are testing for equality with this object.
 116      * @return true if <i>obj</i> is an ExecOptionPermission, and has the same
 117      * name as this ExecOptionPermission object, false otherwise.
 118      */
 119     public boolean equals(Object obj) {
 120         if (obj == this)
 121             return true;
 122 
 123         if ((obj == null) || (obj.getClass() != getClass()))
 124             return false;
 125 
 126         ExecOptionPermission that = (ExecOptionPermission) obj;
 127 
 128         return this.getName().equals(that.getName());
 129     }
 130 
 131 
 132     /**
 133      * Returns the hash code value for this object.
 134      * The hash code used is the hash code of the name, that is,


 137      *
 138      * @return a hash code value for this object.
 139      */
 140     public int hashCode() {
 141         return this.getName().hashCode();
 142     }
 143 
 144     /**
 145      * Returns the canonical string representation of the actions.
 146      *
 147      * @return the canonical string representation of the actions.
 148      */
 149     public String getActions() {
 150         return "";
 151     }
 152 
 153     /**
 154      * Returns a new PermissionCollection object for storing
 155      * ExecOptionPermission objects.
 156      * <p>
 157      * A ExecOptionPermissionCollection stores a collection of
 158      * ExecOptionPermission permissions.
 159      *
 160      * <p>ExecOptionPermission objects must be stored in a manner that allows
 161      * them to be inserted in any order, but that also enables the
 162      * PermissionCollection <code>implies</code> method
 163      * to be implemented in an efficient (and consistent) manner.
 164      *
 165      * @return a new PermissionCollection object suitable for
 166      * storing ExecOptionPermissions.
 167      */
 168     public PermissionCollection newPermissionCollection() {
 169         return new ExecOptionPermissionCollection();
 170     }
 171 
 172     /**
 173      * readObject is called to restore the state of the ExecOptionPermission
 174      * from a stream.
 175      */
 176     private synchronized void readObject(java.io.ObjectInputStream s)
 177          throws IOException, ClassNotFoundException




  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.rmi.rmid;
  27 
  28 import java.security.*;
  29 import java.io.*;
  30 import java.util.*;
  31 
  32 /**
  33  * The ExecOptionPermission class represents permission for rmid to use
  34  * a specific command-line option when launching an activation group.

  35  *
  36  * @author Ann Wollrath
  37  *
  38  * @serial exclude
  39  */
  40 public final class ExecOptionPermission extends Permission
  41 {
  42     /**
  43      * does this permission have a wildcard at the end?
  44      */
  45     private transient boolean wildcard;
  46 
  47     /**
  48      * the name without the wildcard on the end
  49      */
  50     private transient String name;
  51 
  52     /**
  53      * UID for serialization
  54      */
  55     private static final long serialVersionUID = 5842294756823092756L;
  56 
  57     public ExecOptionPermission(String name) {
  58         super(name);
  59         init(name);
  60     }
  61 
  62     public ExecOptionPermission(String name, String actions) {
  63         this(name);
  64     }
  65 
  66     /**
  67      * Checks if the specified permission is "implied" by
  68      * this object.
  69      * <P>
  70      * More specifically, this method returns true if:
  71      * <ul>
  72      * <li> <i>p</i>'s class is the same as this object's class, and
  73      * <li> <i>p</i>'s name equals or (in the case of wildcards)
  74      *      is implied by this object's
  75      *      name. For example, "a.b.*" implies "a.b.c", and
  76      *      "a.b=*" implies "a.b=c"
  77      * </ul>
  78      *
  79      * @param p the permission to check against.
  80      *
  81      * @return true if the passed permission is equal to or
  82      * implied by this permission, false otherwise.
  83      */
  84     public boolean implies(Permission p) {
  85         if (!(p instanceof ExecOptionPermission))
  86             return false;
  87 
  88         ExecOptionPermission that = (ExecOptionPermission) p;
  89 
  90         if (this.wildcard) {
  91             if (that.wildcard) {
  92                 // one wildcard can imply another
  93                 return that.name.startsWith(name);
  94             } else {
  95                 // make sure p.name is longer so a.b.* doesn't imply a.b
  96                 return (that.name.length() > this.name.length()) &&
  97                     that.name.startsWith(this.name);
  98             }
  99         } else {
 100             if (that.wildcard) {
 101                 // a non-wildcard can't imply a wildcard
 102                 return false;
 103             } else {
 104                 return this.name.equals(that.name);
 105             }
 106         }
 107     }
 108 
 109     /**
 110      * Checks two ExecOptionPermission objects for equality.
 111      * Checks that <i>obj</i>'s class is the same as this object's class
 112      * and has the same name as this object.
 113      *
 114      * @param obj the object we are testing for equality with this object.
 115      * @return true if <i>obj</i> is an ExecOptionPermission, and has the same
 116      * name as this ExecOptionPermission object, false otherwise.
 117      */
 118     public boolean equals(Object obj) {
 119         if (obj == this)
 120             return true;
 121 
 122         if ((obj == null) || (obj.getClass() != getClass()))
 123             return false;
 124 
 125         ExecOptionPermission that = (ExecOptionPermission) obj;
 126 
 127         return this.getName().equals(that.getName());
 128     }
 129 
 130 
 131     /**
 132      * Returns the hash code value for this object.
 133      * The hash code used is the hash code of the name, that is,


 136      *
 137      * @return a hash code value for this object.
 138      */
 139     public int hashCode() {
 140         return this.getName().hashCode();
 141     }
 142 
 143     /**
 144      * Returns the canonical string representation of the actions.
 145      *
 146      * @return the canonical string representation of the actions.
 147      */
 148     public String getActions() {
 149         return "";
 150     }
 151 
 152     /**
 153      * Returns a new PermissionCollection object for storing
 154      * ExecOptionPermission objects.
 155      * <p>
 156      * An ExecOptionPermissionCollection stores a collection of
 157      * ExecOptionPermission permissions.
 158      *
 159      * <p>ExecOptionPermission objects must be stored in a manner that allows
 160      * them to be inserted in any order, but that also enables the
 161      * PermissionCollection <code>implies</code> method
 162      * to be implemented in an efficient (and consistent) manner.
 163      *
 164      * @return a new PermissionCollection object suitable for
 165      * storing ExecOptionPermissions.
 166      */
 167     public PermissionCollection newPermissionCollection() {
 168         return new ExecOptionPermissionCollection();
 169     }
 170 
 171     /**
 172      * readObject is called to restore the state of the ExecOptionPermission
 173      * from a stream.
 174      */
 175     private synchronized void readObject(java.io.ObjectInputStream s)
 176          throws IOException, ClassNotFoundException


< prev index next >