1 18 package org.apache.batik.bridge; 19 20 import org.apache.batik.util.ParsedURL; 21 22 30 public class DefaultExternalResourceSecurity implements ExternalResourceSecurity { 31 public static final String DATA_PROTOCOL = "data"; 32 36 public static final String ERROR_CANNOT_ACCESS_DOCUMENT_URL 37 = "DefaultExternalResourceSecurity.error.cannot.access.document.url"; 38 39 43 public static final String ERROR_EXTERNAL_RESOURCE_FROM_DIFFERENT_URL 44 = "DefaultExternalResourceSecurity.error.external.resource.from.different.url"; 45 46 50 protected SecurityException se; 51 52 57 public void checkLoadExternalResource(){ 58 if (se != null) { 59 se.fillInStackTrace(); 60 throw se; 61 } 62 } 63 64 72 public DefaultExternalResourceSecurity(ParsedURL externalResourceURL, 73 ParsedURL docURL){ 74 if (docURL == null) { 77 se = new SecurityException 78 (Messages.formatMessage(ERROR_CANNOT_ACCESS_DOCUMENT_URL, 79 new Object []{externalResourceURL})); 80 } else { 81 String docHost = docURL.getHost(); 82 String externalResourceHost = externalResourceURL.getHost(); 83 84 if ((docHost != externalResourceHost) && 85 ((docHost == null) || (!docHost.equals(externalResourceHost)))){ 86 87 if ( externalResourceURL == null 88 || 89 !DATA_PROTOCOL.equals(externalResourceURL.getProtocol()) ) { 90 se = new SecurityException 91 (Messages.formatMessage(ERROR_EXTERNAL_RESOURCE_FROM_DIFFERENT_URL, 92 new Object []{externalResourceURL})); 93 } 94 95 } 96 } 97 } 98 } 99 100 101 102 | Popular Tags |