Skip to content

Commit

Permalink
Remove SecMgr, etc usage from java.prefs
Browse files Browse the repository at this point in the history
  • Loading branch information
bchristi-git committed Nov 19, 2024
1 parent 63eb485 commit de6717c
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import java.util.Objects;

class MacOSXPreferences extends AbstractPreferences {
// fixme need security checks?

// CF preferences file name for Java nodes with short names
// This value is also in MacOSXPreferencesFile.c
private static final String defaultAppName = "com.apple.java.util.prefs";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,9 @@ class MacOSXPreferencesFile {
loadPrefsLib();
}

@SuppressWarnings({"removal", "restricted"})
@SuppressWarnings("restricted")
private static void loadPrefsLib() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("prefs");
return null;
}
});
System.loadLibrary("prefs");
}

private static class FlushTask extends TimerTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import java.util.*;
import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This class provides a skeletal implementation of the {@link Preferences}
Expand Down Expand Up @@ -1060,12 +1058,7 @@ public String absolutePath() {
*/
@SuppressWarnings("removal")
public boolean isUserNode() {
return AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
return root == Preferences.userRoot();
}
}).booleanValue();
return root == Preferences.userRoot();
}

public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
Expand Down
47 changes: 2 additions & 45 deletions src/java.prefs/share/classes/java/util/prefs/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,10 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.util.Iterator;
import java.util.ServiceLoader;
import java.util.ServiceConfigurationError;

// These imports needed only as a workaround for a JavaDoc bug
import java.lang.RuntimePermission;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Float;
import java.lang.Double;

/**
* A node in a hierarchical collection of preference data. This class
* allows applications to store and retrieve user and system
Expand Down Expand Up @@ -230,16 +220,8 @@ public abstract class Preferences {
@SuppressWarnings("removal")
private static PreferencesFactory factory() {
// 1. Try user-specified system property
String factoryName = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
return System.getProperty(
"java.util.prefs.PreferencesFactory");}});
String factoryName = System.getProperty("java.util.prefs.PreferencesFactory");
if (factoryName != null) {
// FIXME: This code should be run in a doPrivileged and
// not use the context classloader, to avoid being
// dependent on the invoking thread.
// Checking AllPermission also seems wrong.
try {
@SuppressWarnings("deprecation")
Object result =Class.forName(factoryName, false,
Expand All @@ -250,10 +232,6 @@ public String run() {
try {
// workaround for javaws, plugin,
// load factory class using non-system classloader
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new java.security.AllPermission());
}
@SuppressWarnings("deprecation")
Object result = Class.forName(factoryName, false,
Thread.currentThread()
Expand All @@ -267,11 +245,7 @@ public String run() {
}
}
}

return AccessController.doPrivileged(
new PrivilegedAction<PreferencesFactory>() {
public PreferencesFactory run() {
return factory1();}});
return factory1();
}

private static PreferencesFactory factory1() {
Expand Down Expand Up @@ -427,24 +401,12 @@ private static String nodeName(Class<?> c) {
return "/" + packageName.replace('.', '/');
}

/**
* This permission object represents the permission required to get
* access to the user or system root (which in turn allows for all
* other operations).
*/
private static Permission prefsPerm = new RuntimePermission("preferences");

/**
* Returns the root preference node for the calling user.
*
* @return the root preference node for the calling user.
*/
public static Preferences userRoot() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(prefsPerm);

return factory.userRoot();
}

Expand All @@ -454,11 +416,6 @@ public static Preferences userRoot() {
* @return the root preference node for the system.
*/
public static Preferences systemRoot() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(prefsPerm);

return factory.systemRoot();
}

Expand Down
Loading

0 comments on commit de6717c

Please sign in to comment.