Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 4 additions & 28 deletions api/src/main/java/jakarta/activation/CommandInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.io.ObjectInputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* The CommandInfo class is used by CommandMap implementations to
Expand Down Expand Up @@ -171,34 +169,12 @@ static Object instantiate(ClassLoader loader, String cn)

} else {

SecurityManager security = System.getSecurityManager();
if (security != null) {
// if it's ok with the SecurityManager, it's ok with me.
String cname = cn.replace('/', '.');
if (cname.startsWith("[")) {
int b = cname.lastIndexOf('[') + 2;
if (b > 1 && b < cname.length()) {
cname = cname.substring(b);
}
}
int i = cname.lastIndexOf('.');
if (i != -1) {
security.checkPackageAccess(cname.substring(0, i));
}
}

// Beans.instantiate specified to use SCL when loader is null
if (loader == null) {
loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
ClassLoader cl = null;
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
}
return cl;
}
});
try {
loader = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
}
}
Class<?> beanClass = Class.forName(cn, true, loader);
try {
Expand Down
20 changes: 2 additions & 18 deletions api/src/main/java/jakarta/activation/CommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static synchronized CommandMap getDefaultCommandMap() {
return defaultCommandMap;

// fetch per-thread-context-class-loader default
ClassLoader tccl = SecuritySupport.getContextClassLoader();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
CommandMap def = map.get(tccl);
if (def == null) {
def = new MailcapCommandMap();
Expand All @@ -72,24 +72,8 @@ public static synchronized CommandMap getDefaultCommandMap() {
* to change the default
*/
public static synchronized void setDefaultCommandMap(CommandMap commandMap) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
try {
// if it's ok with the SecurityManager, it's ok with me...
security.checkSetFactory();
} catch (SecurityException ex) {
// otherwise, we also allow it if this code and the
// factory come from the same (non-system) class loader (e.g.,
// the JAF classes were loaded with the applet classes).
ClassLoader cl = CommandMap.class.getClassLoader();
if (cl == null || cl.getParent() == null ||
cl != commandMap.getClass().getClassLoader()) {
throw ex;
}
}
}
// remove any per-thread-context-class-loader CommandMap
map.remove(SecuritySupport.getContextClassLoader());
map.remove(Thread.currentThread().getContextClassLoader());
defaultCommandMap = commandMap;
}

Expand Down
16 changes: 1 addition & 15 deletions api/src/main/java/jakarta/activation/DataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public Object getBean(CommandInfo cmdinfo) {
// make the bean
ClassLoader cld = null;
// First try the "application's" class loader.
cld = SecuritySupport.getContextClassLoader();
cld = Thread.currentThread().getContextClassLoader();
if (cld == null)
cld = this.getClass().getClassLoader();
bean = cmdinfo.getCommandObject(this, cld);
Expand Down Expand Up @@ -634,20 +634,6 @@ public static synchronized void setDataContentHandlerFactory(
if (factory != null)
throw new Error("DataContentHandlerFactory already defined");

SecurityManager security = System.getSecurityManager();
if (security != null) {
try {
// if it's ok with the SecurityManager, it's ok with me...
security.checkSetFactory();
} catch (SecurityException ex) {
// otherwise, we also allow it if this code and the
// factory come from the same class loader (e.g.,
// the JAF classes were loaded with the applet classes).
if (DataHandler.class.getClassLoader() !=
newFactory.getClass().getClassLoader())
throw ex;
}
}
factory = newFactory;
}
}
Expand Down
72 changes: 29 additions & 43 deletions api/src/main/java/jakarta/activation/FactoryFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
package jakarta.activation;

import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.Iterator;
import java.util.logging.Level;
Expand Down Expand Up @@ -102,12 +100,7 @@ private static String fromSystemProperty(String factoryId) {

private static String getSystemProperty(final String property) {
logger.log(Level.FINE, "Checking system property {0}", property);
String value = AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(property);
}
});
String value = System.getProperty(property);
logFound(value);
return value;
}
Expand Down Expand Up @@ -163,42 +156,35 @@ private static <T> T lookupUsingHk2ServiceLoader(Class<T> factoryClass, ClassLoa
}

private static ClassLoader[] getClassLoaders(final Class<?>... classes) {
return AccessController.doPrivileged(
new PrivilegedAction<ClassLoader[]>() {
@Override
public ClassLoader[] run() {
ClassLoader[] loaders = new ClassLoader[classes.length];
int w = 0;
for (Class<?> k : classes) {
ClassLoader cl = null;
if (k == Thread.class) {
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
}
} else if (k == System.class) {
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
}
} else {
try {
cl = k.getClassLoader();
} catch (SecurityException ex) {
}
}

if (cl != null) {
loaders[w++] = cl;
}
}

if (loaders.length != w) {
loaders = Arrays.copyOf(loaders, w);
}
return loaders;
ClassLoader[] loaders = new ClassLoader[classes.length];
int w = 0;
for (Class<?> k : classes) {
ClassLoader cl = null;
if (k == Thread.class) {
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException ex) {
}
} else if (k == System.class) {
try {
cl = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
}
} else {
try {
cl = k.getClassLoader();
} catch (SecurityException ex) {
}
}
);

if (cl != null) {
loaders[w++] = cl;
}
}

if (loaders.length != w) {
loaders = Arrays.copyOf(loaders, w);
}
return loaders;
}
}
19 changes: 2 additions & 17 deletions api/src/main/java/jakarta/activation/FileTypeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,8 @@ public FileTypeMap() {
* to change the default
*/
public static synchronized void setDefaultFileTypeMap(FileTypeMap fileTypeMap) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
try {
// if it's ok with the SecurityManager, it's ok with me...
security.checkSetFactory();
} catch (SecurityException ex) {
// otherwise, we also allow it if this code and the
// factory come from the same (non-system) class loader (e.g.,
// the JAF classes were loaded with the applet classes).
ClassLoader cl = FileTypeMap.class.getClassLoader();
if (cl == null || cl.getParent() == null ||
cl != fileTypeMap.getClass().getClassLoader())
throw ex;
}
}
// remove any per-thread-context-class-loader FileTypeMap
map.remove(SecuritySupport.getContextClassLoader());
map.remove(Thread.currentThread().getContextClassLoader());
defaultMap = fileTypeMap;
}

Expand All @@ -114,7 +99,7 @@ public static synchronized FileTypeMap getDefaultFileTypeMap() {
return defaultMap;

// fetch per-thread-context-class-loader default
ClassLoader tccl = SecuritySupport.getContextClassLoader();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
FileTypeMap def = map.get(tccl);
if (def == null) {
def = new MimetypesFileTypeMap();
Expand Down
37 changes: 10 additions & 27 deletions api/src/main/java/jakarta/activation/MailcapCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -126,18 +124,11 @@ public class MailcapCommandMap extends CommandMap {
static {
String dir = null;
try {
dir = AccessController.doPrivileged(
new PrivilegedAction<String>() {
public String run() {
String home = System.getProperty("java.home");
String newdir = home + File.separator + "conf";
File conf = new File(newdir);
if (conf.exists())
return newdir + File.separator;
else
return home + File.separator + "lib" + File.separator;
}
});
String home = System.getProperty("java.home");
String newdir = home + File.separator + "conf";
File conf = new File(newdir);
dir = conf.exists() ? (newdir + File.separator) :
(home + File.separator + "lib" + File.separator);
} catch (Exception ex) {
// ignore any exceptions
}
Expand Down Expand Up @@ -195,7 +186,7 @@ public MailcapCommandMap() {
* Load from the named resource.
*/
private MailcapRegistry loadResource(String name) {
try (InputStream clis = SecuritySupport.getResourceAsStream(this.getClass(), name)) {
try (InputStream clis = this.getClass().getResourceAsStream(name)) {
if (clis != null) {
MailcapRegistry mf = getImplementation().getByInputStream(clis);
if (LogSupport.isLoggable())
Expand Down Expand Up @@ -228,7 +219,7 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
URL[] urls;
ClassLoader cld = null;
// First try the "application's" class loader.
cld = SecuritySupport.getContextClassLoader();
cld = Thread.currentThread().getContextClassLoader();
if (cld == null)
cld = this.getClass().getClassLoader();
if (cld != null)
Expand All @@ -242,7 +233,7 @@ private void loadAllResources(List<MailcapRegistry> v, String name) {
URL url = urls[i];
if (LogSupport.isLoggable())
LogSupport.log("MailcapCommandMap: URL " + url);
try (InputStream clis = SecuritySupport.openStream(url)) {
try (InputStream clis = url.openStream()) {
if (clis != null) {
v.add(getImplementation().getByInputStream(clis));
anyLoaded = true;
Expand Down Expand Up @@ -615,7 +606,7 @@ private DataContentHandler getDataContentHandler(String name) {
try {
ClassLoader cld = null;
// First try the "application's" class loader.
cld = SecuritySupport.getContextClassLoader();
cld = Thread.currentThread().getContextClassLoader();
if (cld == null)
cld = this.getClass().getClassLoader();
Class<?> cl = null;
Expand Down Expand Up @@ -703,15 +694,7 @@ public synchronized String[] getNativeCommands(String mimeType) {
}

private MailcapRegistryProvider getImplementation() {
if (System.getSecurityManager() != null) {
return AccessController.doPrivileged(new PrivilegedAction<MailcapRegistryProvider>() {
public MailcapRegistryProvider run() {
return FactoryFinder.find(MailcapRegistryProvider.class);
}
});
} else {
return FactoryFinder.find(MailcapRegistryProvider.class);
}
return FactoryFinder.find(MailcapRegistryProvider.class);
}

/*
Expand Down
Loading