1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018 SAP SE. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. Oracle designates this 9 * particular file as subject to the "Classpath" exception as provided 10 * by Oracle in the LICENSE file that accompanied this code. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23 * or visit www.oracle.com if you need additional information or have any 24 * questions. 25 */ 26 27 package sun.security.util; 28 29 import java.security.AccessController; 30 import java.security.PrivilegedAction; 31 import java.security.Security; 32 33 public class SecurityProperties { 34 35 public static final boolean INCLUDE_JAR_NAME_IN_EXCEPTIONS 36 = includedInExceptions("jar"); 37 38 /** 39 * Returns the value of the security property propName, which can be overridden 40 * by a system property of the same name 41 * 42 * @param propName the name of the system or security property 43 * @return the value of the system or security property 44 */ privilegedGetOverridable(String propName)45 public static String privilegedGetOverridable(String propName) { 46 if (System.getSecurityManager() == null) { 47 return getOverridableProperty(propName); 48 } else { 49 return AccessController.doPrivileged((PrivilegedAction<String>) () -> getOverridableProperty(propName)); 50 } 51 } 52 getOverridableProperty(String propName)53 private static String getOverridableProperty(String propName) { 54 String val = System.getProperty(propName); 55 if (val == null) { 56 return Security.getProperty(propName); 57 } else { 58 return val; 59 } 60 } 61 62 /** 63 * Returns true in case the system or security property "jdk.includeInExceptions" 64 * contains the category refName 65 * 66 * @param refName the category to check 67 * @return true in case the system or security property "jdk.includeInExceptions" 68 * contains refName, false otherwise 69 */ includedInExceptions(String refName)70 public static boolean includedInExceptions(String refName) { 71 String val = privilegedGetOverridable("jdk.includeInExceptions"); 72 if (val == null) { 73 return false; 74 } 75 76 String[] tokens = val.split(","); 77 for (String token : tokens) { 78 token = token.trim(); 79 if (token.equalsIgnoreCase(refName)) { 80 return true; 81 } 82 } 83 return false; 84 } 85 } 86