40
40
@ SuppressWarnings ({"unused" , "SystemOut" })
41
41
public class ExtensionClassLoader extends URLClassLoader {
42
42
public static final String EXTENSIONS_CONFIG = "otel.javaagent.extensions" ;
43
- // if this class was defined with all permissions then also define classes in this class loader
44
- // with all permissions
45
- // this class is defined with all permissions when security manager support is enabled
46
- private static final boolean addAllPermissions =
47
- ExtensionClassLoader .class
48
- .getProtectionDomain ()
49
- .getPermissions ()
50
- .implies (new AllPermission ());
43
+
44
+ private final boolean isSecurityManagerSupportEnabled ;
51
45
52
46
// NOTE it's important not to use logging in this class, because this class is used before logging
53
47
// is initialized
@@ -56,7 +50,8 @@ public class ExtensionClassLoader extends URLClassLoader {
56
50
ClassLoader .registerAsParallelCapable ();
57
51
}
58
52
59
- public static ClassLoader getInstance (ClassLoader parent , File javaagentFile ) {
53
+ public static ClassLoader getInstance (
54
+ ClassLoader parent , File javaagentFile , boolean isSecurityManagerSupportEnabled ) {
60
55
List <URL > extensions = new ArrayList <>();
61
56
62
57
includeEmbeddedExtensionsIfFound (parent , extensions , javaagentFile );
@@ -81,7 +76,7 @@ public static ClassLoader getInstance(ClassLoader parent, File javaagentFile) {
81
76
82
77
List <ClassLoader > delegates = new ArrayList <>(extensions .size ());
83
78
for (URL url : extensions ) {
84
- delegates .add (getDelegate (parent , url ));
79
+ delegates .add (getDelegate (parent , url , isSecurityManagerSupportEnabled ));
85
80
}
86
81
return new MultipleParentClassLoader (parent , delegates );
87
82
}
@@ -132,8 +127,9 @@ private static File ensureTempDirectoryExists(File tempDirectory) throws IOExcep
132
127
return tempDirectory ;
133
128
}
134
129
135
- private static URLClassLoader getDelegate (ClassLoader parent , URL extensionUrl ) {
136
- return new ExtensionClassLoader (new URL [] {extensionUrl }, parent );
130
+ private static URLClassLoader getDelegate (
131
+ ClassLoader parent , URL extensionUrl , boolean isSecurityManagerSupportEnabled ) {
132
+ return new ExtensionClassLoader (extensionUrl , parent , isSecurityManagerSupportEnabled );
137
133
}
138
134
139
135
// visible for testing
@@ -194,15 +190,17 @@ private static void extractFile(JarFile jarFile, JarEntry jarEntry, File outputF
194
190
195
191
@ Override
196
192
protected PermissionCollection getPermissions (CodeSource codesource ) {
197
- if (addAllPermissions ) {
193
+ if (isSecurityManagerSupportEnabled ) {
198
194
Permissions permissions = new Permissions ();
199
195
permissions .add (new AllPermission ());
200
196
return permissions ;
201
197
}
202
198
return super .getPermissions (codesource );
203
199
}
204
200
205
- private ExtensionClassLoader (URL [] urls , ClassLoader parent ) {
206
- super (urls , parent );
201
+ private ExtensionClassLoader (
202
+ URL url , ClassLoader parent , boolean isSecurityManagerSupportEnabled ) {
203
+ super (new URL [] {url }, parent );
204
+ this .isSecurityManagerSupportEnabled = isSecurityManagerSupportEnabled ;
207
205
}
208
206
}
0 commit comments