- BundleContext bundleContext = null;
- try {
- String[] osgiRuntimeArgs = { "-configuration",
- confDir.getCanonicalPath(), "-data",
- dataDir.getCanonicalPath(), "-console", "-clean" };
- bundleContext = EclipseStarter.startup(osgiRuntimeArgs, null);
- } catch (Exception e) {
- throw new RuntimeException("Cannot start Equinox.", e);
- }
-
- // OSGi bootstrap
- OsgiBoot osgiBoot = new OsgiBoot(bundleContext);
- osgiBoot.installUrls(osgiBoot.getBundlesUrls(bundlesToInstall));
-
- if (moduleUrl != null) {
- Bundle bundle = osgiBoot.installUrl(moduleUrl);
- module = bundle.getSymbolicName();
- // TODO deal with version
- }
-
- System.setProperty(UNIQUE_LAUNCH_MODULE_PROPERTY, module);
- System.setProperty(UNIQUE_LAUNCH_FLOW_PROPERTY, flow);
- System.setProperty("log4j.configuration", "file:./log4j.properties");
-
- // start runtime
- osgiBoot.startBundles(bundlesToStart);
-
- // Bundle bundle = (Bundle) osgiBoot.getBundlesBySymbolicName().get(
- // "org.argeo.slc.specs");
- // bundle.loadClass(Execu)
- //
- // // retrieve modulesManager
- // BundlesManager bundlesManager = new
- // BundlesManager(bundleContext);
- // ExecutionModulesManager modulesManager = bundlesManager
- // .getSingleService(ExecutionModulesManager.class, null, true);
- //
- // RealizedFlow realizedFlow = RealizedFlow.create(module, null,
- // flow,
- // null);
- // modulesManager.start(new BasicNameVersion(module, "0.0.0"));
- // modulesManager.execute(realizedFlow);
-
- // osgiBoot.bootstrap();
- // osgiBoot.bootstrap();
-
- // Mode
- // String typeStr = cl.getOptionValue(typeOpt.getOpt());
- // if (typeStr == null) {
- // type = Type.standalone;
- // } else {
- // try {
- // type = Type.valueOf(typeStr);
- // } catch (IllegalArgumentException e) {
- // throw new SlcException("Unrecognized mode '" + typeStr
- // + "'", e);
- // }
- // }
- //
- // // Script
- // if (type.equals(Type.standalone)) {
- // if (!cl.hasOption(moduleOpt.getOpt()))
- // throw new SlcException("Type " + Type.standalone
- // + " requires option '" + moduleOpt.getLongOpt()
- // + "'");
- // module = cl.getOptionValue(moduleOpt.getOpt());
- //
- // // Targets
- // if (cl.hasOption(flowsOpt.getOpt()))
- // flows = cl.getOptionValue(flowsOpt.getOpt());
- // }
- //
- // // Properties
- // if (cl.hasOption(propertiesOpt.getOpt())) {
- // for (String propertyFile : cl.getOptionValues(propertiesOpt
- // .getOpt())) {
- // loadPropertyFile(properties, propertyFile);
- // }
- // }
- // if (cl.hasOption(propertyOpt.getOpt())) {
- // for (String property : cl.getOptionValues(propertyOpt.getOpt()))
- // {
- // addProperty(properties, property);
- // }
- // }
- //
- // // Runtime
- // if (cl.hasOption(runtimeOpt.getOpt())) {
- // urlStr = cl.getOptionValue(runtimeOpt.getOpt());
- // }
- } catch (ParseException e) {
- System.err.println("Problem with command line arguments. "
- + e.getMessage());
- badExit();
- } catch (SlcException e) {
- System.err.println(e.getMessage());
- badExit();
+ File modulesDir = new File(slcDir, "modules");
+
+ // JAAS
+ File jaasFile = new File(confDir, "jaas.config");
+ if (!jaasFile.exists())
+ copyResource("/org/argeo/slc/cli/jaas.config", jaasFile);
+ System.setProperty("java.security.auth.login.config",
+ jaasFile.getCanonicalPath());
+
+ // log4j
+ File log4jFile = new File(confDir, "log4j.properties");
+ if (!log4jFile.exists())
+ copyResource("/org/argeo/slc/cli/log4j.properties", log4jFile);
+ System.setProperty("log4j.configuration",
+ "file://" + log4jFile.getCanonicalPath());
+ // Run as a privileged action
+ LoginContext lc = new LoginContext(os);
+ lc.login();
+
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ Subject.doAs(subject, new SlcMain(args, confDir, dataDir,
+ modulesDir));
+
+ if (args.length != 0)
+ System.exit(0);