List of usage examples for java.lang Package isSealed
public boolean isSealed()
From source file:Main.java
public static void main(String[] args) { // get the java lang package Package pack = Package.getPackage("java.lang"); // check if this package is sealed System.out.println(pack.isSealed()); }
From source file:com.github.wolf480pl.mias4j.core.runtime.BMClassLoader.java
protected Package copyPackage(Package pkg, CodeSource cs) { return definePackage(pkg.getName(), pkg.getSpecificationTitle(), pkg.getSpecificationVersion(), pkg.getSpecificationVendor(), pkg.getImplementationTitle(), pkg.getImplementationVersion(), pkg.getImplementationVendor(), pkg.isSealed() ? cs.getLocation() : null); }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Loads and verifies the class with name and located with res. *///from w w w . ja va2 s . c om private Class<?> defineClass(final String name, final Resource res) throws IOException { final URL url = res.getCodeSourceURL(); final String pkgName = res.getPackageName(); if (pkgName != null) { final Package pkg = getPackage(pkgName); if (pkg != null) { if (pkg.isSealed()) { if (!pkg.isSealed(url)) { throw new FileSystemException("vfs.impl/pkg-sealed-other-url", pkgName); } } else { if (isSealed(res)) { throw new FileSystemException("vfs.impl/pkg-sealing-unsealed", pkgName); } } } else { definePackage(pkgName, res); } } final byte[] bytes = res.getBytes(); final Certificate[] certs = res.getFileObject().getContent().getCertificates(); final CodeSource cs = new CodeSource(url, certs); return defineClass(name, bytes, 0, bytes.length, cs); }
From source file:org.apache.catalina.loader.WebappClassLoader.java
/** * Find specified class in local repositories. * * @return the loaded class, or null if the class isn't found *//*from ww w . j a v a 2 s .com*/ protected Class findClassInternal(String name) throws ClassNotFoundException { if (!validate(name)) throw new ClassNotFoundException(name); String tempPath = name.replace('.', '/'); String classPath = tempPath + ".class"; ResourceEntry entry = null; entry = findResourceInternal(name, classPath); if ((entry == null) || (entry.binaryContent == null)) throw new ClassNotFoundException(name); Class clazz = entry.loadedClass; if (clazz != null) return clazz; // Looking up the package String packageName = null; int pos = name.lastIndexOf('.'); if (pos != -1) packageName = name.substring(0, pos); Package pkg = null; if (packageName != null) { pkg = getPackage(packageName); // Define the package (if null) if (pkg == null) { if (entry.manifest == null) { definePackage(packageName, null, null, null, null, null, null, null); } else { definePackage(packageName, entry.manifest, entry.codeBase); } } } // Create the code source object CodeSource codeSource = new CodeSource(entry.codeBase, entry.certificates); if (securityManager != null) { // Checking sealing if (pkg != null) { boolean sealCheck = true; if (pkg.isSealed()) { sealCheck = pkg.isSealed(entry.codeBase); } else { sealCheck = (entry.manifest == null) || !isPackageSealed(packageName, entry.manifest); } if (!sealCheck) throw new SecurityException( "Sealing violation loading " + name + " : Package " + packageName + " is sealed."); } } if (entry.loadedClass == null) { synchronized (this) { if (entry.loadedClass == null) { clazz = defineClass(name, entry.binaryContent, 0, entry.binaryContent.length, codeSource); entry.loadedClass = clazz; entry.binaryContent = null; entry.source = null; entry.codeBase = null; entry.manifest = null; entry.certificates = null; } else { clazz = entry.loadedClass; } } } else { clazz = entry.loadedClass; } return clazz; }
From source file:org.echocat.nodoodle.classloading.FileClassLoader.java
private Class<?> defineClass(String name, Resource resource) throws IOException { final int i = name.lastIndexOf('.'); final URL packageUrl = resource.getPackageUrl(); if (i != -1) { final String packageName = name.substring(0, i); // Check if package already loaded. final Package pkg = getPackage(packageName); final Manifest man = resource.getManifest(); if (pkg != null) { // Package found, so check package sealing. if (pkg.isSealed()) { // Verify that code source URL is the same. if (!pkg.isSealed(packageUrl)) { throw new SecurityException("sealing violation: package " + packageName + " is sealed"); }//from w ww. j av a 2 s . c o m } else { // Make sure we are not attempting to seal the package // at this code source URL. if ((man != null) && isSealed(packageName, man)) { throw new SecurityException( "sealing violation: can't seal package " + packageName + ": already loaded"); } } } else { if (man != null) { definePackage(packageName, man, packageUrl); } else { definePackage(packageName, null, null, null, null, null, null, null); } } } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final InputStream inputStream = resource.openStream(); try { IOUtils.copy(inputStream, baos); } finally { IOUtils.closeQuietly(inputStream); } final byte[] bytes = baos.toByteArray(); final CodeSigner[] signers = resource.getCodeSigners(); final CodeSource cs = new CodeSource(packageUrl, signers); return defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(cs, new Permissions())); }