Skip to content

Commit

Permalink
Merge pull request #1585 from istudens/securitymanager_issue
Browse files Browse the repository at this point in the history
invoke ServiceLoader.load() inside of a privileged block
  • Loading branch information
cowtowncoder authored Apr 12, 2017
2 parents 32001a6 + 6ff0838 commit afcb309
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.*;
import java.lang.reflect.Type;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.DateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -967,14 +969,28 @@ public static List<Module> findModules() {
public static List<Module> findModules(ClassLoader classLoader)
{
ArrayList<Module> modules = new ArrayList<Module>();
ServiceLoader<Module> loader = (classLoader == null) ?
ServiceLoader.load(Module.class) : ServiceLoader.load(Module.class, classLoader);
ServiceLoader<Module> loader = secureGetServiceLoader(Module.class, classLoader);
for (Module module : loader) {
modules.add(module);
}
return modules;
}

private static <T> ServiceLoader<T> secureGetServiceLoader(final Class<T> clazz, final ClassLoader classLoader) {
final SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return (classLoader == null) ?
ServiceLoader.load(clazz) : ServiceLoader.load(clazz, classLoader);
}
return AccessController.doPrivileged(new PrivilegedAction<ServiceLoader<T>>() {
@Override
public ServiceLoader<T> run() {
return (classLoader == null) ?
ServiceLoader.load(clazz) : ServiceLoader.load(clazz, classLoader);
}
});
}

/**
* Convenience method that is functionally equivalent to:
*<code>
Expand Down

0 comments on commit afcb309

Please sign in to comment.