diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 3d939ec2c9..cb64cee2d0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -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; @@ -967,14 +969,28 @@ public static List findModules() { public static List findModules(ClassLoader classLoader) { ArrayList modules = new ArrayList(); - ServiceLoader loader = (classLoader == null) ? - ServiceLoader.load(Module.class) : ServiceLoader.load(Module.class, classLoader); + ServiceLoader loader = secureGetServiceLoader(Module.class, classLoader); for (Module module : loader) { modules.add(module); } return modules; } + private static ServiceLoader secureGetServiceLoader(final Class 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>() { + @Override + public ServiceLoader run() { + return (classLoader == null) ? + ServiceLoader.load(clazz) : ServiceLoader.load(clazz, classLoader); + } + }); + } + /** * Convenience method that is functionally equivalent to: *