I am struggling a bit with the java-sandbox API . Consider the following code:
Sandkiste.java:
import java.util.List;
import java.util.concurrent.TimeUnit;
import net.datenwerke.sandbox.*;
import net.datenwerke.sandbox.SandboxContext.AccessType;
import net.datenwerke.sandbox.SandboxContext.RuntimeMode;
import net.datenwerke.sandbox.handlers.BadThreadKillHandler;
public class Sandkiste {
public static void main(String[] args) {
Sandkiste s = new Sandkiste();
s.run();
}
public void run(){
SandboxService sandboxService = SandboxServiceImpl.getInstance();
SandboxContext context = new SandboxContext();
context.addClassForApplicationLoader("Test");
context.addClassPermission(AccessType.PERMIT, "Test");
context.addClassPermission(AccessType.PERMIT,UntrustedCode.class.getName());
context.addClassPermission(AccessType.DENY, "java.lang.System");
context.addClassPermission(AccessType.DENY, "java.io.PrintStream");
context.setRunInThread(true);
SandboxedCallResult<List<String>> result = sandboxService.runSandboxed(UntrustedCode.class, context);
}
}
UntrustedCode.java:
import java.util.List;
import net.datenwerke.sandbox.SandboxedEnvironment;
public class UntrustedCode implements SandboxedEnvironment<List<String>> {
@Override
public List<String> execute() throws Exception {
Test t = new Test();
t.print();
return null;
}
}
Test.java:
public class Test {
public void print() {
System.out.println("Erlaubt!");
}
}
I want to deny access to System.class in all classes that run in the sandbox, but despite the denial of System.class permission, the Test class is still able to call system methods. Is there any way to implement this?
source
share