Java 8 CodeSource - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 CodeSource class.

This code example shows how to use the following methods:getLocation
                        URL url = null;
                        ProtectionDomain pd = provider.getClass().getProtectionDomain();
                        if (pd != null) {
                            CodeSource cs = pd.getCodeSource();
                            if (cs != null) {
                                url = cs.getLocation();
                            } 
                        } 
                        return url;
                    } 
                }); 
                log.debug("Provider code base: " + url);
            } 
 
            Cipher.getInstance("DummyAlg/DummyMode/DummyPadding", "DP");
 
            response.getWriter().write("ok");
            response.getWriter().close();
 
        } catch (Exception e) {
7
CodeRank
This code example shows how to use the following methods:getCertificates, getCodeSigners, getLocation
        } 
        return cs.implies(normalizeCodeSource(codeSource));
    } 
 
    private CodeSource normalizeCodeSource(CodeSource codeSource) {
        URL codeSourceURL = PolicyUtils.normalizeURL(codeSource.getLocation());
        CodeSource result = codeSource;
 
        if (codeSourceURL != codeSource.getLocation()) {
            // URL was normalized - recreate codeSource with new URL 
            CodeSigner[] signers = codeSource.getCodeSigners();
            if (signers == null) {
                result = new CodeSource(codeSourceURL, codeSource
                        .getCertificates());
            } else { 
                result = new CodeSource(codeSourceURL, signers);
            } 
        } 
        return result;
    } 
6
CodeRank
This code example shows how to use the following methods:
 
    public static void main(String[] args) throws Exception {
        String userDir = System.getProperty("user.dir");
        String jarURL = "jar:file:" + userDir + File.separator + "foo.jar!/";
        URL codeSourceURL = new URL(jarURL);
        CodeSource cs = new CodeSource(codeSourceURL, new Certificate[0]);
        PermissionCollection perms = Policy.getPolicy().getPermissions(cs);
        if (!perms.implies(new AllPermission()))
            throw new Exception("FAILED: " + codeSourceURL
                                + " not granted AllPermission"); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:implies
 
    private static void testImplies(URL thisURL, URL thatURL, boolean result)
        throws SecurityException 
    { 
        CodeSource thisCs =
            new CodeSource(thisURL, (java.security.cert.Certificate[]) null);
        CodeSource thatCs =
            new CodeSource(thatURL, (java.security.cert.Certificate[]) null);
 
        if (thisCs.implies(thatCs) != result) {
            throw new SecurityException("test failed");
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:sleep
        Permissions perms = new Permissions();
        perms.add(new SocketPermission("*:1024-", "listen"));
        AccessControlContext acc =
            new AccessControlContext(new ProtectionDomain[] {
                new ProtectionDomain(
                    new CodeSource(null, (Certificate[]) null), perms) });
 
        Remote impl = new DGCImplInsulation();;
 
        try { 
            Remote stub = (Remote) java.security.AccessController.doPrivileged(
                new ExportAction(impl));
            System.err.println("exported remote object; local stub: " + stub);
 
            MarshalledObject mobj = new MarshalledObject(stub);
            stub = (Remote) mobj.get();
            System.err.println("marshalled/unmarshalled stub: " + stub);
 
            ReferenceQueue refQueue = new ReferenceQueue();
            Reference weakRef = new WeakReference(impl, refQueue);

6
CodeRank
This code example shows how to use the following methods:
public class ProtectionDomainUtil { 
  private static ProtectionDomain defaultDomain = null; 
 
  public static ProtectionDomain loadedClassDomain() { 
    if (defaultDomain == null) { 
      CodeSource cs = new CodeSource(null, (Certificate[]) null); 
      defaultDomain = new ProtectionDomain(cs, null); 
    } 
    return defaultDomain; 
  } 
} 
6
CodeRank
This code example shows how to use the following methods:
        assertFalse(loader.load("scrypt", true));
    } 
 
    protected JarLibraryLoader jarLibraryLoader(String name) throws Exception {
        URL url = getClass().getResource("/" + name + ".jar");
        return new JarLibraryLoader(new CodeSource(url, codeSigners()), "lib");
    } 
 
    protected CodeSigner[] codeSigners() throws Exception {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        InputStream is = getClass().getResourceAsStream("/lambdaWorks.p7");
        CertPath certPath = cf.generateCertPath(is, "PKCS7");
        is.close();
        return new CodeSigner[] { new CodeSigner(certPath, null) };
    } 
} 
5
CodeRank
This code example shows how to use the following methods:getLocation
    public ClasspathSource(Name id, CodeSource cs, String baseAssetsPath, String baseOverridesPath, String baseDeltasPath) {
        if (cs == null) {
            throw new IllegalStateException("Can't access assets: CodeSource is null");
        } 
 
        URL url = cs.getLocation();
 
        try { 
            Path codePath = Paths.get(url.toURI());
            if (Files.isRegularFile(codePath)) {
                source = new ArchiveSource(id, codePath.toFile(), baseAssetsPath, baseOverridesPath, baseDeltasPath);
            } else { 
                source = new DirectorySource(id, codePath.resolve(baseAssetsPath), codePath.resolve(baseOverridesPath), codePath.resolve(baseDeltasPath));
            } 
        } catch (Throwable e) {
            throw new IllegalStateException("Error loading assets: " + e.getMessage(), e);
        } 
    } 
 
    @Override 
5
CodeRank
This code example shows how to use the following methods:getCertificates, getCodeSigners, getLocation
		} 
		return cs.implies(normalizeCodeSource(codeSource));
	} 
 
	private CodeSource normalizeCodeSource(CodeSource codeSource) {
		URL codeSourceURL = PolicyUtils.normalizeURL(codeSource.getLocation());
		CodeSource result = codeSource;
 
		if (codeSourceURL != codeSource.getLocation()) {
			// URL was normalized - recreate codeSource with new URL 
			CodeSigner[] signers = codeSource.getCodeSigners();
			if (signers == null) {
				result = new CodeSource(codeSourceURL,
						codeSource.getCertificates());
			} else { 
				result = new CodeSource(codeSourceURL, signers);
			} 
		} 
		return result;
	} 
5
CodeRank
This code example shows how to use the following methods:getCertificates, getCodeSigners, getLocation
		return permissions == null || permissions.size() == 0;
	} 
 
	private CodeSource normalizeCodeSource(CodeSource codeSource) {
		final URL codeSourceURL = PolicyUtils.normalizeURL(codeSource
				.getLocation());
		CodeSource result = codeSource;
 
		if (codeSourceURL != codeSource.getLocation()) {
			// URL was normalized - recreate codeSource with new URL 
			final CodeSigner[] signers = codeSource.getCodeSigners();
			if (signers == null) {
				result = new CodeSource(codeSourceURL,
						codeSource.getCertificates());
			} else { 
				result = new CodeSource(codeSourceURL, signers);
			} 
		} 
		return result;
	} 
5
CodeRank
See Code Examples for Java 8 CodeSource Methods: