use of java.security.ProtectionDomain in project jdk8u_jdk by JetBrains.
the class MBeanInstantiator method getClassLoader.
private ClassLoader getClassLoader(final ObjectName name) {
if (clr == null) {
return null;
}
// Restrict to getClassLoader permission only
Permissions permissions = new Permissions();
permissions.add(new MBeanPermission("*", null, name, "getClassLoader"));
ProtectionDomain protectionDomain = new ProtectionDomain(null, permissions);
ProtectionDomain[] domains = { protectionDomain };
AccessControlContext ctx = new AccessControlContext(domains);
ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
return clr.getClassLoader(name);
}
}, ctx);
return loader;
}
use of java.security.ProtectionDomain in project stanbol by apache.
the class Main method main.
/**
* @param args
*/
public static void main(String[] args) {
String home = System.getProperties().getProperty(SLING_HOME);
if (home == null) {
home = new File(DEFAULT_STANBOL_HOME).getAbsolutePath();
System.setProperty(SLING_HOME, home);
}
//else do not override user configured values
List<String> argsList = new ArrayList<String>(Arrays.asList(args));
if (argsList.contains(PRINTHELPARG)) {
doHelp();
System.exit(0);
}
if (argsList.contains(NOSECURITYARG)) {
argsList.remove(NOSECURITYARG);
} else {
args = argsList.toArray(new String[argsList.size()]);
Policy.setPolicy(new Policy() {
@Override
public PermissionCollection getPermissions(ProtectionDomain domain) {
PermissionCollection result = new Permissions();
result.add(new AllPermission());
return result;
}
});
System.setSecurityManager(new SecurityManager());
}
//now use the standard Apache Sling launcher to do the job
org.apache.sling.launchpad.app.Main.main(argsList.toArray(new String[argsList.size()]));
}
use of java.security.ProtectionDomain 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.ProtectionDomain in project wcomponents by BorderTech.
the class DefaultInternalConfiguration method getDebuggingInfo.
/**
* @return debugging information for logging on application start-up.
*/
protected String getDebuggingInfo() {
final String paramsFile = "log4j.appender.PARAMS.File";
File cwd = new File(".");
String workingDir;
try {
workingDir = cwd.getCanonicalPath();
} catch (IOException ex) {
workingDir = "UNKNOWN";
}
String codesourceStr = "";
// Try to be sneaky and print the codesource location (for orientation of user)
try {
ProtectionDomain domain = getClass().getProtectionDomain();
CodeSource codesource = null;
if (domain != null) {
codesource = domain.getCodeSource();
}
codesourceStr = (codesource != null ? " code location of ParamImpl: " + codesource.getLocation() : "");
} catch (Throwable failed) {
// Okay
}
StringBuffer info = new StringBuffer();
info.append("----Parameters start----");
info.append(codesourceStr);
info.append("\nWorking directory is ");
info.append(workingDir);
info.append("\nParameters have loaded, there is a full parameter dump in log4j FILE appender at ");
info.append(get(paramsFile));
info.append("\nTo dump all params to stdout set ");
info.append(DUMP);
info.append(" to true; currently value is ");
info.append(get(DUMP));
info.append("\n----Parameters end------");
return info.toString();
}
use of java.security.ProtectionDomain in project jPOS by jpos.
the class Slf4JDynamicBinder method applyMods.
public static void applyMods() throws Exception {
if (!bound && !bindingsExist()) {
final ProtectionDomain pd = Slf4JDynamicBinder.class.getProtectionDomain();
final ClassPool cp = ClassPool.getDefault();
CtClass clz = cp.getAndRename(StaticLoggerBinder.class.getName(), STATIC_BINDER_CLASS);
clz.toClass(null, pd);
CtClass clz2 = cp.get("org.slf4j.LoggerFactory");
CtMethod bindMethod = clz2.getDeclaredMethod("bind");
bindMethod.setBody("try " + "{" + " org.slf4j.impl.StaticLoggerBinder.getSingleton();" + " INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;" + " fixSubstituteLoggers();" + " replayEvents();" + " SUBST_FACTORY.clear();" + "} " + "catch(Exception e)" + "{" + " failedBinding(e); " + " throw new IllegalStateException(\"Unexpected initialization failure\", e);" + "}");
clz2.toClass(null, pd);
clz2.detach();
clz.detach();
bound = true;
}
}
Aggregations