8209416: Refactoring GetPropertyAction calls in security libs

Reviewed-by: xuelei, rriggs
This commit is contained in:
Weijun Wang 2018-08-14 22:39:34 +08:00
parent 815cdefb43
commit 33a96c6df9
29 changed files with 146 additions and 196 deletions

View file

@ -45,6 +45,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.net.dns.ResolverConfiguration;
import sun.security.action.GetPropertyAction;
import sun.security.krb5.internal.crypto.EType;
import sun.security.krb5.internal.Krb5;
@ -122,12 +123,12 @@ public class Config {
private static boolean isMacosLionOrBetter() {
// split the "10.x.y" version number
String osname = getProperty("os.name");
String osname = GetPropertyAction.privilegedGetProperty("os.name");
if (!osname.contains("OS X")) {
return false;
}
String osVersion = getProperty("os.version");
String osVersion = GetPropertyAction.privilegedGetProperty("os.version");
String[] fragments = osVersion.split("\\.");
// sanity check the "10." part of the version
@ -152,14 +153,16 @@ public class Config {
/*
* If either one system property is specified, we throw exception.
*/
String tmp = getProperty("java.security.krb5.kdc");
String tmp = GetPropertyAction
.privilegedGetProperty("java.security.krb5.kdc");
if (tmp != null) {
// The user can specify a list of kdc hosts separated by ":"
defaultKDC = tmp.replace(':', ' ');
} else {
defaultKDC = null;
}
defaultRealm = getProperty("java.security.krb5.realm");
defaultRealm = GetPropertyAction
.privilegedGetProperty("java.security.krb5.realm");
if ((defaultKDC == null && defaultRealm != null) ||
(defaultRealm == null && defaultKDC != null)) {
throw new KrbException
@ -818,11 +821,12 @@ public class Config {
* The method returns null if it cannot find a Java config file.
*/
private String getJavaFileName() {
String name = getProperty("java.security.krb5.conf");
String name = GetPropertyAction
.privilegedGetProperty("java.security.krb5.conf");
if (name == null) {
name = getProperty("java.home") + File.separator +
"conf" + File.separator + "security" +
File.separator + "krb5.conf";
name = GetPropertyAction.privilegedGetProperty("java.home")
+ File.separator + "conf" + File.separator + "security"
+ File.separator + "krb5.conf";
if (!fileExists(name)) {
name = null;
}
@ -852,7 +856,7 @@ public class Config {
*/
private String getNativeFileName() {
String name = null;
String osname = getProperty("os.name");
String osname = GetPropertyAction.privilegedGetProperty("os.name");
if (osname.startsWith("Windows")) {
try {
Credentials.ensureLoaded();
@ -899,13 +903,8 @@ public class Config {
return name;
}
private static String getProperty(String property) {
return java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction(property));
}
private String findMacosConfigFile() {
String userHome = getProperty("user.home");
String userHome = GetPropertyAction.privilegedGetProperty("user.home");
final String PREF_FILE = "/Library/Preferences/edu.mit.Kerberos";
String userPrefs = userHome + PREF_FILE;