Search in sources :

Example 1 with FreeplaneSecurityManager

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);
    }
}
Also used : LogicalStyleFilterController(org.freeplane.features.styles.LogicalStyleFilterController) FormatController(org.freeplane.features.format.FormatController) FreeplaneSecurityManager(org.freeplane.main.application.FreeplaneSecurityManager) FilterController(org.freeplane.features.filter.FilterController) HelpController(org.freeplane.features.help.HelpController) MapController(org.freeplane.features.map.MapController) LogicalStyleFilterController(org.freeplane.features.styles.LogicalStyleFilterController) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) TextController(org.freeplane.features.text.TextController) ModeController(org.freeplane.features.mode.ModeController) FormatController(org.freeplane.features.format.FormatController) ApplicationResourceController(org.freeplane.main.application.ApplicationResourceController) ModelessAttributeController(org.freeplane.features.attribute.ModelessAttributeController) ResourceController(org.freeplane.core.resources.ResourceController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) ScannerController(org.freeplane.features.format.ScannerController) LinkController(org.freeplane.features.link.LinkController) TimeController(org.freeplane.features.time.TimeController) ScannerController(org.freeplane.features.format.ScannerController)

Example 2 with FreeplaneSecurityManager

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);
    }
}
Also used : Binding(groovy.lang.Binding) PrintStream(java.io.PrintStream) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) FreeplaneSecurityManager(org.freeplane.main.application.FreeplaneSecurityManager)

Example 3 with FreeplaneSecurityManager

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;
}
Also used : FreeplaneSecurityManager(org.freeplane.main.application.FreeplaneSecurityManager)

Example 4 with FreeplaneSecurityManager

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);
    }
}
Also used : PrintStream(java.io.PrintStream) ScriptException(javax.script.ScriptException) SimpleScriptContext(javax.script.SimpleScriptContext) Compilable(javax.script.Compilable) FreeplaneSecurityManager(org.freeplane.main.application.FreeplaneSecurityManager)

Aggregations

FreeplaneSecurityManager (org.freeplane.main.application.FreeplaneSecurityManager)4 PrintStream (java.io.PrintStream)2 Binding (groovy.lang.Binding)1 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)1 Compilable (javax.script.Compilable)1 ScriptException (javax.script.ScriptException)1 SimpleScriptContext (javax.script.SimpleScriptContext)1 ResourceController (org.freeplane.core.resources.ResourceController)1 ModelessAttributeController (org.freeplane.features.attribute.ModelessAttributeController)1 FilterController (org.freeplane.features.filter.FilterController)1 FormatController (org.freeplane.features.format.FormatController)1 ScannerController (org.freeplane.features.format.ScannerController)1 HelpController (org.freeplane.features.help.HelpController)1 IconController (org.freeplane.features.icon.IconController)1 LinkController (org.freeplane.features.link.LinkController)1 MapController (org.freeplane.features.map.MapController)1 Controller (org.freeplane.features.mode.Controller)1 ModeController (org.freeplane.features.mode.ModeController)1 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)1 LogicalStyleFilterController (org.freeplane.features.styles.LogicalStyleFilterController)1