use of java.security.ProtectionDomain in project ignite by apache.
the class IgniteUtils method resolveProjectHome.
/**
* Resolve project home directory based on source code base.
*
* @return Project home directory (or {@code null} if it cannot be resolved).
*/
@Nullable
private static String resolveProjectHome() {
assert Thread.holdsLock(IgniteUtils.class);
// Resolve Ignite home via environment variables.
String ggHome0 = IgniteSystemProperties.getString(IGNITE_HOME);
if (!F.isEmpty(ggHome0))
return ggHome0;
String appWorkDir = System.getProperty("user.dir");
if (appWorkDir != null) {
ggHome0 = findProjectHome(new File(appWorkDir));
if (ggHome0 != null)
return ggHome0;
}
URI classesUri;
Class<IgniteUtils> cls = IgniteUtils.class;
try {
ProtectionDomain domain = cls.getProtectionDomain();
// Should not happen, but to make sure our code is not broken.
if (domain == null || domain.getCodeSource() == null || domain.getCodeSource().getLocation() == null) {
logResolveFailed(cls, null);
return null;
}
// Resolve path to class-file.
classesUri = domain.getCodeSource().getLocation().toURI();
// Overcome UNC path problem on Windows (http://www.tomergabel.com/JavaMishandlesUNCPathsOnWindows.aspx)
if (isWindows() && classesUri.getAuthority() != null)
classesUri = new URI(classesUri.toString().replace("file://", "file:/"));
} catch (URISyntaxException | SecurityException e) {
logResolveFailed(cls, e);
return null;
}
File classesFile;
try {
classesFile = new File(classesUri);
} catch (IllegalArgumentException e) {
logResolveFailed(cls, e);
return null;
}
return findProjectHome(classesFile);
}
use of java.security.ProtectionDomain in project rt.equinox.framework by eclipse.
the class EclipseStarter method getSysPathFromCodeSource.
private static String getSysPathFromCodeSource() {
ProtectionDomain pd = EclipseStarter.class.getProtectionDomain();
if (pd == null)
return null;
CodeSource cs = pd.getCodeSource();
if (cs == null)
return null;
URL url = cs.getLocation();
if (url == null)
return null;
String result = url.getPath();
if (File.separatorChar == '\\') {
// in case on windows the \ is used
result = result.replace('\\', '/');
}
if (result.endsWith(".jar")) {
// $NON-NLS-1$
result = result.substring(0, result.lastIndexOf('/'));
if (// $NON-NLS-1$
"folder".equals(getProperty(PROP_FRAMEWORK_SHAPE)))
result = result.substring(0, result.lastIndexOf('/'));
} else {
if (// $NON-NLS-1$
result.endsWith("/"))
result = result.substring(0, result.length() - 1);
result = result.substring(0, result.lastIndexOf('/'));
result = result.substring(0, result.lastIndexOf('/'));
}
return result;
}
use of java.security.ProtectionDomain in project rt.equinox.framework by eclipse.
the class EquinoxContainerAdaptor method invalidateWiring.
@Override
public void invalidateWiring(ModuleWiring moduleWiring, ModuleLoader current) {
if (current instanceof BundleLoader) {
BundleLoader bundleLoader = (BundleLoader) current;
bundleLoader.close();
}
long updatedTimestamp = storage.getModuleDatabase().getRevisionsTimestamp();
if (System.getSecurityManager() != null && updatedTimestamp != lastSecurityAdminFlush.getAndSet(updatedTimestamp)) {
storage.getSecurityAdmin().clearCaches();
List<Module> modules = storage.getModuleContainer().getModules();
for (Module module : modules) {
for (ModuleRevision revision : module.getRevisions().getModuleRevisions()) {
Generation generation = (Generation) revision.getRevisionInfo();
if (generation != null) {
ProtectionDomain domain = generation.getDomain();
if (domain != null) {
((BundlePermissions) domain.getPermissions()).clearPermissionCache();
}
}
}
}
}
clearManifestCache(moduleWiring);
}
use of java.security.ProtectionDomain in project Payara by payara.
the class ACCClassLoader method copyClass.
private Class<?> copyClass(final Class c) throws ClassNotFoundException {
final String name = c.getName();
final ProtectionDomain pd = c.getProtectionDomain();
byte[] bytecode = readByteCode(name);
for (ClassFileTransformer xf : transformers) {
try {
bytecode = xf.transform(this, name, null, pd, bytecode);
} catch (IllegalClassFormatException ex) {
throw new ClassNotFoundException(name, ex);
}
}
return defineClass(name, bytecode, 0, bytecode.length, pd);
}
use of java.security.ProtectionDomain in project Payara by payara.
the class SecurityContextUtil method authorizeCORBA.
// return true if authorization succeeds, false otherwise.
private boolean authorizeCORBA(byte[] object_id, String method) throws Exception {
// Check if target is an EJB
ProtocolManager protocolMgr = orbHelper.getProtocolManager();
// is on a callback object in the client VM.
if (protocolMgr == null) {
return true;
}
if (protocolMgr.getEjbDescriptor(object_id) != null) {
// an EJB object
return true;
}
CORBAObjectPermission perm = new CORBAObjectPermission("*", method);
// Create a ProtectionDomain for principal on current thread.
com.sun.enterprise.security.SecurityContext sc = com.sun.enterprise.security.SecurityContext.getCurrent();
Set principalSet = sc.getPrincipalSet();
Principal[] principals = (principalSet == null ? null : (Principal[]) principalSet.toArray(new Principal[principalSet.size()]));
CodeSource cs = new CodeSource(new java.net.URL("file://"), (java.security.cert.Certificate[]) null);
ProtectionDomain prdm = new ProtectionDomain(cs, null, null, principals);
// Check if policy gives principal the permissions
boolean result = policy.implies(prdm, perm);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "CORBA Object permission evaluation result=" + result + " for method=" + method);
}
return result;
}
Aggregations