use of java.security.CodeSource in project jdk8u_jdk by JetBrains.
the class DGCImplInsulation method main.
public static void main(String[] args) throws Exception {
TestLibrary.suggestSecurityManager(null);
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);
impl = null;
System.gc();
if (refQueue.remove(TIMEOUT) == weakRef) {
throw new RuntimeException("TEST FAILED: remote object garbage collected");
} else {
System.err.println("TEST PASSED");
stub = null;
System.gc();
Thread.sleep(2000);
System.gc();
}
} finally {
try {
UnicastRemoteObject.unexportObject(impl, true);
} catch (Exception e) {
}
}
}
use of java.security.CodeSource in project ArsMagica2 by Mithion.
the class SpellTextureHelper method getResourceListing.
public static List<String> getResourceListing() throws IOException, URISyntaxException {
CodeSource src = AMCore.class.getProtectionDomain().getCodeSource();
ArrayList<String> toReturn = new ArrayList<String>();
if (src != null) {
URL jar = src.getLocation();
if (jar.getProtocol() == "jar") {
String path = jar.toString().replace("jar:", "").replace("file:", "").replace("!/am2/AMCore.class", "").replace('/', File.separatorChar);
path = URLDecoder.decode(path, "UTF-8");
LogHelper.debug(path);
JarFile jarFile = new JarFile(path);
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().startsWith("assets/arsmagica2/textures/items/spells/icons/")) {
String name = entry.getName().replace("assets/arsmagica2/textures/items/spells/icons/", "");
if (name.equals(""))
continue;
toReturn.add("spells/icons/" + name.replace(".png", ""));
}
}
jarFile.close();
} else if (jar.getProtocol() == "file") {
String path = jar.toURI().toString().replace("/am2/AMCore.class", iconsPath).replace("file:/", "").replace("%20", " ").replace("/", "\\");
File file = new File(path);
if (file.exists() && file.isDirectory()) {
for (File sub : file.listFiles()) {
toReturn.add(iconsPrefix + sub.getName().replace(".png", ""));
}
}
}
return toReturn;
} else {
return toReturn;
}
}
use of java.security.CodeSource in project OpenAM by OpenRock.
the class ISPermission method equals.
/**
* Returns true if two <code>ISPermission</code> objects for equality.
*
* @param obj <code>ISPermission</code> object.
* @return true if subject, <code>codesource</code>, service name, resource
* name actions and environment parameters of both objects are
* equal.
*/
public boolean equals(Object obj) {
boolean result = true;
debug.message("ISPermission:: equals(Object) called ");
if (obj == this) {
if (debug.messageEnabled()) {
debug.message("ISPermission::equals::this " + result);
}
return true;
}
if (obj instanceof ISPermission) {
ISPermission perm = (ISPermission) obj;
Subject subject = perm.getSubject();
if (subject != null) {
result = subject.equals(this.subject);
} else {
if (this.subject != null) {
// subject is null, while this.subject is
result = false;
// not null.
}
}
if (debug.messageEnabled()) {
debug.message("ISPermission::subject equals:" + result);
}
if (result) {
CodeSource codesource = perm.getCodeSource();
if (codesource != null) {
result = codesource.equals(this.codesource);
if (debug.messageEnabled()) {
debug.message("ISPermission::codesource equals:" + codesource.equals(this.codesource));
}
} else {
if (this.codesource != null) {
result = false;
}
}
}
if (result) {
ProtectionDomain protectionDomain = perm.getProtectionDomain();
if (protectionDomain != null) {
result = protectionDomain.equals(this.protectionDomain);
if (debug.messageEnabled()) {
debug.message("ISPermission::protectionDomain equals:" + protectionDomain.equals(this.protectionDomain));
}
} else {
if (this.protectionDomain != null) {
result = false;
}
}
}
if (result) {
String serviceName = perm.getServiceName();
if (serviceName != null) {
result = serviceName.equals(this.serviceName);
if (debug.messageEnabled()) {
debug.message("ISPermission::servicename equals:" + serviceName.equals(this.serviceName));
}
} else {
if (this.serviceName != null) {
result = false;
}
}
}
if (result) {
String resourceName = perm.getResourceName();
if (resourceName != null) {
result = resourceName.equals(this.resourceName);
if (debug.messageEnabled()) {
debug.message("ISPermission::resourceName equals:" + resourceName.equals(this.resourceName));
}
} else {
if (this.resourceName != null) {
result = false;
}
}
}
if (result) {
String actions = perm.getActions();
if (actions != null) {
result = actionEquals(actions, this.actions);
if (debug.messageEnabled()) {
debug.message("ISPermission::Actions equals:" + actionEquals(actions, this.actions));
}
} else {
if (this.actions != null) {
result = false;
}
}
}
if (result) {
Map envParams = perm.getEnvParams();
if (envParams != null && !envParams.isEmpty()) {
result = envParams.equals(this.envParams);
if (debug.messageEnabled()) {
debug.message("ISPermission::equals::envMap" + envParams.equals(this.envParams));
}
} else {
if (this.envParams != null && !this.envParams.isEmpty()) {
result = false;
}
}
}
}
if (debug.messageEnabled()) {
debug.message("ISPermission::equals::returning " + result);
}
return result;
}
use of java.security.CodeSource in project yyl_example by Relucent.
the class ClassPath method getClassLocationURL.
/**
* 获取类的class文件位置的URL。这个方法是本类最基础的方法,供其它方法调用。
*/
private static URL getClassLocationURL(final Class<?> cls) {
if (cls == null)
throw new IllegalArgumentException("null input: cls");
URL result = null;
final String clsAsResource = cls.getName().replace('.', '/').concat(".class");
final ProtectionDomain pd = cls.getProtectionDomain();
if (pd != null) {
final CodeSource cs = pd.getCodeSource();
if (cs != null)
result = cs.getLocation();
if (result != null) {
if ("file".equals(result.getProtocol())) {
try {
if (result.toExternalForm().endsWith(".jar") || result.toExternalForm().endsWith(".zip"))
result = new URL("jar:".concat(result.toExternalForm()).concat("!/").concat(clsAsResource));
else if (new File(result.getFile()).isDirectory())
result = new URL(result, clsAsResource);
} catch (MalformedURLException ignore) {
}
}
}
}
if (result == null) {
final ClassLoader clsLoader = cls.getClassLoader();
result = clsLoader != null ? clsLoader.getResource(clsAsResource) : ClassLoader.getSystemResource(clsAsResource);
}
return result;
}
use of java.security.CodeSource in project intellij-community by JetBrains.
the class CompactSyntaxLexerAdapter method getSourceLocation.
private static String getSourceLocation(Class<?> clazz) {
final CodeSource source = clazz.getProtectionDomain().getCodeSource();
if (source != null) {
final URL location = source.getLocation();
if (location != null) {
return location.toExternalForm();
}
}
final String name = clazz.getName().replace('.', '/') + ".class";
final ClassLoader loader = clazz.getClassLoader();
final URL resource = loader != null ? loader.getResource(name) : ClassLoader.getSystemResource(name);
return resource != null ? resource.toExternalForm() : "<unknown>";
}
Aggregations