use of java.security.CodeSource in project jdk8u_jdk by JetBrains.
the class ClassLoading method run.
/**
* Repeatedly load a class not found in classpath through RMIClassLoader.
* Arguments: <# reps>
*/
public long run(String[] args) throws Exception {
int reps = Integer.parseInt(args[0]);
CodeSource csrc = getClass().getProtectionDomain().getCodeSource();
String url = "jar:" + csrc.getLocation().toString() + ALTROOT;
long start = System.currentTimeMillis();
for (int i = 0; i < reps; i++) RMIClassLoader.loadClass(url, CLASSNAME);
long time = System.currentTimeMillis() - start;
return time;
}
use of java.security.CodeSource in project jdk8u_jdk by JetBrains.
the class Implies method testImplies.
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");
}
}
use of java.security.CodeSource in project jdk8u_jdk by JetBrains.
the class NotificationInfoTest method main.
public static void main(String[] args) throws Exception {
System.out.println("Checking that all known MBeans that are " + "NotificationBroadcasters have sane " + "MBeanInfo.getNotifications()");
System.out.println("Checking platform MBeans...");
checkPlatformMBeans();
CodeSource cs = javax.management.MBeanServer.class.getProtectionDomain().getCodeSource();
URL codeBase;
if (cs == null) {
String javaHome = System.getProperty("java.home");
String[] candidates = { "/lib/rt.jar", "/classes/" };
codeBase = null;
for (String candidate : candidates) {
File file = new File(javaHome + candidate);
if (file.exists()) {
codeBase = file.toURI().toURL();
break;
}
}
if (codeBase == null) {
throw new Exception("Could not determine codeBase for java.home=" + javaHome);
}
} else
codeBase = cs.getLocation();
System.out.println();
System.out.println("Looking for standard MBeans...");
String[] classes = findStandardMBeans(codeBase);
System.out.println("Testing standard MBeans...");
for (int i = 0; i < classes.length; i++) {
String name = classes[i];
Class<?> c;
try {
c = Class.forName(name);
} catch (Throwable e) {
System.out.println(name + ": cannot load (not public?): " + e);
continue;
}
if (!NotificationBroadcaster.class.isAssignableFrom(c)) {
System.out.println(name + ": not a NotificationBroadcaster");
continue;
}
if (Modifier.isAbstract(c.getModifiers())) {
System.out.println(name + ": abstract class");
continue;
}
NotificationBroadcaster mbean;
Constructor<?> constr;
try {
constr = c.getConstructor();
} catch (Exception e) {
System.out.println(name + ": no public no-arg constructor: " + e);
continue;
}
try {
mbean = (NotificationBroadcaster) constr.newInstance();
} catch (Exception e) {
System.out.println(name + ": no-arg constructor failed: " + e);
continue;
}
check(mbean);
}
System.out.println();
System.out.println("Testing some explicit cases...");
check(new RelationService(false));
/*
We can't do this:
check(new RequiredModelMBean());
because the Model MBean spec more or less forces us to use the
names GENERIC and ATTRIBUTE_CHANGE for its standard notifs.
*/
checkRMIConnectorServer();
System.out.println();
if (!suspicious.isEmpty())
System.out.println("SUSPICIOUS CLASSES: " + suspicious);
if (failed.isEmpty())
System.out.println("TEST PASSED");
else {
System.out.println("TEST FAILED: " + failed);
System.exit(1);
}
}
use of java.security.CodeSource in project apex-core by apache.
the class JarHelper method getJar.
public String getJar(Class<?> jarClass) {
String jar = null;
final CodeSource codeSource = jarClass.getProtectionDomain().getCodeSource();
if (codeSource != null) {
URL location = codeSource.getLocation();
jar = sourceToJar.get(location);
if (jar == null) {
// don't create jar file from folders multiple times
if ("jar".equals(location.getProtocol())) {
try {
location = ((JarURLConnection) location.openConnection()).getJarFileURL();
} catch (IOException e) {
throw new AssertionError("Cannot resolve jar file for " + jarClass, e);
}
}
if ("file".equals(location.getProtocol())) {
jar = location.getFile();
final File dir = new File(jar);
if (dir.isDirectory()) {
try {
jar = createJar("apex-", dir, false);
} catch (IOException e) {
throw new AssertionError("Cannot resolve jar file for " + jarClass + ". URL " + location, e);
}
}
} else {
throw new AssertionError("Cannot resolve jar file for " + jarClass + ". URL " + location);
}
sourceToJar.put(location, jar);
logger.debug("added sourceLocation {} as {}", location, jar);
}
if (jar == null) {
throw new AssertionError("Cannot resolve jar file for " + jarClass);
}
}
return jar;
}
use of java.security.CodeSource in project tdme by andreasdr.
the class StandardFileSystem method list.
/*
* (non-Javadoc)
* @see net.drewke.tdme.os.FileSystemInterface#listFiles(java.lang.String, java.io.FilenameFilter)
*/
public String[] list(String path, FilenameFilter filter) throws IOException {
ArrayList<String> files = new ArrayList<String>();
// list files in file system
String[] fileSystemFiles = new File(path).list(filter);
if (fileSystemFiles != null) {
for (String fileName : fileSystemFiles) {
files.add(fileName);
}
}
// list file in associated jar from calling class
try {
// we only support unix style path names in jar files
path = path.replace('\\', '/');
//
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
CodeSource src = Class.forName(stackTraceElements[2].getClassName()).getProtectionDomain().getCodeSource();
if (src != null) {
URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
while (true) {
ZipEntry e = zip.getNextEntry();
if (e == null)
break;
String name = e.getName();
if (name.startsWith(path)) {
String fileName = name.substring(path.length() + 1);
if (filter.accept(new File(path), fileName))
files.add(fileName);
}
}
}
} catch (ClassNotFoundException cnfe) {
//
}
// remove duplicate entries
ArrayList<String> filesNoDuplicates = new ArrayList<String>();
for (String file : files) {
boolean duplicate = false;
for (String _file : filesNoDuplicates) {
if (file.equals(_file)) {
duplicate = true;
break;
}
}
if (duplicate == false)
filesNoDuplicates.add(file);
}
//
String[] _files = new String[filesNoDuplicates.size()];
filesNoDuplicates.toArray(_files);
return _files;
}
Aggregations