/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.activiti.scripting.secure.behavior;

import org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
import org.activiti.scripting.secure.impl.SecureJavascriptUtil;

/**
 * @author Joram Barrez
 * @author Bassam Al-Sarori
 */
public class SecureJavascriptTaskActivityBehavior extends ScriptTaskActivityBehavior {

    private static final long serialVersionUID = 1L;

    public SecureJavascriptTaskActivityBehavior(String scriptTaskId, String script,
                                            String language, String resultVariable, boolean storeScriptVariables) {
        super(scriptTaskId, script, language, resultVariable, storeScriptVariables);
    }

    @Override
    public void execute(ActivityExecution execution) throws Exception {
      ProcessEngineConfigurationImpl config = (ProcessEngineConfigurationImpl) execution.getEngineServices().getProcessEngineConfiguration();
      SecureJavascriptUtil.evaluateScript(execution, script, config.getBeans());
    }

}

@@ -635,53 +635,208 @@
 ine.
-impl.bpmn.behavior.ScriptTaskActivityBehavior
+ActivitiException;%0Aimport org.activiti.engine.delegate.BpmnError;%0Aimport org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior;%0Aimport org.activiti.engine.impl.bpmn.helper.ErrorPropagation
 ;%0Aim
@@ -1028,16 +1028,131 @@
 iptUtil;
+%0Aimport org.apache.commons.lang3.exception.ExceptionUtils;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -1345,16 +1345,126 @@
 ID = 1L;
+%0A    private static final Logger LOGGER = LoggerFactory.getLogger(SecureJavascriptTaskActivityBehavior.class);
 %0A%0A    pu
@@ -1983,16 +1983,81 @@
 ;%0A      
+%0A      boolean noErrors = true;%0A      try %7B%0A    %09Object result = 
 SecureJa
@@ -2123,16 +2123,617 @@
 ans());%0A
+        if (resultVariable != null) %7B%0A          execution.setVariable(resultVariable, result);%0A        %7D%0A%0A      %7D catch (ActivitiException e) %7B%0A        %0A        LOGGER.warn(%22Exception while executing %22 + execution.getActivity().getId() + %22 : %22 + e.getMessage());%0A        %0A        noErrors = false;%0A        Throwable rootCause = ExceptionUtils.getRootCause(e);%0A        if (rootCause instanceof BpmnError) %7B%0A          ErrorPropagation.propagateError((BpmnError) rootCause, execution);%0A        %7D else %7B%0A          throw e;%0A        %7D%0A      %7D%0A       %0A      if (noErrors) %7B%0A        leave(execution);%0A      %7D%0A
     %7D%0A%0A%7D

fix execution of script task with secure scripting