use of org.freeplane.main.application.FreeplaneSecurityManager in project freeplane by freeplane.
the class FreeplaneHeadlessStarter method createController.
public Controller createController() {
try {
Controller controller = new Controller(applicationResourceController);
Controller.setCurrentController(controller);
applicationResourceController.init();
LogUtils.createLogger();
FreeplaneGUIStarter.showSysInfo();
final HeadlessMapViewController mapViewController = new HeadlessMapViewController();
controller.setMapViewManager(mapViewController);
controller.setViewController(new HeadlessUIController(controller, mapViewController, ""));
System.setSecurityManager(new FreeplaneSecurityManager());
FilterController.install();
FormatController.install(new FormatController());
final ScannerController scannerController = new ScannerController();
ScannerController.install(scannerController);
scannerController.addParsersForStandardFormats();
ModelessAttributeController.install();
TextController.install();
TimeController.install();
LinkController.install();
IconController.install();
HelpController.install();
FilterController.getCurrentFilterController().getConditionFactory().addConditionController(70, new LogicalStyleFilterController());
MapController.install();
NodeHistory.install(controller);
return controller;
} catch (final Exception e) {
LogUtils.severe(e);
throw new RuntimeException(e);
}
}
use of org.freeplane.main.application.FreeplaneSecurityManager in project freeplane by freeplane.
the class GroovyScript method execute.
@Override
public Object execute(final NodeModel node) {
try {
if (errorsInScript != null && compileTimeStrategy.canUseOldCompiledScript()) {
throw new ExecuteScriptException(errorsInScript.getMessage(), errorsInScript);
}
final ScriptingSecurityManager scriptingSecurityManager = createScriptingSecurityManager();
final ScriptingPermissions originalScriptingPermissions = new ScriptingPermissions(ResourceController.getResourceController().getProperties());
final FreeplaneSecurityManager securityManager = (FreeplaneSecurityManager) System.getSecurityManager();
final boolean needToSetFinalSecurityManager = securityManager.needToSetFinalSecurityManager();
final PrintStream oldOut = System.out;
try {
compileAndCache();
final Binding binding = createBinding(node);
compiledScript.setBinding(binding);
if (needToSetFinalSecurityManager)
securityManager.setFinalSecurityManager(scriptingSecurityManager);
System.setOut(outStream);
return compiledScript.run();
} finally {
System.setOut(oldOut);
if (needToSetFinalSecurityManager && securityManager.hasFinalSecurityManager())
securityManager.removeFinalSecurityManager(scriptingSecurityManager);
/* restore preferences (and assure that the values are unchanged!). */
originalScriptingPermissions.restorePermissions();
}
} catch (final GroovyRuntimeException e) {
handleScriptRuntimeException(e);
// And if: Shouldn't it raise an ExecuteScriptException?
throw new RuntimeException(e);
} catch (final Throwable e) {
if (Controller.getCurrentController().getSelection() != null)
Controller.getCurrentModeController().getMapController().select(node);
throw new ExecuteScriptException(e.getMessage(), e);
}
}
use of org.freeplane.main.application.FreeplaneSecurityManager in project freeplane by freeplane.
the class ScriptSecurity method getScriptingSecurityManager.
ScriptingSecurityManager getScriptingSecurityManager() {
final FreeplaneSecurityManager securityManager = (FreeplaneSecurityManager) System.getSecurityManager();
final ScriptingSecurityManager scriptingSecurityManager;
// such that the scripts are not able to change them).
if (securityManager.needToSetFinalSecurityManager()) {
final ScriptingPermissions permissions = permissions();
permissions.assertScriptExecutionAllowed();
final boolean executeSignedScripts = permissions.isExecuteSignedScriptsWithoutRestriction();
if (executeSignedScripts && isSignedScript()) {
scriptingSecurityManager = permissions.getPermissiveScriptingSecurityManager();
} else {
scriptingSecurityManager = permissions.getScriptingSecurityManager();
}
} else {
// will not be used
scriptingSecurityManager = null;
}
return scriptingSecurityManager;
}
use of org.freeplane.main.application.FreeplaneSecurityManager in project freeplane by freeplane.
the class GenericScript method execute.
@Override
public Object execute(final NodeModel node) {
try {
if (errorsInScript != null && compileTimeStrategy.canUseOldCompiledScript()) {
throw new ExecuteScriptException(errorsInScript.getMessage(), errorsInScript);
}
final ScriptingSecurityManager scriptingSecurityManager = createScriptingSecurityManager();
final ScriptingPermissions originalScriptingPermissions = new ScriptingPermissions(ResourceController.getResourceController().getProperties());
final FreeplaneSecurityManager securityManager = (FreeplaneSecurityManager) System.getSecurityManager();
final boolean needToSetFinalSecurityManager = securityManager.needToSetFinalSecurityManager();
final PrintStream oldOut = System.out;
try {
final SimpleScriptContext context = createScriptContext(node);
if (compilationEnabled && engine instanceof Compilable) {
compileAndCache((Compilable) engine);
if (needToSetFinalSecurityManager)
securityManager.setFinalSecurityManager(scriptingSecurityManager);
System.setOut(outStream);
return compiledScript.eval(context);
} else {
if (needToSetFinalSecurityManager)
securityManager.setFinalSecurityManager(scriptingSecurityManager);
System.setOut(outStream);
return engine.eval(scriptSource.getScript(), context);
}
} finally {
System.setOut(oldOut);
if (needToSetFinalSecurityManager && securityManager.hasFinalSecurityManager())
securityManager.removeFinalSecurityManager(scriptingSecurityManager);
/* restore preferences (and assure that the values are unchanged!). */
originalScriptingPermissions.restorePermissions();
}
} catch (final ScriptException e) {
handleScriptRuntimeException(e);
// And if: Shouldn't it raise an ExecuteScriptException?
throw new RuntimeException(e);
} catch (final Throwable e) {
if (Controller.getCurrentController().getSelection() != null)
Controller.getCurrentModeController().getMapController().select(node);
throw new ExecuteScriptException(e.getMessage(), e);
}
}
Aggregations