use of java.security.ProtectionDomain in project blade by biezhi.
the class AbstractClassGenerator method generate.
protected Class generate(ClassLoaderData data) {
Class gen;
Object save = CURRENT.get();
CURRENT.set(this);
try {
ClassLoader classLoader = data.getClassLoader();
if (classLoader == null) {
throw new IllegalStateException("ClassLoader is null while trying to define class " + getClassName() + ". It seems that the loader has been expired from a weak reference somehow. " + "Please file an issue at cglib's issue tracker.");
}
synchronized (classLoader) {
String name = generateClassName(data.getUniqueNamePredicate());
data.reserveName(name);
this.setClassName(name);
}
if (attemptLoad) {
try {
gen = classLoader.loadClass(getClassName());
return gen;
} catch (ClassNotFoundException e) {
// ignore
}
}
byte[] b = strategy.generate(this);
String className = ClassNameReader.getClassName(new ClassReader(b));
ProtectionDomain protectionDomain = getProtectionDomain();
synchronized (classLoader) {
// just in case
if (protectionDomain == null) {
gen = ReflectUtils.defineClass(className, b, classLoader);
} else {
gen = ReflectUtils.defineClass(className, b, classLoader, protectionDomain);
}
}
return gen;
} catch (RuntimeException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Exception e) {
throw new CodeGenerationException(e);
} finally {
CURRENT.set(save);
}
}
use of java.security.ProtectionDomain in project jetty.project by eclipse.
the class WebAppClassLoaderTest method testNullClassFileTransformer.
@Test
public void testNullClassFileTransformer() throws Exception {
_loader.addTransformer(new ClassFileTransformer() {
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
return null;
}
});
assertCanLoadClass("org.acme.webapp.ClassInJarA");
}
use of java.security.ProtectionDomain in project flyway by flyway.
the class ClassUtils method getLocationOnDisk.
/**
* Retrieves the physical location on disk of this class.
*
* @param aClass The class to get the location for.
* @return The absolute path of the .class file.
*/
public static String getLocationOnDisk(Class<?> aClass) {
try {
ProtectionDomain protectionDomain = aClass.getProtectionDomain();
if (protectionDomain == null) {
//Android
return null;
}
CodeSource codeSource = protectionDomain.getCodeSource();
if (codeSource == null) {
//Custom classloader with for example classes defined using URLClassLoader#defineClass(String name, byte[] b, int off, int len)
return null;
}
String url = codeSource.getLocation().getPath();
return URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
//Can never happen.
return null;
}
}
use of java.security.ProtectionDomain in project gitblit by gitblit.
the class Launcher method main.
public static void main(String[] args) {
if (DEBUG) {
System.out.println("jcp=" + System.getProperty("java.class.path"));
ProtectionDomain protectionDomain = Launcher.class.getProtectionDomain();
System.out.println("launcher=" + protectionDomain.getCodeSource().getLocation().toExternalForm());
}
// Load the JARs in the lib and ext folder
String[] folders = new String[] { "lib", "ext" };
List<File> jars = new ArrayList<File>();
for (String folder : folders) {
if (folder == null) {
continue;
}
File libFolder = new File(folder);
if (!libFolder.exists()) {
continue;
}
List<File> found = findJars(libFolder.getAbsoluteFile());
jars.addAll(found);
}
// sort the jars by name and then reverse the order so the newer version
// of the library gets loaded in the event that this is an upgrade
Collections.sort(jars);
Collections.reverse(jars);
if (jars.size() == 0) {
for (String folder : folders) {
File libFolder = new File(folder);
// this is a test of adding a comment
// more really interesting things
System.err.println("Failed to find any JARs in " + libFolder.getPath());
}
System.exit(-1);
} else {
for (File jar : jars) {
try {
jar.canRead();
addJarFile(jar);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
// Start Server
GitBlitServer.main(args);
}
use of java.security.ProtectionDomain in project elasticsearch by elastic.
the class ESPolicyUnitTests method testListen.
public void testListen() {
assumeTrue("test cannot run with security manager", System.getSecurityManager() == null);
final PermissionCollection noPermissions = new Permissions();
final ESPolicy policy = new ESPolicy(noPermissions, Collections.emptyMap(), true);
assertFalse(policy.implies(new ProtectionDomain(ESPolicyUnitTests.class.getProtectionDomain().getCodeSource(), noPermissions), new SocketPermission("localhost:" + randomFrom(0, randomIntBetween(49152, 65535)), "listen")));
}
Aggregations