Home | History | Annotate | Download | only in security
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package java.security;
     19 
     20 import java.util.Enumeration;
     21 import java.util.Hashtable;
     22 
     23 /**
     24  * A default {@code PermissionCollection} implementation that uses a hashtable.
     25  * Each hashtable entry stores a Permission object as both the key and the
     26  * value.
     27  * <p>
     28  * This {@code PermissionCollection} is intended for storing &quot;neutral&quot;
     29  * permissions which do not require special collection.
     30  */
     31 
     32 final class PermissionsHash extends PermissionCollection {
     33 
     34     private static final long serialVersionUID = -8491988220802933440L;
     35 
     36     private final Hashtable perms = new Hashtable();
     37 
     38     /**
     39      * Adds the argument to the collection.
     40      *
     41      * @param permission
     42      *            the permission to add to the collection.
     43      */
     44     public void add(Permission permission) {
     45         perms.put(permission, permission);
     46     }
     47 
     48     /**
     49      * Returns an enumeration of the permissions in the receiver.
     50      *
     51      * @return Enumeration the permissions in the receiver.
     52      */
     53     public Enumeration elements() {
     54         return perms.elements();
     55     }
     56 
     57     /**
     58      * Indicates whether the argument permission is implied by the permissions
     59      * contained in the receiver.
     60      *
     61      * @return boolean <code>true</code> if the argument permission is implied
     62      *         by the permissions in the receiver, and <code>false</code> if
     63      *         it is not.
     64      * @param permission
     65      *            java.security.Permission the permission to check
     66      */
     67     public boolean implies(Permission permission) {
     68         for (Enumeration elements = elements(); elements.hasMoreElements();) {
     69             if (((Permission)elements.nextElement()).implies(permission)) {
     70                 return true;
     71             }
     72         }
     73         return false;
     74     }
     75 }
     76