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 /** 36 * Returns the value of the security property propName, which can be overridden 37 * by a system property of the same name 38 * 39 * @param propName the name of the system or security property 40 * @return the value of the system or security property 41 */ 42 public static String privilegedGetOverridable(String propName) { 43 return AccessController.doPrivileged((PrivilegedAction<String>) 44 () -> { 45 String val = System.getProperty(propName); 46 if (val == null) { 47 return Security.getProperty(propName); 48 } else { 49 return val; 50 } 51 }); 52 } 53 54 /** 55 * Returns true in case the system or security property "jdk.includeInExceptions" 56 * contains the category refName 57 * 58 * @param refName the category to check 59 * @return true in case the system or security property "jdk.includeInExceptions" 60 * contains refName, false otherwise 61 */ 62 public static boolean includedInExceptions(String refName) { 63 String val = privilegedGetOverridable("jdk.includeInExceptions"); 64 if (val == null) { 65 return false; 66 } 67 68 String[] tokens = val.split(","); 69 for (String token : tokens) { 70 token = token.trim(); 71 if (token.equalsIgnoreCase(refName)) { 72 return true; 73 } 74 } 75 return false; 76 } 77 }