Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (22 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libjava/java/security/BasicPermission.java

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    1 /* BasicPermission.java -- Implements a simple named permission.
    2    Copyright (C) 1998, 1999 Free Software Foundation, Inc.
     1/* BasicPermission.java --
     2   Copyright (C) 1998, 1999 Free Software Foundation, Inc.
    33
    44This file is part of GNU Classpath.
     
    4545 * This class implements a simple model for named permissions without an
    4646 * associated action list.  That is, either the named permission is granted
    47  * or it is not. 
    48  * <p>
    49  * It also supports trailing wildcards to allow the
    50  * easy granting of permissions in a hierarchical fashion.  (For example,
    51  * the name "org.gnu.*" might grant all permissions under the "org.gnu"
    52  * permissions hierarchy).  The only valid wildcard character is a '*'
    53  * which matches anything.  It must be the rightmost element in the
    54  * permission name and must follow a '.' or else the Permission name must
    55  * consist of only a '*'.  Any other occurrence of a '*' is not valid.
    56  * <p>
    57  * This class ignores the action list.  Subclasses can choose to implement
     47 * or it is not.
     48 *
     49 *
     50 *
     51 *
     52 *
     53 *
     54 *
     55 * occurrence of a '*' is not valid.
     56 *
     57 * This class ignores the action list.  Subclasses can choose to implement
    5858 * actions on top of this class if desired.
    5959 *
    60  * @version 0.1
    61  *
    62  * @author Aaron M. Renn ([email protected])
     60 * @author Aaron M. Renn <[email protected]>
     61 * @author Eric Blake <[email protected]>
     62 * @see Permission
     63 * @see Permissions
     64 * @see PermissionCollection
     65 * @see RuntimePermission
     66 * @see SecurityPermission
     67 * @see PropertyPermission
     68 * @see AWTPermission
     69 * @see NetPermission
     70 * @see SecurityManager
     71 * @since 1.1
     72 * @status updated to 1.4
    6373 */
    6474public abstract class BasicPermission extends java.security.Permission
    6575  implements Serializable
    66   // FIXME extends with fully qualified classname as workaround for gcj 3.0.4
     76  // FIXME extends with fully qualified classname
    6777{
    6878  /**
    69    * This method initializes a new instance of <code>BasicPermission</code>
    70    * with the specified name.  If the name contains an illegal wildcard
    71    * character, an exception is thrown.
    72    *
    73    * @param name The name of this permission.
    74    *
    75    * @exception IllegalArgumentException If the name contains an invalid wildcard character
    76    * @exception NullPointerException If the name is null
    77    */
    78   public BasicPermission(String name)
    79     throws IllegalArgumentException, NullPointerException
     79   * Compatible with JDK 1.1+.
     80   */
     81  private static final long serialVersionUID = 6279438298436773498L;
     82
     83  /**
     84   * Create a new instance with the specified permission name. If the name
     85   * is empty, or contains an illegal wildcard character, an exception is
     86   * thrown.
     87   *
     88   * @param name the name of this permission
     89   * @throws NullPointerException if name is null
     90   * @throws IllegalArgumentException if name is invalid
     91   */
     92  public BasicPermission(String name)
    8093  {
    8194    super(name);
    82 
    8395    if (name.indexOf("*") != -1)
    8496      {
    85         if (!name.endsWith(".*") && !name.equals("*"))
    86           throw new IllegalArgumentException("Bad wildcard: " + name);
    87 
    88         if (name.indexOf("*") != name.lastIndexOf("*"))
    89           throw new IllegalArgumentException("Bad wildcard: " + name);
     97        if ((! name.endsWith(".*") && ! name.equals("*"))
     98            || name.indexOf("*") != name.lastIndexOf("*"))
     99          throw new IllegalArgumentException("Bad wildcard: " + name);
    90100      }
    91   }
    92 
    93   /**
    94    * This method initializes a new instance of <code>BasicPermission</code>
    95    * with the specified name.  If the name contains an illegal wildcard
    96    * character, an exception is thrown.  The action list passed to this
    97    * form of the constructor is ignored.
    98    *
    99    * @param name The name of this permission.
    100    * @param actions The list of actions for this permission - ignored in this class.
    101    *
    102    * @exception IllegalArgumentException If the name contains an invalid wildcard character
    103    * @exception NullPointerException If the name is null
    104    */
    105   public BasicPermission(String name, String actions)
    106     throws IllegalArgumentException, NullPointerException
    107   {
    108     // ignore actions
     101    if ("".equals(name))
     102      throw new IllegalArgumentException("Empty name");
     103  }
     104
     105  /**
     106   * Create a new instance with the specified permission name. If the name
     107   * is empty, or contains an illegal wildcard character, an exception is
     108   * thrown. The actions parameter is ignored.
     109   *
     110   * @param name the name of this permission
     111   * @param actions ignored
     112   * @throws NullPointerException if name is null
     113   * @throws IllegalArgumentException if name is invalid
     114   */
     115  public BasicPermission(String name, String actions)
     116  {
    109117    this(name);
    110118  }
    111119
    112120  /**
    113    * This method tests to see if the specified permission is implied by
    114    * this permission.  This will be true if the following conditions are met:
    115    * <p>
    116    * <ul>
    117    * <li>The specified object is an instance of <code>BasicPermission</code>,
    118    * or a subclass.
    119    * <li>The name of the specified permission is identical to this permission's
    120    * name or the name of the specified permission satisfies a wildcard match
    121    * on this permission.
     121   * This method tests to see if the specified permission is implied by this
     122   * permission.  This will be true if the following conditions are met:<ul>
     123   * <li>The specified object is an instance of the same class as this
     124   * object.</li>
     125   * <li>The name of the specified permission is implied by this permission's
     126   * name based on wildcard matching. For example, "a.*" implies "a.b".</li>
    122127   * </ul>
    123128   *
    124    * @param perm The <code>Permission</code> object to test against.
    125    *
    126    * @return <code>true</code> if the specified permission is implied by this one or <code>false</code> otherwise.
     129   * @param perm the <code>Permission</code> object to test against
     130   * @return true if the specified permission is implied
    127131   */
    128132  public boolean implies(Permission perm)
    129133  {
    130     if (!(perm instanceof BasicPermission))
     134    if (!))
    131135      return false;
    132136
     
    138142
    139143    int last = name.length() - 1;
    140     if (name.charAt(last) == '*'
    141         && otherName.startsWith(name.substring(0, last)))
    142       return true;
    143 
    144     return false;
     144    return name.charAt(last) == '*'
     145      && otherName.startsWith(name.substring(0, last));
    145146  }
    146147
     
    148149   * This method tests to see if this object is equal to the specified
    149150   * <code>Object</code>.  This will be true if and only if the specified
    150    * object meets the following conditions:
    151    * <p>
    152    * <ul>
    153    * <li>It is an instance of <code>BasicPermission</code>, or a subclass.
    154    * <li>It has the same name as this permission.
     151   * object meets the following conditions:<ul>
     152   * <li>It is an instance of the same class as this.</li>
     153   * <li>It has the same name as this permission.</li>
    155154   * </ul>
    156155   *
    157    * @param obj The <code>Object</code> to test for equality against this object
    158    *
    159    * @return <code>true</code> if the specified <code>Object</code> is equal to this object or <code>false</code> otherwise.
     156   * @param obj the <code>Object</code> to test for equality
     157   * @return true if obj is semantically equal to this
    160158   */
    161159  public boolean equals(Object obj)
    162160  {
    163     if (!(obj instanceof BasicPermission))
    164       return (false);
    165 
    166     if (!getName().equals(((BasicPermission) obj).getName()))
    167       return (false);
    168 
    169     return (true);
     161    return getClass().isInstance(obj)
     162      && getName().equals(((BasicPermission) obj).getName());
    170163  }
    171164
     
    175168   * method on the <code>String</code> that is the name of this permission.
    176169   *
    177    * @return A hash value for this object
     170   * @return hash value for this object
    178171   */
    179172  public int hashCode()
    180173  {
    181     return (getName().hashCode());
    182   }
    183 
    184   /**
    185    * This method returns a list of the actions associated with this 
     174    return );
     175  }
     176
     177  /**
     178   * This method returns a list of the actions associated with this
    186179   * permission.  This method always returns the empty string ("") since
    187180   * this class ignores actions.
    188181   *
    189    * @return The action list.
     182   * @return
    190183   */
    191184  public String getActions()
    192185  {
    193     return ("");
     186    return ;
    194187  }
    195188
    196189  /**
    197190   * This method returns an instance of <code>PermissionCollection</code>
    198    * suitable for storing <code>BasicPermission</code> objects.  This returns
    199    * be a sub class of <code>PermissionCollection</code>
    200    * that allows for an efficient and consistent implementation of
    201    * the <code>implies</code> method.  The collection doesn't handle subclasses
    202    * of BasicPermission correctly; they must override this method.
    203    *
    204    * @return A new empty <code>PermissionCollection</code> object.
     191   * suitable for storing <code>BasicPermission</code> objects.  The
     192   * collection returned can only store objects of the same type as this.
     193   * Subclasses which use actions must override this method; but a class with
     194   * no actions will work fine with this.
     195   *
     196   * @return a new empty <code>PermissionCollection</code> object
    205197   */
    206198  public PermissionCollection newPermissionCollection()
    207199  {
    208     return new PermissionCollection()
    209     {
    210       Hashtable permissions = new Hashtable();
    211       boolean allAllowed = false;
    212 
    213       public void add(Permission permission)
     200    return new BasicPermissionCollection(getClass());
     201  }
     202} // class BasicPermission
     203
     204/**
     205 * Implements AllPermission.newPermissionCollection, and obeys serialization
     206 * of JDK.
     207 *
     208 * @author Eric Blake <[email protected]>
     209 */
     210final class BasicPermissionCollection extends PermissionCollection
     211{
     212  /**
     213   * Compatible with JDK 1.1+.
     214   */
     215  private static final long serialVersionUID = 739301742472979399L;
     216
     217  /**
     218   * The permissions in the collection.
     219   *
     220   * @serial a hash mapping name to permissions, all of type permClass
     221   */
     222  private final Hashtable permissions = new Hashtable();
     223
     224  /**
     225   * If "*" is in the collection.
     226   *
     227   * @serial true if a permission named "*" is in the collection
     228   */
     229  private boolean all_allowed;
     230
     231  /**
     232   * The runtime class which all entries in the table must belong to.
     233   *
     234   * @serial the limiting subclass of this collection
     235   */
     236  private final Class permClass;
     237
     238  /**
     239   * Construct a collection over the given runtime class.
     240   *
     241   * @param c the class
     242   */
     243  BasicPermissionCollection(Class c)
     244  {
     245    permClass = c;
     246  }
     247
     248  /**
     249   * Add a Permission. It must be of the same type as the permission which
     250   * created this collection.
     251   *
     252   * @param perm the permission to add
     253   * @throws IllegalArgumentException if perm is not the correct type
     254   * @throws SecurityException if the collection is read-only
     255   */
     256  public void add(Permission perm)
     257  {
     258    if (isReadOnly())
     259      throw new SecurityException("readonly");
     260    if (! permClass.isInstance(perm))
     261      throw new IllegalArgumentException("Expecting instance of " + permClass);
     262    BasicPermission bp = (BasicPermission) perm;
     263    String name = bp.getName();
     264    if (name.equals("*"))
     265      all_allowed = true;
     266    permissions.put(name, bp);
     267  }
     268
     269  /**
     270   * Returns true if this collection implies the given permission.
     271   *
     272   * @param permission the permission to check
     273   * @return true if it is implied by this
     274   */
     275  public boolean implies(Permission permission)
     276  {
     277    if (! permClass.isInstance(permission))
     278      return false;
     279    if (all_allowed)
     280      return true;
     281    BasicPermission toImply = (BasicPermission) permission;
     282    String name = toImply.getName();
     283    if (name.equals("*"))
     284      return false;
     285    int prefixLength = name.length();
     286    if (name.endsWith("*"))
     287      prefixLength -= 2;
     288
     289    while (true)
    214290      {
    215         if (isReadOnly())
    216           throw new IllegalStateException("readonly");
    217 
    218         BasicPermission bp = (BasicPermission) permission;
    219         String name = bp.getName();
    220         if (name.equals("*"))
    221           allAllowed = true;
    222         permissions.put(name, bp);
     291        if (permissions.get(name) != null)
     292          return true;
     293        prefixLength = name.lastIndexOf('.', prefixLength);
     294        if (prefixLength < 0)
     295          return false;
     296        name = name.substring(0, prefixLength + 1) + '*';
    223297      }
    224 
    225       public boolean implies(Permission permission)
    226       {
    227         if (!(permission instanceof BasicPermission))
    228           return false;
    229 
    230         if (allAllowed)
    231           return true;
    232 
    233         BasicPermission toImply = (BasicPermission) permission;
    234         String name = toImply.getName();
    235         if (name.equals("*"))
    236           return false;
    237 
    238         int prefixLength = name.length();
    239         if (name.endsWith("*"))
    240           prefixLength -= 2;
    241 
    242         while (true)
    243           {
    244             if (permissions.get(name) != null)
    245               return true;
    246 
    247             prefixLength = name.lastIndexOf('.', prefixLength);
    248             if (prefixLength < 0)
    249               return false;
    250             name = name.substring(0, prefixLength + 1) + '*';
    251           }
    252       }
    253 
    254       public Enumeration elements()
    255       {
    256         return permissions.elements();
    257       }
    258     };
    259   }
    260 }
     298  }
     299
     300  /**
     301   * Enumerate over the collection.
     302   *
     303   * @return an enumeration of the collection contents
     304   */
     305  public Enumeration elements()
     306  {
     307    return permissions.elements();
     308  }
     309} // class BasicPermissionCollection
Note: See TracChangeset for help on using the changeset viewer.