use of java.security.CodeSource in project Lucee by lucee.
the class CFMLEngineFactory method deployBundledBundle.
private File deployBundledBundle(File bundleDirectory, String symbolicName, String symbolicVersion) {
String sub = "bundles/";
String nameAndVersion = symbolicName + "|" + symbolicVersion;
String osgiFileName = symbolicName + "-" + symbolicVersion + ".jar";
String pack20Ext = ".pack.gz";
boolean isPack200 = false;
// first we look for a exact match
InputStream is = getClass().getResourceAsStream("bundles/" + osgiFileName);
if (is == null)
is = getClass().getResourceAsStream("/bundles/" + osgiFileName);
if (is != null)
printDate("found /bundles/" + osgiFileName + " in lucee.jar");
else
printDate("could not find /bundles/" + osgiFileName + " in lucee.jar");
if (is == null) {
is = getClass().getResourceAsStream("bundles/" + osgiFileName + pack20Ext);
if (is == null)
is = getClass().getResourceAsStream("/bundles/" + osgiFileName + pack20Ext);
isPack200 = true;
if (is != null)
printDate("found /bundles/" + osgiFileName + pack20Ext + " in lucee.jar");
else
printDate("could not find /bundles/" + osgiFileName + pack20Ext + " in lucee.jar");
}
if (is != null) {
File temp = null;
try {
// copy to temp file
temp = File.createTempFile("bundle", ".tmp");
printDate("copy lucee.jar!/bundles/" + osgiFileName + pack20Ext + " to " + temp);
Util.copy(new BufferedInputStream(is), new FileOutputStream(temp), true, true);
if (isPack200) {
File temp2 = File.createTempFile("bundle", ".tmp2");
Pack200Util.pack2Jar(temp, temp2);
printDate("unpack " + temp + " to " + temp2);
temp.delete();
temp = temp2;
}
// adding bundle
File trg = new File(bundleDirectory, osgiFileName);
temp.renameTo(trg);
printDate("adding bundle [" + symbolicName + "] in version [" + symbolicVersion + "] to [" + trg + "]");
log(Logger.LOG_DEBUG, "adding bundle [" + symbolicName + "] in version [" + symbolicVersion + "] to [" + trg + "]");
return trg;
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
if (temp != null && temp.exists())
temp.delete();
}
}
// this also not works with windows
if (isWindows())
return null;
ZipEntry entry;
File temp;
ZipInputStream zis = null;
try {
CodeSource src = CFMLEngineFactory.class.getProtectionDomain().getCodeSource();
if (src == null)
return null;
URL loc = src.getLocation();
zis = new ZipInputStream(loc.openStream());
String path, name, bundleInfo;
int index;
while ((entry = zis.getNextEntry()) != null) {
temp = null;
path = entry.getName().replace('\\', '/');
// some zip path start with "/" some not
if (path.startsWith("/"))
path = path.substring(1);
isPack200 = false;
if (path.startsWith(sub) && (path.endsWith(".jar"))) {
// ignore non jar files or file from elsewhere
index = path.lastIndexOf('/') + 1;
if (index == sub.length()) {
// ignore sub directories
name = path.substring(index);
temp = null;
try {
temp = File.createTempFile("bundle", ".tmp");
Util.copy(zis, new FileOutputStream(temp), false, true);
/*if(isPack200) {
File temp2 = File.createTempFile("bundle", ".tmp2");
Pack200Util.pack2Jar(temp, temp2);
temp.delete();
temp=temp2;
name=name.substring(0,name.length()-".pack.gz".length());
}*/
bundleInfo = BundleLoader.loadBundleInfo(temp);
if (bundleInfo != null && nameAndVersion.equals(bundleInfo)) {
File trg = new File(bundleDirectory, name);
temp.renameTo(trg);
printDate("adding bundle [ " + symbolicName + " ] in version [ " + symbolicVersion + " ] to [ " + trg + " ]");
log(Logger.LOG_DEBUG, "adding bundle [" + symbolicName + "] in version [" + symbolicVersion + "] to [" + trg + "]");
return trg;
}
} finally {
if (temp != null && temp.exists())
temp.delete();
}
}
}
zis.closeEntry();
}
} catch (Throwable t) {
if (t instanceof ThreadDeath)
throw (ThreadDeath) t;
} finally {
Util.closeEL(zis);
}
return null;
}
use of java.security.CodeSource 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.CodeSource in project drools by kiegroup.
the class PackageCompilationDataTest method testCodeSourceUrl.
@Test
public void testCodeSourceUrl() throws Exception {
final String className = TestEvalExpression.class.getName();
KnowledgeBaseImpl kBase = new KnowledgeBaseImpl("xxx", null);
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.drools");
pkg.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
JavaDialectRuntimeData data = new JavaDialectRuntimeData();
data.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
pkg.getDialectRuntimeRegistry().setDialectData("java", data);
kBase.addPackage(pkg);
final JavaDialectRuntimeData pcData = (JavaDialectRuntimeData) pkg.getDialectRuntimeRegistry().getDialectData("java");
final EvalCondition invoker = new EvalCondition(null);
pcData.putInvoker(className, invoker);
final InputStream is = getClass().getClassLoader().getResourceAsStream(className.replace('.', '/') + ".class");
try {
pcData.write(className.replace('.', '/') + ".class", read(is));
} finally {
is.close();
}
pcData.onAdd(pkg.getDialectRuntimeRegistry(), kBase.getRootClassLoader());
pcData.onBeforeExecute();
Class cls = kBase.getRootClassLoader().loadClass("org.drools.core.rule.PackageCompilationDataTest$TestEvalExpression");
final CodeSource codeSource = invoker.getEvalExpression().getClass().getProtectionDomain().getCodeSource();
assertNotNull(codeSource.getLocation());
}
use of java.security.CodeSource 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;
}
use of java.security.CodeSource in project Payara by payara.
the class SMGlobalPolicyUtil method loadServerPolicy.
private static void loadServerPolicy(PolicyType policyType) throws IOException {
if (policyType == null)
return;
if (logger.isLoggable(Level.FINE)) {
logger.fine("PolicyType= " + policyType);
}
String policyFilename = null;
Map<CommponentType, PermissionCollection> policyMap = null;
switch(policyType) {
case EEGranted:
policyFilename = domainCfgFolder + EE_GRANT_FILE;
policyMap = compTypeToEEGarntsMap;
break;
case EERestricted:
policyFilename = domainCfgFolder + EE_RESTRICTED_FILE;
policyMap = compTypeToEERestrictedMap;
break;
case ServerAllowed:
policyFilename = domainCfgFolder + SERVER_ALLOWED_FILE;
policyMap = compTypeToServAllowedMap;
break;
}
if (policyFilename == null || policyMap == null)
throw new IllegalArgumentException("Unrecognized policy type: " + policyType);
if (logger.isLoggable(Level.FINE)) {
logger.fine("policyFilename= " + policyFilename);
}
File f = new File(policyFilename);
if (!f.exists())
return;
URL furl = new URL("file:" + policyFilename);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loading policy from " + furl);
}
PolicyFile pf = new PolicyFile(furl);
CodeSource cs = new CodeSource(new URL(EJB_TYPE_CODESOURCE), (Certificate[]) null);
PermissionCollection pc = pf.getPermissions(cs);
policyMap.put(CommponentType.ejb, pc);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded EJB policy = " + pc);
}
cs = new CodeSource(new URL(WEB_TYPE_CODESOURCE), (Certificate[]) null);
pc = pf.getPermissions(cs);
policyMap.put(CommponentType.war, pc);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded WEB policy =" + pc);
}
cs = new CodeSource(new URL(RAR_TYPE_CODESOURCE), (Certificate[]) null);
pc = pf.getPermissions(cs);
policyMap.put(CommponentType.rar, pc);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded rar policy =" + pc);
}
cs = new CodeSource(new URL(CLIENT_TYPE_CODESOURCE), (Certificate[]) null);
pc = pf.getPermissions(cs);
policyMap.put(CommponentType.car, pc);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded car policy =" + pc);
}
cs = new CodeSource(new URL(EAR_TYPE_CODESOURCE), (Certificate[]) null);
pc = pf.getPermissions(cs);
policyMap.put(CommponentType.ear, pc);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Loaded ear policy =" + pc);
}
}
Aggregations