pnuts.ext.SecurePnutsImpl class is a wrapper class of PnutsImpl class which adds a security functionality using JDK1.2 security. This class is useful to implement a secure script environment, in which Pnuts scripts can be executed as safely as Java applet.
First, -Djava.security.manager option should be given to the java command (This makes SecurePnutsImpl the default) . When the URL is behind a firewall, -Dhttp.proxyHost=host and -Dhttp.proxyPort=port are needed.
java -Djava.security.manager -Xbootclasspath/a:pnuts.jar pnuts.tools.Main -r init
Then specify the script's URL to load() function. The script is executed under the user's security policy.
load(URL("http://202.32.138.49/pnuts/examples/awt/hello.pnut"))
When the second parameter of the SecurePnutsImpl constructor is a CodeSource object, the script is executed assuming that the CodeSource represents the original location of the script. The following code illustrates how to evaluate an expression safely when the expression is originated in a remote host.
import("pnuts.ext.*") import("java.security.*") impl = SecurePnutsImpl(PnutsImpl(), CodeSource(URL("http://202.32.138.49/pnuts/"), null)) impl.eval(`s = URL("http://localhost/pnuts/examples/awt/hello.pnut")`, getContext()) impl.eval("read(s.openStream())", getContext()) ==> access denied impl.eval(`s = URL("http://202.32.138.49/pnuts/examples/awt/hello.pnut")`, getContext()) impl.eval("read(s.openStream())", getContext()) ==> succeed