I struggle a little 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();
/* configure context */
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);
/* run code in sandbox */
SandboxedCallResult<List<String>> result = sandboxService.runSandboxed(UntrustedCode.class, context);
/* output result */
}
}
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 the access of the System.class in all classes which are being executed in the sandbox but despite denying permission of the System.class the class "Test" is still able to call methods of System. Is there are way to realize this?