1 17 18 package org.apache.jasper.servlet; 19 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.net.URL ; 23 import java.net.URLClassLoader ; 24 import java.security.CodeSource ; 25 import java.security.PermissionCollection ; 26 27 import org.apache.jasper.Constants; 28 29 37 public class JasperLoader extends URLClassLoader { 38 39 private PermissionCollection permissionCollection; 40 private CodeSource codeSource; 41 private String className; 42 private ClassLoader parent; 43 private SecurityManager securityManager; 44 45 public JasperLoader(URL [] urls, ClassLoader parent, 46 PermissionCollection permissionCollection, 47 CodeSource codeSource) { 48 super(urls, parent); 49 this.permissionCollection = permissionCollection; 50 this.codeSource = codeSource; 51 this.parent = parent; 52 this.securityManager = System.getSecurityManager(); 53 } 54 55 64 public Class loadClass(String name) throws ClassNotFoundException { 65 66 return (loadClass(name, false)); 67 } 68 69 94 public Class loadClass(final String name, boolean resolve) 95 throws ClassNotFoundException { 96 97 Class clazz = null; 98 99 clazz = findLoadedClass(name); 101 if (clazz != null) { 102 if (resolve) 103 resolveClass(clazz); 104 return (clazz); 105 } 106 107 if (securityManager != null) { 109 int dot = name.lastIndexOf('.'); 110 if (dot >= 0) { 111 try { 112 if (!"org.apache.jasper.runtime".equalsIgnoreCase(name.substring(0,dot))){ 114 securityManager.checkPackageAccess(name.substring(0,dot)); 115 } 116 } catch (SecurityException se) { 117 String error = "Security Violation, attempt to use " + 118 "Restricted Class: " + name; 119 se.printStackTrace(); 120 throw new ClassNotFoundException (error); 121 } 122 } 123 } 124 125 if( !name.startsWith(Constants.JSP_PACKAGE_NAME) ) { 126 clazz = parent.loadClass(name); 129 if( resolve ) 130 resolveClass(clazz); 131 return clazz; 132 } 133 134 return findClass(name); 135 } 136 137 138 143 public InputStream getResourceAsStream(String name) { 144 InputStream is = parent.getResourceAsStream(name); 145 if (is == null) { 146 URL url = findResource(name); 147 if (url != null) { 148 try { 149 is = url.openStream(); 150 } catch (IOException e) { 151 is = null; 152 } 153 } 154 } 155 return is; 156 } 157 158 159 169 public final PermissionCollection getPermissions(CodeSource codeSource) { 170 return permissionCollection; 171 } 172 } 173 | Popular Tags |