1 18 package org.apache.batik.script.rhino; 19 20 import org.mozilla.javascript.Context; 21 import org.mozilla.javascript.GeneratedClassLoader; 22 import org.mozilla.javascript.JavaScriptException; 23 import org.mozilla.javascript.Script; 24 import org.mozilla.javascript.Scriptable; 25 import org.mozilla.javascript.SecurityController; 26 27 import java.security.AccessController ; 28 import java.security.AccessControlContext ; 29 import java.security.PrivilegedAction ; 30 import java.security.PrivilegedExceptionAction ; 31 import java.security.PrivilegedActionException ; 32 33 42 public class BatikSecurityController extends SecurityController { 43 44 47 public GeneratedClassLoader createClassLoader 48 (final ClassLoader parentLoader, Object securityDomain) { 49 50 if (securityDomain instanceof RhinoClassLoader) { 51 return (RhinoClassLoader)securityDomain; 52 } 53 54 throw new SecurityException ("Script() objects are not supported"); 57 } 58 59 65 public Object getDynamicSecurityDomain(Object securityDomain) { 66 67 ClassLoader loader = (RhinoClassLoader)securityDomain; 68 if (loader != null) 74 return loader; 75 76 return AccessController.getContext(); 77 } 78 79 89 public Object execWithDomain(final Context cx, final Scriptable scope, 90 final Script script, Object securityDomain) 91 throws JavaScriptException { 92 93 AccessControlContext acc; 94 if (securityDomain instanceof AccessControlContext ) 95 acc = (AccessControlContext )securityDomain; 96 else { 97 RhinoClassLoader loader = (RhinoClassLoader)securityDomain; 98 acc = loader.rhinoAccessControlContext; 99 } 100 101 try { 102 return AccessController.doPrivileged 104 (new PrivilegedExceptionAction () { 105 public Object run() throws JavaScriptException { 106 return script.exec(cx, scope); 107 } 108 }, acc ); 109 } catch (Exception e) { 110 throw new JavaScriptException(e); 111 } 112 113 } 114 } 115 | Popular Tags |