From 40463fbf0025582b07de4e70f60fab7ae2aeb800 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Thu, 20 Sep 2007 14:36:07 +0000 Subject: [PATCH] Fix AR-1765 WebScripts clear authentication before commiting transaction git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6843 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/scripts/WebScriptRuntime.java | 86 +++++++++++-------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/source/java/org/alfresco/web/scripts/WebScriptRuntime.java b/source/java/org/alfresco/web/scripts/WebScriptRuntime.java index e6c4246a5c..a921c429b2 100644 --- a/source/java/org/alfresco/web/scripts/WebScriptRuntime.java +++ b/source/java/org/alfresco/web/scripts/WebScriptRuntime.java @@ -145,39 +145,9 @@ public abstract class WebScriptRuntime logger.debug("Format style: " + desc.getFormatStyle() + ", Default format: " + desc.getDefaultFormat()); logger.debug("Invoking Web Script " + description.getId() + (user == null ? " (unauthenticated)" : " (authenticated as " + user + ") (format " + format + ") (" + locale + ")")); } - - if (description.getRequiredTransaction() == RequiredTransaction.none) - { - authenticatedExecute(scriptReq, scriptRes); - } - else - { - // encapsulate script within transaction - RetryingTransactionCallback work = new RetryingTransactionCallback() - { - public Object execute() throws Exception - { - if (logger.isDebugEnabled()) - logger.debug("Begin transaction: " + description.getRequiredTransaction()); - - authenticatedExecute(scriptReq, scriptRes); - - if (logger.isDebugEnabled()) - logger.debug("End transaction: " + description.getRequiredTransaction()); - - return null; - } - }; - - if (description.getRequiredTransaction() == RequiredTransaction.required) - { - retryingTransactionHelper.doInTransaction(work); - } - else - { - retryingTransactionHelper.doInTransaction(work, false, true); - } - } + + // execute script within required level of authentication + authenticatedExecute(scriptReq, scriptRes); } finally { @@ -277,7 +247,7 @@ public abstract class WebScriptRuntime if (required == RequiredAuthentication.none) { - wrappedExecute(scriptReq, scriptRes); + transactionedExecute(scriptReq, scriptRes); } else if ((required == RequiredAuthentication.user || required == RequiredAuthentication.admin) && isGuest) { @@ -311,7 +281,7 @@ public abstract class WebScriptRuntime } // Execute Web Script - wrappedExecute(scriptReq, scriptRes); + transactionedExecute(scriptReq, scriptRes); } } finally @@ -330,6 +300,52 @@ public abstract class WebScriptRuntime } } } + + /** + * Execute script within required level of transaction + * + * @param scriptReq + * @param scriptRes + * @throws IOException + */ + protected void transactionedExecute(final WebScriptRequest scriptReq, final WebScriptResponse scriptRes) + throws IOException + { + final WebScript script = scriptReq.getServiceMatch().getWebScript(); + final WebScriptDescription description = script.getDescription(); + if (description.getRequiredTransaction() == RequiredTransaction.none) + { + wrappedExecute(scriptReq, scriptRes); + } + else + { + // encapsulate script within transaction + RetryingTransactionCallback work = new RetryingTransactionCallback() + { + public Object execute() throws Exception + { + if (logger.isDebugEnabled()) + logger.debug("Begin transaction: " + description.getRequiredTransaction()); + + wrappedExecute(scriptReq, scriptRes); + + if (logger.isDebugEnabled()) + logger.debug("End transaction: " + description.getRequiredTransaction()); + + return null; + } + }; + + if (description.getRequiredTransaction() == RequiredTransaction.required) + { + retryingTransactionHelper.doInTransaction(work); + } + else + { + retryingTransactionHelper.doInTransaction(work, false, true); + } + } + } /** * Execute Web Script with pre & post hooks