35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
package java.net; |
package java.net; |
40 |
|
|
41 |
import java.io.ByteArrayOutputStream; |
import java.io.ByteArrayOutputStream; |
60 |
import java.util.jar.JarFile; |
import java.util.jar.JarFile; |
61 |
import java.util.jar.Manifest; |
import java.util.jar.Manifest; |
62 |
|
|
|
|
|
63 |
/** |
/** |
64 |
* A secure class loader that can load classes and resources from |
* A secure class loader that can load classes and resources from |
65 |
* multiple locations. Given an array of <code>URL</code>s this class |
* multiple locations. Given an array of <code>URL</code>s this class |
656 |
if (loader == null) |
if (loader == null) |
657 |
{ |
{ |
658 |
String file = newUrl.getFile(); |
String file = newUrl.getFile(); |
659 |
|
String protocol = newUrl.getProtocol(); |
660 |
|
|
661 |
// Check that it is not a directory |
// Check that it is not a directory |
662 |
if (! (file.endsWith("/") || file.endsWith(File.separator))) |
if (! (file.endsWith("/") || file.endsWith(File.separator))) |
663 |
loader = new JarURLLoader(this, newUrl); |
loader = new JarURLLoader(this, newUrl); |
664 |
else if ("file".equals(newUrl.getProtocol())) |
else if ("file".equals(protocol)) |
665 |
loader = new FileURLLoader(this, newUrl); |
loader = new FileURLLoader(this, newUrl); |
666 |
else |
else |
667 |
loader = new RemoteURLLoader(this, newUrl); |
loader = new RemoteURLLoader(this, newUrl); |
812 |
// And finally construct the class! |
// And finally construct the class! |
813 |
SecurityManager sm = System.getSecurityManager(); |
SecurityManager sm = System.getSecurityManager(); |
814 |
if (sm != null && securityContext != null) |
if (sm != null && securityContext != null) |
815 |
return (Class) AccessController.doPrivileged(new PrivilegedAction() |
{ |
816 |
{ |
return (Class)AccessController.doPrivileged |
817 |
public Object run() |
(new PrivilegedAction() |
818 |
{ |
{ |
819 |
return defineClass(className, classData, 0, |
public Object run() |
820 |
classData.length, source); |
{ |
821 |
} |
return defineClass(className, classData, |
822 |
}, securityContext); |
0, classData.length, |
823 |
|
source); |
824 |
|
} |
825 |
|
}, securityContext); |
826 |
|
} |
827 |
else |
else |
828 |
return defineClass(className, classData, 0, classData.length, source); |
return defineClass(className, classData, 0, classData.length, source); |
829 |
} |
} |
960 |
|
|
961 |
// If the file end in / it must be an directory. |
// If the file end in / it must be an directory. |
962 |
if (file.endsWith("/") || file.endsWith(File.separator)) |
if (file.endsWith("/") || file.endsWith(File.separator)) |
963 |
// Grant permission to read everything in that directory and |
{ |
964 |
// all subdirectories. |
// Grant permission to read everything in that directory and |
965 |
permissions.add(new FilePermission(file + "-", "read")); |
// all subdirectories. |
966 |
|
permissions.add(new FilePermission(file + "-", "read")); |
967 |
|
} |
968 |
else |
else |
969 |
// It is a 'normal' file. |
{ |
970 |
// Grant permission to access that file. |
// It is a 'normal' file. |
971 |
permissions.add(new FilePermission(file, "read")); |
// Grant permission to access that file. |
972 |
|
permissions.add(new FilePermission(file, "read")); |
973 |
|
} |
974 |
} |
} |
975 |
else |
else |
976 |
{ |
{ |