1 16 17 package org.apache.batik.script.rhino; 18 19 import org.apache.batik.test.*; 20 import org.apache.batik.util.ApplicationSecurityEnforcer; 21 import org.apache.batik.util.ParsedURL; 22 import org.apache.batik.test.svg.SelfContainedSVGOnLoadTest; 23 import org.apache.batik.bridge.UserAgent; 24 import org.apache.batik.bridge.UserAgentAdapter; 25 import org.apache.batik.bridge.ScriptSecurity; 26 import org.apache.batik.bridge.DefaultScriptSecurity; 27 import org.apache.batik.bridge.NoLoadScriptSecurity; 28 import org.apache.batik.bridge.RelaxedScriptSecurity; 29 30 39 40 public class ScriptSelfTest extends SelfContainedSVGOnLoadTest { 41 boolean secure = true; 42 boolean constrain = true; 43 String scripts = "text/ecmascript, application/java-archive"; 44 TestUserAgent userAgent = new TestUserAgent(); 45 46 public void setId(String id){ 47 super.setId(id); 48 svgURL = resolveURL("test-resources/org/apache/batik/" + id + ".svg"); 49 } 50 51 public void setSecure(Boolean secure){ 52 this.secure = secure.booleanValue(); 53 } 54 55 public Boolean getSecure(){ 56 return new Boolean (this.secure); 57 } 58 59 public void setConstrain(Boolean constrain){ 60 this.constrain = constrain.booleanValue(); 61 } 62 63 public Boolean getConstrain(){ 64 return new Boolean (this.constrain); 65 } 66 67 public void setScripts(String scripts){ 68 this.scripts = scripts; 69 } 70 71 public String getScripts(){ 72 return scripts; 73 } 74 75 public TestReport runImpl() throws Exception { 76 ApplicationSecurityEnforcer ase 77 = new ApplicationSecurityEnforcer(this.getClass(), 78 "org/apache/batik/apps/svgbrowser/resources/svgbrowser.policy"); 79 80 if (secure) { 81 ase.enforceSecurity(true); 82 } 83 84 try { 85 return super.runImpl(); 86 } finally { 87 ase.enforceSecurity(false); 88 } 89 } 90 91 protected UserAgent buildUserAgent(){ 92 return userAgent; 93 } 94 95 class TestUserAgent extends UserAgentAdapter { 96 public ScriptSecurity getScriptSecurity(String scriptType, 97 ParsedURL scriptPURL, 98 ParsedURL docPURL){ 99 if (scripts.indexOf(scriptType) == -1){ 100 return new NoLoadScriptSecurity(scriptType); 101 } else { 102 if (constrain){ 103 return new DefaultScriptSecurity 104 (scriptType, scriptPURL, docPURL); 105 } else { 106 return new RelaxedScriptSecurity 107 (scriptType, scriptPURL, docPURL); 108 } 109 } 110 } 111 } 112 113 } 114 | Popular Tags |