< prev index next >

src/java.base/share/classes/java/security/Security.java

Print this page




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 java.security;
  27 
  28 import java.util.*;
  29 import java.util.concurrent.ConcurrentHashMap;
  30 import java.io.*;
  31 import java.net.URL;
  32 


  33 import jdk.internal.misc.SharedSecrets;
  34 import jdk.internal.util.StaticProperty;
  35 import sun.security.util.Debug;
  36 import sun.security.util.PropertyExpander;
  37 
  38 import sun.security.jca.*;
  39 
  40 /**
  41  * <p>This class centralizes all security properties and common security
  42  * methods. One of its primary uses is to manage providers.
  43  *
  44  * <p>The default values of security properties are read from an
  45  * implementation-specific location, which is typically the properties file
  46  * {@code conf/security/java.security} in the Java installation directory.
  47  *
  48  * @author Benjamin Renaud
  49  * @since 1.1
  50  */
  51 
  52 public final class Security {


 778      * permission to see if it's ok to set the specified
 779      * security property value.
 780      *
 781      * @param key the name of the property to be set.
 782      *
 783      * @param datum the value of the property to be set.
 784      *
 785      * @throws  SecurityException
 786      *          if a security manager exists and its {@link
 787      *          java.lang.SecurityManager#checkPermission} method
 788      *          denies access to set the specified security property value
 789      * @throws  NullPointerException if key or datum is null
 790      *
 791      * @see #getProperty
 792      * @see java.security.SecurityPermission
 793      */
 794     public static void setProperty(String key, String datum) {
 795         check("setProperty."+key);
 796         props.put(key, datum);
 797         invalidateSMCache(key);  /* See below. */





 798     }
 799 
 800     /*
 801      * Implementation detail:  If the property we just set in
 802      * setProperty() was either "package.access" or
 803      * "package.definition", we need to signal to the SecurityManager
 804      * class that the value has just changed, and that it should
 805      * invalidate it's local cache values.
 806      */
 807     private static void invalidateSMCache(String key) {
 808 
 809         final boolean pa = key.equals("package.access");
 810         final boolean pd = key.equals("package.definition");
 811 
 812         if (pa || pd) {
 813             SharedSecrets.getJavaLangAccess().invalidatePackageAccessCache();
 814         }
 815     }
 816 
 817     private static void check(String directive) {




  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  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 java.security;
  27 
  28 import java.util.*;
  29 import java.util.concurrent.ConcurrentHashMap;
  30 import java.io.*;
  31 import java.net.URL;
  32 
  33 import jdk.internal.event.EventHelper;
  34 import jdk.internal.event.SecurityPropertyEvent;
  35 import jdk.internal.misc.SharedSecrets;
  36 import jdk.internal.util.StaticProperty;
  37 import sun.security.util.Debug;
  38 import sun.security.util.PropertyExpander;
  39 
  40 import sun.security.jca.*;
  41 
  42 /**
  43  * <p>This class centralizes all security properties and common security
  44  * methods. One of its primary uses is to manage providers.
  45  *
  46  * <p>The default values of security properties are read from an
  47  * implementation-specific location, which is typically the properties file
  48  * {@code conf/security/java.security} in the Java installation directory.
  49  *
  50  * @author Benjamin Renaud
  51  * @since 1.1
  52  */
  53 
  54 public final class Security {


 780      * permission to see if it's ok to set the specified
 781      * security property value.
 782      *
 783      * @param key the name of the property to be set.
 784      *
 785      * @param datum the value of the property to be set.
 786      *
 787      * @throws  SecurityException
 788      *          if a security manager exists and its {@link
 789      *          java.lang.SecurityManager#checkPermission} method
 790      *          denies access to set the specified security property value
 791      * @throws  NullPointerException if key or datum is null
 792      *
 793      * @see #getProperty
 794      * @see java.security.SecurityPermission
 795      */
 796     public static void setProperty(String key, String datum) {
 797         check("setProperty."+key);
 798         props.put(key, datum);
 799         invalidateSMCache(key);  /* See below. */
 800 
 801         SecurityPropertyEvent spe = new SecurityPropertyEvent();
 802         if (spe.isEnabled() || EventHelper.isLoggingSecurity()) {
 803             EventHelper.commitSecurityPropertyEvent(spe, key, datum);
 804         }
 805     }
 806 
 807     /*
 808      * Implementation detail:  If the property we just set in
 809      * setProperty() was either "package.access" or
 810      * "package.definition", we need to signal to the SecurityManager
 811      * class that the value has just changed, and that it should
 812      * invalidate it's local cache values.
 813      */
 814     private static void invalidateSMCache(String key) {
 815 
 816         final boolean pa = key.equals("package.access");
 817         final boolean pd = key.equals("package.definition");
 818 
 819         if (pa || pd) {
 820             SharedSecrets.getJavaLangAccess().invalidatePackageAccessCache();
 821         }
 822     }
 823 
 824     private static void check(String directive) {


< prev index next >