1 18 package org.apache.batik.bridge; 19 20 import java.awt.AWTPermission ; 21 import java.io.FilePermission ; 22 import java.io.SerializablePermission ; 23 import java.lang.reflect.ReflectPermission ; 24 import java.net.NetPermission ; 25 import java.net.SocketPermission ; 26 import java.net.URL ; 27 import java.security.AllPermission ; 28 import java.security.Permission ; 29 import java.sql.SQLPermission ; 30 import java.util.PropertyPermission ; 31 import java.util.Vector ; 32 33 import javax.sound.sampled.AudioPermission ; 34 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.Element ; 37 import org.w3c.dom.events.Event ; 38 import org.w3c.dom.events.EventListener ; 39 import org.w3c.dom.events.EventTarget ; 40 41 import org.apache.batik.dom.svg.SVGOMDocument; 42 import org.apache.batik.script.ScriptHandler; 43 import org.apache.batik.script.Window; 44 45 49 public class JarCheckPermissionsGranted implements ScriptHandler { 50 public static final String svgNS = "http://www.w3.org/2000/svg"; 51 public static final String testNS = "http://xml.apache.org/batik/test"; 52 53 56 public static final String testedPath = "build.sh"; 57 58 61 public static final String testedHost = "nagoya.apache.org:8080"; 62 63 66 protected static Object [][] basePermissions = { 67 {"AllPermission", new AllPermission ()}, 68 {"FilePermission read", new FilePermission (testedPath, "read")}, 69 {"FilePermission write", new FilePermission (testedPath, "write")}, 70 {"FilePermission execute", new FilePermission (testedPath, "execute")}, 71 {"FilePermission delete", new FilePermission (testedPath, "delete")}, 72 {"SocketPermission accept", new SocketPermission (testedHost, "accept")}, 74 {"SocketPermission connect", new SocketPermission (testedHost, "connect")}, 75 {"SocketPermission listen", new SocketPermission (testedHost, "listen")}, 76 {"SocketPermission resolve", new SocketPermission (testedHost, "resolve")}, 77 {"AudioPermission play", new AudioPermission ("play")}, 78 {"AudioPermission record", new AudioPermission ("record")}, 79 {"AWTPermission accessClipboard", new AWTPermission ("accessClipboard")}, 80 {"AWTPermission accessEventQueue", new AWTPermission ("accessEventQueue")}, 81 {"AWTPermission listenToAllAWTEvents", new AWTPermission ("listenToAllAWTEvents")}, 82 {"AWTPermission showWindowWithoutWarningBanner", new AWTPermission ("showWindowWithoutWarningBanner")}, 83 {"AWTPermission readDisplayPixels", new AWTPermission ("readDisplayPixels")}, 84 {"AWTPermission createRobot", new AWTPermission ("createRobot")}, 85 {"AWTPermission fullScreenExclusive", new AWTPermission ("fullScreenExclusive")}, 86 {"NetPermission setDefaultAuthenticator", new NetPermission ("setDefaultAuthenticator")}, 89 {"NetPermission requestPasswordAuthentication", new NetPermission ("requestPasswordAuthentication")}, 90 {"NetPermission specifyStreamHandler", new NetPermission ("specifyStreamHandler")}, 91 {"PropertyPermission java.home read", new PropertyPermission ("java.home", "read")}, 92 {"PropertyPermission java.home write", new PropertyPermission ("java.home", "write")}, 93 {"ReflectPermission", new ReflectPermission ("suppressAccessChecks")}, 94 {"RuntimePermission createClassLoader", new RuntimePermission ("createClassLoader")}, 95 {"RuntimePermission getClassLoader", new RuntimePermission ("getClassLoader")}, 96 {"RuntimePermission setContextClassLoader", new RuntimePermission ("setContextClassLoader")}, 97 {"RuntimePermission setSecurityManager", new RuntimePermission ("setSecurityManager")}, 98 {"RuntimePermission createSecurityManager", new RuntimePermission ("createSecurityManager")}, 99 {"RuntimePermission exitVM", new RuntimePermission ("exitVM")}, 100 {"RuntimePermission shutdownHooks", new RuntimePermission ("shutdownHooks")}, 101 {"RuntimePermission setFactory", new RuntimePermission ("setFactory")}, 102 {"RuntimePermission setIO", new RuntimePermission ("setIO")}, 103 {"RuntimePermission modifyThread", new RuntimePermission ("modifyThread")}, 104 {"RuntimePermission stopThread", new RuntimePermission ("stopThread")}, 105 {"RuntimePermission modifyThreadGroup", new RuntimePermission ("modifyThreadGroup")}, 106 {"RuntimePermission getProtectionDomain", new RuntimePermission ("getProtectionDomain")}, 107 {"RuntimePermission readFileDescriptor", new RuntimePermission ("readFileDescriptor")}, 108 {"RuntimePermission writeFileDescriptor", new RuntimePermission ("writeFileDescriptor")}, 109 {"RuntimePermission loadLibrary.{library name}", new RuntimePermission ("loadLibrary.{library name}")}, 110 {"RuntimePermission accessClassInPackage.java.security", new RuntimePermission ("accessClassInPackage.java.security")}, 111 {"RuntimePermission defineClassInPackage.java.lang", new RuntimePermission ("defineClassInPackage.java.lang")}, 112 {"RuntimePermission accessDeclaredMembers", new RuntimePermission ("accessDeclaredMembers")}, 113 {"RuntimePermission queuePrintJob", new RuntimePermission ("queuePrintJob")}, 114 115 {"SecurityPermission createAccessControlContext", new SerializablePermission ("createAccessControlContext")}, 116 {"SecurityPermission getDomainCombiner", new SerializablePermission ("getDomainCombiner")}, 117 {"SecurityPermission getPolicy", new SerializablePermission ("getPolicy")}, 118 {"SecurityPermission setPolicy", new SerializablePermission ("setPolicy")}, 119 {"SecurityPermission setSystemScope", new SerializablePermission ("setSystemScope")}, 120 {"SecurityPermission setIdentityPublicKey", new SerializablePermission ("setIdentityPublicKey")}, 121 {"SecurityPermission setIdentityInfo", new SerializablePermission ("setIdentityInfo")}, 122 {"SecurityPermission addIdentityCertificate", new SerializablePermission ("addIdentityCertificate")}, 123 {"SecurityPermission removeIdentityCertificate", new SerializablePermission ("removeIdentityCertificate")}, 124 {"SecurityPermission printIdentity", new SerializablePermission ("printIdentity")}, 125 {"SecurityPermission getSignerPrivateKey", new SerializablePermission ("getSignerPrivateKey")}, 126 {"SecurityPermission setSignerKeyPair", new SerializablePermission ("setSignerKeyPair")}, 127 128 {"SerializablePermission enableSubclassImplementation", new SerializablePermission ("enableSubclassImplementation")}, 129 {"SerializablePermission enableSubstitution", new SerializablePermission ("enableSubstitution")}, 130 131 {"SQLPermission", new SQLPermission ("setLog")}, 132 133 }; 136 137 140 private Object [][] permissions; 141 142 145 private Element [] statusRects; 146 147 152 public void run(final Document document, final Window win){ 153 URL docURL = ((SVGOMDocument)document).getURLObject(); 158 if (docURL != null && docURL.getHost() != null && !"".equals(docURL.getHost())) { 159 permissions = new Object [basePermissions.length + 3][2]; 160 System.arraycopy(basePermissions, 0, 161 permissions, 3, basePermissions.length); 162 163 String docHost = docURL.getHost(); 164 if (docURL.getPort() != -1) { 165 docHost += ":" + docURL.getPort(); 166 } 167 168 permissions[0][0] = "SocketPermission accept " + docHost; 169 permissions[0][1] = new SocketPermission (docHost, "accept"); 170 permissions[1][0] = "SocketPermission connect " + docHost; 171 permissions[1][1] = new SocketPermission (docHost, "connect"); 172 permissions[2][0] = "SocketPermission resolve " + docHost; 173 permissions[2][1] = new SocketPermission (docHost, "resolve"); 174 } else { 175 permissions = basePermissions; 176 } 177 178 EventTarget root = (EventTarget )document.getDocumentElement(); 179 root.addEventListener("SVGLoad", new EventListener () { 180 public void handleEvent(Event evt){ 181 SecurityManager sm = System.getSecurityManager(); 182 int successCnt = 0; 183 Vector unexpectedDenial = new Vector (); 184 int unexpectedDenialCnt = 0; 185 int unexpectedGrantsCnt = 0; 186 187 if (sm == null){ 188 for (int i=0; i<permissions.length; i++) { 189 successCnt++; 190 } 191 } 192 else { 193 for (int i=0; i<permissions.length; i++) { 194 Permission p = (Permission )permissions[i][1]; 195 try { 196 sm.checkPermission(p); 197 successCnt++; 198 } catch (SecurityException se){ 199 unexpectedDenial.add(permissions[i][0]); 200 unexpectedDenialCnt++; 201 } 202 } 203 } 204 205 Element result = document.getElementById("testResult"); 207 if ( successCnt == permissions.length ) { 208 result.setAttributeNS(null, "result", "passed"); 209 } else { 210 System.out.println("test failed: " + unexpectedGrantsCnt + " / " + unexpectedDenialCnt); 211 result.setAttributeNS(null, "result", "failed"); 212 result.setAttributeNS(null, "errorCode", "unexpected.grants.or.denials"); 213 214 String unexpectedDenialString = ""; 215 216 for (int i=0; i<unexpectedDenialCnt; i++) { 217 unexpectedDenialString += unexpectedDenial.elementAt(i).toString(); 218 } 219 220 Element entry = null; 221 222 entry = document.createElementNS(testNS, "errorDescriptiongEntry"); 223 entry.setAttributeNS(null, "id", "unexpected.denials.count"); 224 entry.setAttributeNS(null, "value", "" + unexpectedDenialCnt); 225 result.appendChild(entry); 226 227 System.out.println("unexpected.denials : " + unexpectedDenialString); 228 entry = document.createElementNS(testNS, "errorDescriptionEntry"); 229 entry.setAttributeNS(null, "id", "unexpected.denials"); 230 entry.setAttributeNS(null, "value", unexpectedDenialString); 231 result.appendChild(entry); 232 } 233 } }, false); 234 } 235 } 236 | Popular Tags |