use of java.net.JarURLConnection in project sling by apache.
the class JspCTldLocationsCache method scanJars.
/*
* Scans all JARs accessible to the webapp's classloader and its
* parent classloaders for TLDs.
*
* The list of JARs always includes the JARs under WEB-INF/lib, as well as
* all shared JARs in the classloader delegation chain of the webapp's
* classloader.
*
* Considering JARs in the classloader delegation chain constitutes a
* Tomcat-specific extension to the TLD search
* order defined in the JSP spec. It allows tag libraries packaged as JAR
* files to be shared by web applications by simply dropping them in a
* location that all web applications have access to (e.g.,
* <CATALINA_HOME>/common/lib).
*
* The set of shared JARs to be scanned for TLDs is narrowed down by
* the <tt>noTldJars</tt> class variable, which contains the names of JARs
* that are known not to contain any TLDs.
*/
private void scanJars() throws Exception {
ClassLoader loader = webappLoader;
while (loader != null) {
if (loader instanceof URLClassLoader) {
URL[] urls = ((URLClassLoader) loader).getURLs();
for (URL url : urls) {
URLConnection conn = url.openConnection();
if (conn instanceof JarURLConnection) {
if (needScanJar(loader, webappLoader, ((JarURLConnection) conn).getJarFile().getName())) {
scanJar((JarURLConnection) conn, true);
}
} else {
String urlStr = url.toString();
if (urlStr.startsWith(FILE_PROTOCOL) && urlStr.endsWith(JAR_FILE_SUFFIX) && needScanJar(loader, webappLoader, urlStr)) {
URL jarURL = new URL("jar:" + urlStr + "!/");
scanJar((JarURLConnection) jarURL.openConnection(), true);
}
}
}
}
loader = loader.getParent();
}
}
use of java.net.JarURLConnection in project jdk8u_jdk by JetBrains.
the class AppletPanel method getAccessControlContext.
/**
* get the context for the AppletClassLoader we are creating.
* the context is granted permission to create the class loader,
* connnect to the codebase, and whatever else the policy grants
* to all codebases.
*/
private AccessControlContext getAccessControlContext(final URL codebase) {
PermissionCollection perms = (PermissionCollection) AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
Policy p = java.security.Policy.getPolicy();
if (p != null) {
return p.getPermissions(new CodeSource(null, (java.security.cert.Certificate[]) null));
} else {
return null;
}
}
});
if (perms == null)
perms = new Permissions();
//XXX: this is needed to be able to create the classloader itself!
perms.add(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
Permission p;
java.net.URLConnection urlConnection = null;
try {
urlConnection = codebase.openConnection();
p = urlConnection.getPermission();
} catch (java.io.IOException ioe) {
p = null;
}
if (p != null)
perms.add(p);
if (p instanceof FilePermission) {
String path = p.getName();
int endIndex = path.lastIndexOf(File.separatorChar);
if (endIndex != -1) {
path = path.substring(0, endIndex + 1);
if (path.endsWith(File.separator)) {
path += "-";
}
perms.add(new FilePermission(path, SecurityConstants.FILE_READ_ACTION));
}
} else {
URL locUrl = codebase;
if (urlConnection instanceof JarURLConnection) {
locUrl = ((JarURLConnection) urlConnection).getJarFileURL();
}
String host = locUrl.getHost();
if (host != null && (host.length() > 0))
perms.add(new SocketPermission(host, SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
}
ProtectionDomain domain = new ProtectionDomain(new CodeSource(codebase, (java.security.cert.Certificate[]) null), perms);
AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { domain });
return acc;
}
use of java.net.JarURLConnection in project sling by apache.
the class ClassLoaderResourceProviderChildrenTest method mockClassLoader.
private ClassLoader mockClassLoader(String... paths) throws MalformedURLException, IOException {
final ClassLoader cl = Mockito.mock(ClassLoader.class);
final JarURLConnection conn = Mockito.mock(JarURLConnection.class);
final URLStreamHandler handler = new URLStreamHandler() {
@Override
protected URLConnection openConnection(final URL url) throws IOException {
if (throwExceptionOnOpenConnection) {
throw new IOException("Throwing up for testing that");
}
return conn;
}
};
final JarFile f = Mockito.mock(JarFile.class);
final URL url = new URL("jar://some.jar", "localhost", 1234, "some.jar", handler);
final Vector<JarEntry> entries = new Vector<JarEntry>();
for (String path : paths) {
entries.add(new JarEntry(path));
}
when(cl.getResource(Matchers.contains("install"))).thenReturn(url);
when(conn.getJarFile()).thenReturn(f);
when(f.entries()).thenReturn(entries.elements());
return cl;
}
use of java.net.JarURLConnection in project jPOS by jpos.
the class CLIPrefixedClassNameCompleter method resolveModuleEntriesFromJar.
private static List<String> resolveModuleEntriesFromJar(URL url, String _prefix) throws IOException {
final String prefix = _prefix.endsWith("/") ? _prefix : _prefix + "/";
List<String> resourceList = new ArrayList<String>();
JarURLConnection conn = (JarURLConnection) url.openConnection();
Enumeration entries = conn.getJarFile().entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
if (name.startsWith(prefix) && !name.contains("$") && !entry.isDirectory()) {
name = name.substring(prefix.length()).toLowerCase();
if (!name.contains("/")) {
resourceList.add(name);
}
}
}
return resourceList;
}
use of java.net.JarURLConnection in project jPOS by jpos.
the class ModuleUtils method resolveModuleEntriesFromJar.
private static List<String> resolveModuleEntriesFromJar(URL url, String _prefix) throws IOException {
final String prefix = _prefix.endsWith("/") ? _prefix : _prefix + "/";
List<String> resourceList = new ArrayList<String>();
JarURLConnection conn = (JarURLConnection) url.openConnection();
Enumeration entries = conn.getJarFile().entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry) entries.nextElement();
String name = entry.getName();
if (name.startsWith(prefix) && !entry.isDirectory()) {
resourceList.add(name);
}
}
return resourceList;
}
Aggregations