Search in sources :

Example 31 with CodeSource

use of java.security.CodeSource in project wildfly by wildfly.

the class SecurityHelper method getSecurityContextForJNDILookup.

private static AccessControlContext getSecurityContextForJNDILookup(Collection<JndiPermission> jndiPermissions) {
    CodeSource src = new CodeSource(null, (Certificate[]) null);
    Permissions perms = new Permissions();
    for (JndiPermission p : jndiPermissions) {
        perms.add(p);
    }
    ProtectionDomain domain = new ProtectionDomain(src, perms);
    AccessControlContext ctx = new AccessControlContext(new ProtectionDomain[] { domain });
    return ctx;
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) Permissions(java.security.Permissions) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) CodeSource(java.security.CodeSource) Certificate(java.security.cert.Certificate)

Example 32 with CodeSource

use of java.security.CodeSource in project robovm by robovm.

the class SecureClassLoaderTest method testGetPermissions.

public void testGetPermissions() throws Exception {
    URL url = new URL("http://localhost");
    CodeSource cs = new CodeSource(url, (Certificate[]) null);
    MyClassLoader ldr = new MyClassLoader();
    ldr.getPerms(null);
    ldr.getPerms(cs);
}
Also used : CodeSource(java.security.CodeSource) URL(java.net.URL) Certificate(java.security.cert.Certificate)

Example 33 with CodeSource

use of java.security.CodeSource in project streamsx.topology by IBMStreams.

the class DependencyResolver method addJarDependency.

public void addJarDependency(BOperatorInvocation op, Class<?> clazz) {
    CodeSource thisCodeSource = this.getClass().getProtectionDomain().getCodeSource();
    CodeSource source = clazz.getProtectionDomain().getCodeSource();
    if (null == source || thisCodeSource.equals(source)) {
        return;
    }
    Path absolutePath = null;
    try {
        absolutePath = Paths.get(source.getLocation().toURI()).toAbsolutePath();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    if (operatorToJarDependencies.containsKey(op)) {
        operatorToJarDependencies.get(op).add(absolutePath);
    } else {
        operatorToJarDependencies.put(op, new HashSet<Path>());
        operatorToJarDependencies.get(op).add(absolutePath);
    }
}
Also used : Path(java.nio.file.Path) URISyntaxException(java.net.URISyntaxException) CodeSource(java.security.CodeSource)

Example 34 with CodeSource

use of java.security.CodeSource in project jdk8u_jdk by JetBrains.

the class PolicyPermissions method getCodeSource.

/**
     * Given a PermissionEntry, create a codeSource.
     *
     * @return null if signedBy alias is not recognized
     */
CodeSource getCodeSource(GrantEntry ge, KeyStore keyStore) throws java.net.MalformedURLException {
    Certificate[] certs = null;
    if (ge.signedBy != null) {
        certs = getCertificates(keyStore, ge.signedBy);
        if (certs == null) {
            // just return
            if (debug != null) {
                debug.println(" no certs for alias " + ge.signedBy + ", ignoring.");
            }
            return null;
        }
    }
    URL location;
    if (ge.codeBase != null) {
        location = new URL(ge.codeBase);
    } else {
        location = null;
    }
    if (ge.principals == null || ge.principals.size() == 0) {
        return (canonicalizeCodebase(new CodeSource(location, certs), false));
    } else {
        return (canonicalizeCodebase(new SubjectCodeSource(null, ge.principals, location, certs), false));
    }
}
Also used : CodeSource(java.security.CodeSource) URL(java.net.URL) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 35 with CodeSource

use of java.security.CodeSource in project jdk8u_jdk by JetBrains.

the class PolicyPermissions method canonicalizeCodebase.

private CodeSource canonicalizeCodebase(CodeSource cs, boolean extractSignerCerts) {
    CodeSource canonCs = cs;
    if (cs.getLocation() != null && cs.getLocation().getProtocol().equalsIgnoreCase("file")) {
        try {
            String path = cs.getLocation().getFile().replace('/', File.separatorChar);
            URL csUrl = null;
            if (path.endsWith("*")) {
                // remove trailing '*' because it causes canonicalization
                // to fail on win32
                path = path.substring(0, path.length() - 1);
                boolean appendFileSep = false;
                if (path.endsWith(File.separator)) {
                    appendFileSep = true;
                }
                if (path.equals("")) {
                    path = System.getProperty("user.dir");
                }
                File f = new File(path);
                path = f.getCanonicalPath();
                StringBuffer sb = new StringBuffer(path);
                // separator, so we have to check for that, too)
                if (!path.endsWith(File.separator) && (appendFileSep || f.isDirectory())) {
                    sb.append(File.separatorChar);
                }
                sb.append('*');
                path = sb.toString();
            } else {
                path = new File(path).getCanonicalPath();
            }
            csUrl = new File(path).toURL();
            if (cs instanceof SubjectCodeSource) {
                SubjectCodeSource scs = (SubjectCodeSource) cs;
                if (extractSignerCerts) {
                    canonCs = new SubjectCodeSource(scs.getSubject(), scs.getPrincipals(), csUrl, getSignerCertificates(scs));
                } else {
                    canonCs = new SubjectCodeSource(scs.getSubject(), scs.getPrincipals(), csUrl, scs.getCertificates());
                }
            } else {
                if (extractSignerCerts) {
                    canonCs = new CodeSource(csUrl, getSignerCertificates(cs));
                } else {
                    canonCs = new CodeSource(csUrl, cs.getCertificates());
                }
            }
        } catch (IOException ioe) {
            // signer certificates
            if (extractSignerCerts) {
                if (!(cs instanceof SubjectCodeSource)) {
                    canonCs = new CodeSource(cs.getLocation(), getSignerCertificates(cs));
                } else {
                    SubjectCodeSource scs = (SubjectCodeSource) cs;
                    canonCs = new SubjectCodeSource(scs.getSubject(), scs.getPrincipals(), scs.getLocation(), getSignerCertificates(scs));
                }
            }
        }
    } else {
        if (extractSignerCerts) {
            if (!(cs instanceof SubjectCodeSource)) {
                canonCs = new CodeSource(cs.getLocation(), getSignerCertificates(cs));
            } else {
                SubjectCodeSource scs = (SubjectCodeSource) cs;
                canonCs = new SubjectCodeSource(scs.getSubject(), scs.getPrincipals(), scs.getLocation(), getSignerCertificates(scs));
            }
        }
    }
    return canonCs;
}
Also used : CodeSource(java.security.CodeSource) URL(java.net.URL)

Aggregations

CodeSource (java.security.CodeSource)104 URL (java.net.URL)49 ProtectionDomain (java.security.ProtectionDomain)39 File (java.io.File)30 IOException (java.io.IOException)20 Certificate (java.security.cert.Certificate)17 JarFile (java.util.jar.JarFile)13 PermissionCollection (java.security.PermissionCollection)12 URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11 Permissions (java.security.Permissions)11 Policy (java.security.Policy)10 FilePermission (java.io.FilePermission)7 InputStream (java.io.InputStream)6 AccessControlContext (java.security.AccessControlContext)6 MalformedURLException (java.net.MalformedURLException)5 Permission (java.security.Permission)4 JarEntry (java.util.jar.JarEntry)4 GroovyClassLoader (groovy.lang.GroovyClassLoader)3 URLClassLoader (java.net.URLClassLoader)3