r9823 - helma-ng/trunk/src/org/helma/javascript

[email protected] Tue, 9 Jun 2009 09:20:09 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090609072009.B397E3D0E3@mia>
Author: hannes
Date: 2009-06-09 09:20:09 +0200 (Tue, 09 Jun 2009)
New Revision: 9823

Modified:
   helma-ng/trunk/src/org/helma/javascript/HelmaContextFactory.java
   helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java
Log:
Attach java.security.CodeSources to compiled modules and install org.mozilla.javascript.PolicySecurityController in Rhino Contexts.

Details at http://dev.helma.org/trac/helma/changeset/9823

Modified: helma-ng/trunk/src/org/helma/javascript/HelmaContextFactory.java
===================================================================
--- helma-ng/trunk/src/org/helma/javascript/HelmaContextFactory.java	2009-06-09 07:20:08 UTC (rev 9822)
+++ helma-ng/trunk/src/org/helma/javascript/HelmaContextFactory.java	2009-06-09 07:20:09 UTC (rev 9823)
@@ -14,6 +14,7 @@
 import org.mozilla.javascript.ContextFactory;
 import org.mozilla.javascript.ErrorReporter;
 import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.PolicySecurityController;
 import org.helma.repository.Trackable;
 import org.helma.tools.HelmaConfiguration;
 
@@ -64,6 +65,7 @@
         cx.setWrapFactory(engine.wrapFactory);
         cx.setLanguageVersion(languageVersion);
         cx.setOptimizationLevel(optimizationLevel);
+        cx.setSecurityController(new PolicySecurityController());
         if (errorReporter != null) {
             cx.setErrorReporter(errorReporter);
         }

Modified: helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java
===================================================================
--- helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java	2009-06-09 07:20:08 UTC (rev 9822)
+++ helma-ng/trunk/src/org/helma/javascript/ReloadableScript.java	2009-06-09 07:20:09 UTC (rev 9823)
@@ -25,6 +25,8 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.*;
+import java.security.CodeSource;
+import java.security.CodeSigner;
 
 /**
  * This class represents a JavaScript Resource.
@@ -105,7 +107,8 @@
         Resource resource = (Resource) source;
         try {
             exception = null;
-            script = cx.compileReader(resource.getReader(), resource.getRelativePath(), 1, null);
+            CodeSource source = new CodeSource(resource.getUrl(), (CodeSigner[]) null);
+            script = cx.compileReader(resource.getReader(), resource.getRelativePath(), 1, source);
         } catch (Exception x) {
             exception = x;
         } finally {
@@ -133,7 +136,8 @@
             exception = null;
             for (Resource res: resources) {
                 if (res.getName().endsWith(".js")) {
-                    scripts.add(cx.compileReader(res.getReader(), res.getRelativePath(), 1, null));
+                    CodeSource source = new CodeSource(res.getUrl(), (CodeSigner[]) null);                    
+                    scripts.add(cx.compileReader(res.getReader(), res.getRelativePath(), 1, source));
                 }
            }
         } catch (Exception x) {