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;
}
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);
}
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);
}
}
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));
}
}
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;
}
Aggregations