|
10 | 10 |
|
11 | 11 | import org.opensearch.javaagent.bootstrap.AgentPolicy;
|
12 | 12 |
|
13 |
| -import java.lang.StackWalker.Option; |
14 | 13 | import java.lang.reflect.Method;
|
15 | 14 | import java.net.InetSocketAddress;
|
16 | 15 | import java.net.NetPermission;
|
|
19 | 18 | import java.security.Policy;
|
20 | 19 | import java.security.ProtectionDomain;
|
21 | 20 | import java.util.Collection;
|
22 |
| -import java.util.ArrayList; |
23 |
| -import java.util.List; |
24 |
| -import java.lang.StackWalker.StackFrame; |
25 |
| -import java.util.stream.Collectors; |
26 | 21 |
|
27 | 22 | import net.bytebuddy.asm.Advice;
|
28 | 23 | import net.bytebuddy.asm.Advice.Origin;
|
@@ -51,23 +46,7 @@ public static void intercept(@Advice.AllArguments Object[] args, @Origin Method
|
51 | 46 | }
|
52 | 47 |
|
53 | 48 | final StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
|
54 |
| - final Collection<ProtectionDomain> callers = walker.walk(s -> { |
55 |
| - List<ProtectionDomain> domains = new ArrayList<>(); |
56 |
| - boolean foundPrivileged = false; |
57 |
| - |
58 |
| - for (StackFrame frame : s.toList()) { |
59 |
| - if (frame.getClassName().equals("java.security.AccessController") && |
60 |
| - frame.getMethodName().equals("doPrivileged")) { |
61 |
| - foundPrivileged = true; |
62 |
| - break; |
63 |
| - } |
64 |
| - Class<?> callerClass = frame.getDeclaringClass(); |
65 |
| - domains.add(callerClass.getProtectionDomain()); |
66 |
| - } |
67 |
| - |
68 |
| - return foundPrivileged ? domains : s.map(f -> f.getDeclaringClass().getProtectionDomain()) |
69 |
| - .collect(Collectors.toList()); |
70 |
| - }); |
| 49 | + final Collection<ProtectionDomain> callers = walker.walk(StackCallerProtectionDomainChainExtractor.INSTANCE); |
71 | 50 |
|
72 | 51 | if (args[0] instanceof InetSocketAddress address) {
|
73 | 52 | if (!AgentPolicy.isTrustedHost(address.getHostString())) {
|
|
0 commit comments