mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Coding standards and consistency sweep across new services code in repository project.
Covers spacing, trailing {, @since tags, tabs and copyright headers. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30211 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -109,99 +109,108 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
}
|
||||
}
|
||||
|
||||
private Object executeExpression(String expression, ExecutionContext executionContext, List<VariableAccess> variableAccesses) {
|
||||
boolean userChanged = checkFullyAuthenticatedUser(executionContext);
|
||||
Object result = executeScript(expression, executionContext, variableAccesses);
|
||||
if(userChanged)
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object executeScript(String expression,
|
||||
ExecutionContext executionContext,
|
||||
List<VariableAccess> variableAccesses)
|
||||
{
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (runas == null && user !=null)
|
||||
{
|
||||
return executeScript(executionContext, services, expression, variableAccesses, companyHome);
|
||||
}
|
||||
else
|
||||
private Object executeExpression(String expression, ExecutionContext executionContext, List<VariableAccess> variableAccesses)
|
||||
{
|
||||
boolean userChanged = checkFullyAuthenticatedUser(executionContext);
|
||||
Object result = executeScript(expression, executionContext, variableAccesses);
|
||||
if(userChanged)
|
||||
{
|
||||
String runAsUser = runas;
|
||||
if(runAsUser == null)
|
||||
{
|
||||
runAsUser = AuthenticationUtil.getSystemUserName();
|
||||
} else
|
||||
{
|
||||
validateRunAsUser();
|
||||
}
|
||||
return executeScriptAs(runAsUser, expression, executionContext, variableAccesses);
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object executeScriptAs(String runAsUser,
|
||||
final String expression,
|
||||
final ExecutionContext executionContext,
|
||||
final List<VariableAccess> variableAccesses) {
|
||||
// execute as specified runAsUser
|
||||
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
return executeScript(executionContext, services, expression, variableAccesses,companyHome);
|
||||
}
|
||||
}, runAsUser);
|
||||
}
|
||||
private Object executeScript(String expression,
|
||||
ExecutionContext executionContext,
|
||||
List<VariableAccess> variableAccesses)
|
||||
{
|
||||
String user = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (runas == null && user !=null)
|
||||
{
|
||||
return executeScript(executionContext, services, expression, variableAccesses, companyHome);
|
||||
}
|
||||
else
|
||||
{
|
||||
String runAsUser = runas;
|
||||
if(runAsUser == null)
|
||||
{
|
||||
runAsUser = AuthenticationUtil.getSystemUserName();
|
||||
}
|
||||
else
|
||||
{
|
||||
validateRunAsUser();
|
||||
}
|
||||
return executeScriptAs(runAsUser, expression, executionContext, variableAccesses);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a valid Fully Authenticated User is set.
|
||||
* If none is set then attempts to set the task assignee as the Fully Authenticated User.
|
||||
* @param executionContext
|
||||
* @return <code>true</code> if the Fully Authenticated User was changes, otherwise <code>false</code>.
|
||||
*/
|
||||
private boolean checkFullyAuthenticatedUser(final ExecutionContext executionContext) {
|
||||
if(AuthenticationUtil.getFullyAuthenticatedUser()!= null)
|
||||
return false;
|
||||
TaskInstance taskInstance = executionContext.getTaskInstance();
|
||||
if(taskInstance!=null)
|
||||
{
|
||||
String userName = taskInstance.getActorId();
|
||||
if (userName != null)
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private Object executeScriptAs(String runAsUser,
|
||||
final String expression,
|
||||
final ExecutionContext executionContext,
|
||||
final List<VariableAccess> variableAccesses)
|
||||
{
|
||||
// execute as specified runAsUser
|
||||
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>()
|
||||
{
|
||||
public Object doWork() throws Exception
|
||||
{
|
||||
return executeScript(executionContext, services, expression, variableAccesses,companyHome);
|
||||
}
|
||||
}, runAsUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified 'runas' field
|
||||
* specifies a valid username.
|
||||
*/
|
||||
private void validateRunAsUser() {
|
||||
Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>()
|
||||
{ // Validate using System user to ensure sufficient permissions available to access person node.
|
||||
|
||||
public Boolean doWork() throws Exception {
|
||||
return services.getPersonService().personExists(runas);
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
if (!runAsExists)
|
||||
{
|
||||
throw new WorkflowException("runas user '" + runas + "' does not exist.");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks a valid Fully Authenticated User is set.
|
||||
* If none is set then attempts to set the task assignee as the Fully Authenticated User.
|
||||
* @param executionContext
|
||||
* @return <code>true</code> if the Fully Authenticated User was changes, otherwise <code>false</code>.
|
||||
*/
|
||||
private boolean checkFullyAuthenticatedUser(final ExecutionContext executionContext)
|
||||
{
|
||||
if(AuthenticationUtil.getFullyAuthenticatedUser()!= null)
|
||||
return false;
|
||||
|
||||
TaskInstance taskInstance = executionContext.getTaskInstance();
|
||||
if(taskInstance!=null)
|
||||
{
|
||||
String userName = taskInstance.getActorId();
|
||||
if (userName != null)
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(userName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the specified 'runas' field
|
||||
* specifies a valid username.
|
||||
*/
|
||||
private void validateRunAsUser()
|
||||
{
|
||||
Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>()
|
||||
{
|
||||
// Validate using System user to ensure sufficient permissions available to access person node.
|
||||
|
||||
public Boolean doWork() throws Exception
|
||||
{
|
||||
return services.getPersonService().personExists(runas);
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
if (!runAsExists)
|
||||
{
|
||||
throw new WorkflowException("runas user '" + runas + "' does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the expression {@link String} from the script.
|
||||
* @param isTextOnly Is the script text only or is it XML?
|
||||
* @return the expression {@link String}.
|
||||
*/
|
||||
private String getExpression(boolean isTextOnly) {
|
||||
private String getExpression(boolean isTextOnly)
|
||||
{
|
||||
if (isTextOnly)
|
||||
{
|
||||
return script.getText().trim();
|
||||
@@ -215,26 +224,28 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
}
|
||||
return expressionElement.getText().trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<VariableAccess> getVariableAccessors(boolean isTextOnly) {
|
||||
if(isTextOnly)
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<VariableAccess> getVariableAccessors(boolean isTextOnly)
|
||||
{
|
||||
if (isTextOnly)
|
||||
{
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return jpdlReader.readVariableAccesses(script);
|
||||
return jpdlReader.readVariableAccesses(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the script specified as text only, or as explicit expression, variable elements
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean isScriptOnlyText() {
|
||||
@SuppressWarnings("unchecked")
|
||||
private boolean isScriptOnlyText()
|
||||
{
|
||||
Iterator<Element> iter = script.elementIterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
@@ -244,8 +255,8 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -358,7 +369,7 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
inputMap.put("executionContext", executionContext);
|
||||
inputMap.put("token", token);
|
||||
Node node = executionContext.getNode();
|
||||
if (node != null)
|
||||
if (node != null)
|
||||
{
|
||||
inputMap.put("node", node);
|
||||
}
|
||||
@@ -368,7 +379,7 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
inputMap.put("task", task);
|
||||
}
|
||||
TaskInstance taskInstance = executionContext.getTaskInstance();
|
||||
if (taskInstance != null)
|
||||
if (taskInstance != null)
|
||||
{
|
||||
inputMap.put("taskInstance", taskInstance);
|
||||
}
|
||||
@@ -408,16 +419,16 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
}
|
||||
|
||||
|
||||
private static NodeRef getPersonNode(ServiceRegistry services) {
|
||||
String userName = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if(userName != null)
|
||||
{
|
||||
NodeRef person = services.getPersonService().getPerson(userName);
|
||||
return person;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static NodeRef getPersonNode(ServiceRegistry services)
|
||||
{
|
||||
String userName = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (userName != null)
|
||||
{
|
||||
NodeRef person = services.getPersonService().getPerson(userName);
|
||||
return person;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are variables to read from the process context
|
||||
@@ -467,12 +478,13 @@ public class AlfrescoJavaScript extends JBPMSpringActionHandler
|
||||
return writable;
|
||||
}
|
||||
|
||||
public void setScript(Element script) {
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
public void setRunas(String runas) {
|
||||
this.runas = runas;
|
||||
}
|
||||
public void setScript(Element script)
|
||||
{
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
public void setRunas(String runas)
|
||||
{
|
||||
this.runas = runas;
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.workflow.jbpm;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -39,123 +57,127 @@ import org.mockito.stubbing.Answer;
|
||||
|
||||
public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
private static final QName fooName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Foo");
|
||||
private static final QName barName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Bar");
|
||||
private static final QName docName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Doc");
|
||||
private static final String BASIC_USER = "basic"+GUID.generate();
|
||||
private static String systemUser = AuthenticationUtil.getSystemUserName();
|
||||
|
||||
private ServiceRegistry services;
|
||||
private ExecutionContext context;
|
||||
private HashMap<String, Object> variables;
|
||||
private PersonService personService;
|
||||
private static final QName fooName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Foo");
|
||||
private static final QName barName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Bar");
|
||||
private static final QName docName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "Doc");
|
||||
private static final String BASIC_USER = "basic"+GUID.generate();
|
||||
private static String systemUser = AuthenticationUtil.getSystemUserName();
|
||||
|
||||
private ServiceRegistry services;
|
||||
private ExecutionContext context;
|
||||
private HashMap<String, Object> variables;
|
||||
private PersonService personService;
|
||||
private Repository repository;
|
||||
|
||||
/**
|
||||
* Test that JavaScript can still be run even if no Authentication is provided.
|
||||
* This can occur if, e.g. the action is executed as part of an asynchronous task.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunsWithoutAuthentication() throws Exception {
|
||||
NodeRef systemNode = personService.getPerson(systemUser);
|
||||
NodeRef baseUserNode = personService.getPerson(BASIC_USER);
|
||||
TestUserStore userStore = new TestUserStore();
|
||||
variables.put("userStore", userStore);
|
||||
Element script = buildScript("userStore.storeUsers(person)");
|
||||
|
||||
// Check authentication cleared.
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
|
||||
// Check uses system user when no authentication set and no task assignee.
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(systemUser, userStore.runAsUser);
|
||||
assertEquals(systemUser, userStore.fullUser);
|
||||
assertEquals(systemNode, userStore.person.getNodeRef());
|
||||
/**
|
||||
* Test that JavaScript can still be run even if no Authentication is provided.
|
||||
* This can occur if, e.g. the action is executed as part of an asynchronous task.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunsWithoutAuthentication() throws Exception
|
||||
{
|
||||
NodeRef systemNode = personService.getPerson(systemUser);
|
||||
NodeRef baseUserNode = personService.getPerson(BASIC_USER);
|
||||
TestUserStore userStore = new TestUserStore();
|
||||
variables.put("userStore", userStore);
|
||||
Element script = buildScript("userStore.storeUsers(person)");
|
||||
|
||||
// Check authentication cleared.
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
|
||||
// Check uses system user when no authentication set and no task assignee.
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(systemUser, userStore.runAsUser);
|
||||
assertEquals(systemUser, userStore.fullUser);
|
||||
assertEquals(systemNode, userStore.person.getNodeRef());
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
|
||||
// Check that when a task assignee exists, then he/she is used for authentication.
|
||||
TaskInstance taskInstance = mock(TaskInstance.class);
|
||||
when(taskInstance.getActorId()).thenReturn(BASIC_USER);
|
||||
when(context.getTaskInstance()).thenReturn(taskInstance);
|
||||
scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(BASIC_USER, userStore.runAsUser);
|
||||
assertEquals(BASIC_USER, userStore.fullUser);
|
||||
assertEquals(baseUserNode, userStore.person.getNodeRef());
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
/**
|
||||
* See Jira issue ALF-657.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContent() throws Exception
|
||||
{
|
||||
NodeRef fooFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
fooName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef barFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
barName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef doc = nodeService.createNode(fooFolder,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
docName,
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
PermissionService permissions = services.getPermissionService();
|
||||
permissions.setPermission(doc, BASIC_USER, PermissionService.ALL_PERMISSIONS, true);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
|
||||
Element script = buildScript("doc.move(bar)");
|
||||
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
variables.put("bar", new JBPMNode(barFolder, services));
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to bar!");
|
||||
}
|
||||
catch (ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(barFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* See Jira issue ALF-5346.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContentBetweenSites() throws Exception
|
||||
{
|
||||
SiteService siteService = services.getSiteService();
|
||||
FileFolderService fileFolderService = services.getFileFolderService();
|
||||
|
||||
// Check that when a task assignee exists, then he/she is used for authentication.
|
||||
TaskInstance taskInstance = mock(TaskInstance.class);
|
||||
when(taskInstance.getActorId()).thenReturn(BASIC_USER);
|
||||
when(context.getTaskInstance()).thenReturn(taskInstance);
|
||||
scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(BASIC_USER, userStore.runAsUser);
|
||||
assertEquals(BASIC_USER, userStore.fullUser);
|
||||
assertEquals(baseUserNode, userStore.person.getNodeRef());
|
||||
|
||||
// Check authentication is correctly reset.
|
||||
assertNull(AuthenticationUtil.getFullyAuthenticatedUser());
|
||||
assertNull(AuthenticationUtil.getRunAsUser());
|
||||
}
|
||||
|
||||
/**
|
||||
* See Jira issue ALF-657.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContent() throws Exception {
|
||||
NodeRef fooFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
fooName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef barFolder = nodeService.createNode(rootNodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
barName,
|
||||
ContentModel.TYPE_FOLDER).getChildRef();
|
||||
|
||||
NodeRef doc = nodeService.createNode(fooFolder,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
docName,
|
||||
ContentModel.TYPE_CONTENT).getChildRef();
|
||||
PermissionService permissions = services.getPermissionService();
|
||||
permissions.setPermission(doc, BASIC_USER, PermissionService.ALL_PERMISSIONS, true);
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
String siteAName = "siteA"+GUID.generate();
|
||||
String siteBName = "siteB"+GUID.generate();
|
||||
|
||||
Element script = buildScript("doc.move(bar)");
|
||||
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
variables.put("bar", new JBPMNode(barFolder, services));
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to bar!");
|
||||
} catch(ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(fooFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(barFolder, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* See Jira issue ALF-5346.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRunAsAdminMoveContentBetweenSites() throws Exception {
|
||||
SiteService siteService = services.getSiteService();
|
||||
FileFolderService fileFolderService = services.getFileFolderService();
|
||||
|
||||
String siteAName = "siteA"+GUID.generate();
|
||||
String siteBName = "siteB"+GUID.generate();
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||
|
||||
siteService.createSite(
|
||||
"testSitePreset", siteAName, "title", "description", SiteVisibility.PRIVATE);
|
||||
@@ -171,38 +193,38 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
ContentWriter writer = fileFolderService.getWriter(doc);
|
||||
writer.putContent("Just some old content that doesn't mean anything");
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
|
||||
Element script = buildScript("doc.move(companyhome.childByNamePath(\"Sites/"+ siteBName +"/documentLibrary\"))");
|
||||
|
||||
NodeRef companyHome = repository.getCompanyHome();
|
||||
variables.put("companyhome", new JBPMNode(companyHome, services));
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to Site B!");
|
||||
} catch(ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(docLibB, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(BASIC_USER);
|
||||
|
||||
Element script = buildScript("doc.move(companyhome.childByNamePath(\"Sites/"+ siteBName +"/documentLibrary\"))");
|
||||
|
||||
NodeRef companyHome = repository.getCompanyHome();
|
||||
variables.put("companyhome", new JBPMNode(companyHome, services));
|
||||
variables.put("doc", new JBPMNode(doc, services));
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
try
|
||||
{
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.execute(context);
|
||||
fail("The user should not have permission to write to Site B!");
|
||||
} catch(ScriptException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
assertEquals(docLibA, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
|
||||
AlfrescoJavaScript scriptHandler = new AlfrescoJavaScript();
|
||||
scriptHandler.setScript(script);
|
||||
scriptHandler.setRunas(AuthenticationUtil.getAdminUserName());
|
||||
scriptHandler.execute(context);
|
||||
assertEquals(docLibB, nodeService.getPrimaryParent(doc).getParentRef());
|
||||
}
|
||||
|
||||
public void testScopeVariables() throws Exception
|
||||
public void testScopeVariables() throws Exception
|
||||
{
|
||||
String admin = AuthenticationUtil.getAdminUserName();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(admin);
|
||||
String admin = AuthenticationUtil.getAdminUserName();
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(admin);
|
||||
NodeRef person = personService.getPerson(admin);
|
||||
Serializable userHome = nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER);
|
||||
|
||||
@@ -231,31 +253,33 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
value = (ScriptNode) variables.get(key);
|
||||
assertEquals(companyHome, value.getNodeRef());
|
||||
}
|
||||
|
||||
private Element buildScript(String expression) {
|
||||
Element script = DocumentHelper.createElement("script");
|
||||
script.setText(expression);
|
||||
return script;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
|
||||
this.services = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
|
||||
repository = (Repository) applicationContext.getBean("repositoryHelper");
|
||||
personService = services.getPersonService();
|
||||
createUser(BASIC_USER);
|
||||
|
||||
// Sets up the Execution Context
|
||||
context = mock(ExecutionContext.class);
|
||||
ContextInstance contextInstance = mock(ContextInstance.class);
|
||||
when(context.getContextInstance()).thenReturn(contextInstance);
|
||||
variables = new HashMap<String, Object>();
|
||||
when(contextInstance.getVariables()).thenReturn(variables);
|
||||
when(contextInstance.getVariables( any(Token.class))).thenReturn(variables);
|
||||
when(context.getVariable(anyString())).thenAnswer(new Answer<Object>()
|
||||
private Element buildScript(String expression)
|
||||
{
|
||||
Element script = DocumentHelper.createElement("script");
|
||||
script.setText(expression);
|
||||
return script;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void onSetUp() throws Exception
|
||||
{
|
||||
super.onSetUp();
|
||||
|
||||
this.services = (ServiceRegistry) applicationContext.getBean("ServiceRegistry");
|
||||
repository = (Repository) applicationContext.getBean("repositoryHelper");
|
||||
personService = services.getPersonService();
|
||||
createUser(BASIC_USER);
|
||||
|
||||
// Sets up the Execution Context
|
||||
context = mock(ExecutionContext.class);
|
||||
ContextInstance contextInstance = mock(ContextInstance.class);
|
||||
when(context.getContextInstance()).thenReturn(contextInstance);
|
||||
variables = new HashMap<String, Object>();
|
||||
when(contextInstance.getVariables()).thenReturn(variables);
|
||||
when(contextInstance.getVariables( any(Token.class))).thenReturn(variables);
|
||||
when(context.getVariable(anyString())).thenAnswer(new Answer<Object>()
|
||||
{
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
@@ -263,7 +287,7 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
return variables.get(key);
|
||||
}
|
||||
});
|
||||
doAnswer(new Answer<Void>()
|
||||
doAnswer(new Answer<Void>()
|
||||
{
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable
|
||||
{
|
||||
@@ -273,8 +297,8 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
return null;
|
||||
}
|
||||
}).when(context).setVariable(anyString(), any());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createUser(String userName)
|
||||
{
|
||||
if (this.authenticationService.authenticationExists(userName) == false)
|
||||
@@ -291,16 +315,17 @@ public class AlfrescoJavaScriptIntegrationTest extends BaseAlfrescoSpringTest
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestUserStore {
|
||||
private String runAsUser;
|
||||
private String fullUser;
|
||||
private ScriptNode person = null;
|
||||
|
||||
public void storeUsers(ScriptNode user)
|
||||
{
|
||||
fullUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
runAsUser = AuthenticationUtil.getRunAsUser();
|
||||
this.person = user;
|
||||
}
|
||||
public static class TestUserStore
|
||||
{
|
||||
private String runAsUser;
|
||||
private String fullUser;
|
||||
private ScriptNode person = null;
|
||||
|
||||
public void storeUsers(ScriptNode user)
|
||||
{
|
||||
fullUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
runAsUser = AuthenticationUtil.getRunAsUser();
|
||||
this.person = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -82,7 +82,7 @@ public class AlfrescoTimer extends Timer
|
||||
&& taskInstance.isOpen())
|
||||
{
|
||||
taskInstance.setSignalling(false);
|
||||
taskInstance.end();
|
||||
taskInstance.end();
|
||||
}
|
||||
return deleteTimer;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -786,10 +786,10 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
{
|
||||
throw getStartWorkflowException(workflowDefinitionId, e);
|
||||
}
|
||||
catch (DataAccessException e)
|
||||
{
|
||||
throw getStartWorkflowException(workflowDefinitionId, e);
|
||||
}
|
||||
catch (DataAccessException e)
|
||||
{
|
||||
throw getStartWorkflowException(workflowDefinitionId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private WorkflowException getStartWorkflowException(final String workflowDefinitionId, Exception e)
|
||||
@@ -1859,21 +1859,21 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
|
||||
private Object[] getProcessIds(List<?> processList)
|
||||
{
|
||||
ArrayList<Object> ids = new ArrayList<Object>(processList.size());
|
||||
if (processList.isEmpty())
|
||||
{
|
||||
ids.add(new Long(-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Object obj : processList)
|
||||
{
|
||||
ProcessInstance instance = (ProcessInstance) obj;
|
||||
ids.add(instance.getId());
|
||||
}
|
||||
}
|
||||
return ids.toArray();
|
||||
}
|
||||
ArrayList<Object> ids = new ArrayList<Object>(processList.size());
|
||||
if (processList.isEmpty())
|
||||
{
|
||||
ids.add(new Long(-1));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Object obj : processList)
|
||||
{
|
||||
ProcessInstance instance = (ProcessInstance) obj;
|
||||
ids.add(instance.getId());
|
||||
}
|
||||
}
|
||||
return ids.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create process-specific query criteria
|
||||
@@ -1999,7 +1999,7 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
return (WorkflowTask) jbpmTemplate.execute(new JbpmCallback()
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
public Object doInJbpm(JbpmContext context)
|
||||
{
|
||||
// retrieve task
|
||||
TaskMgmtSession taskSession = context.getTaskMgmtSession();
|
||||
@@ -2443,11 +2443,11 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<QName, Serializable> getTaskProperties(TaskInstance instance, boolean localProperties, Map<Long, TokenVariableMap> variablesCache)
|
||||
{
|
||||
// retrieve type definition for task
|
||||
// retrieve type definition for task
|
||||
TypeDefinition taskDef = getFullTaskDefinition(instance);
|
||||
Map<QName, PropertyDefinition> taskProperties = taskDef.getProperties();
|
||||
Map<QName, AssociationDefinition> taskAssocs = taskDef.getAssociations();
|
||||
|
||||
|
||||
// build properties from jBPM context (visit all tokens to the root)
|
||||
Map<String, Object> vars = instance.getVariablesLocally();
|
||||
if (!localProperties)
|
||||
@@ -2492,8 +2492,8 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
boolean isAssoc = taskAssocs.containsKey(qname);
|
||||
if (taskProperties.containsKey(qname) || isAssoc || instance.hasVariableLocally(key))
|
||||
{
|
||||
Serializable value = convertValue(entry.getValue());
|
||||
properties.put(qname, value);
|
||||
Serializable value = convertValue(entry.getValue());
|
||||
properties.put(qname, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2654,7 +2654,7 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
Session session = context.getSession();
|
||||
for (Object obj: comments)
|
||||
{
|
||||
Comment comment = (Comment) obj;
|
||||
Comment comment = (Comment) obj;
|
||||
comment.getToken().getComments().remove(comment);
|
||||
session.delete(comment);
|
||||
}
|
||||
@@ -2975,7 +2975,7 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
* @return JBPMNodeList or JBPMNode
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Serializable convertNodeRefs(boolean isMany, Serializable value)
|
||||
private Serializable convertNodeRefs(boolean isMany, Serializable value)
|
||||
{
|
||||
if (value instanceof NodeRef)
|
||||
{
|
||||
@@ -3395,11 +3395,11 @@ public class JBPMEngine extends AlfrescoBpmEngine implements WorkflowEngine
|
||||
TaskInstance taskInstance = timer.getTaskInstance();
|
||||
if (taskInstance != null)
|
||||
{
|
||||
workflowTask = createWorkflowTask(taskInstance);
|
||||
workflowTask = createWorkflowTask(taskInstance);
|
||||
}
|
||||
|
||||
return factory.createWorkflowTimer(new Long(timer.getId()).toString(), timer.getName(),
|
||||
timer.getException(), timer.getDueDate(), path, workflowTask);
|
||||
timer.getException(), timer.getDueDate(), path, workflowTask);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -174,8 +174,8 @@ public class JBPMEngineTest extends BaseAlfrescoSpringTest
|
||||
assertEquals(path.getInstance().getId(), instance.getId());
|
||||
|
||||
workflowComponent.cancelWorkflow(instance.getId());
|
||||
WorkflowInstance result = workflowComponent.getWorkflowById(instance.getId());
|
||||
assertNull("The workflow isntance should be null!", result);
|
||||
WorkflowInstance result = workflowComponent.getWorkflowById(instance.getId());
|
||||
assertNull("The workflow isntance should be null!", result);
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ public class JBPMEngineTest extends BaseAlfrescoSpringTest
|
||||
|
||||
public void testCancelWorkflowInstance() throws Exception
|
||||
{
|
||||
WorkflowDefinition workflowDef = getTestDefinition();
|
||||
WorkflowDefinition workflowDef = getTestDefinition();
|
||||
workflowComponent.startWorkflow(workflowDef.getId(), null);
|
||||
List<WorkflowInstance> instances1 = workflowComponent.getActiveWorkflows(workflowDef.getId());
|
||||
assertNotNull(instances1);
|
||||
|
@@ -139,15 +139,15 @@ public class JbpmWorkflowServiceIntegrationTest extends AbstractWorkflowServiceI
|
||||
return "alfresco/workflow/parallelreview_processdefinition.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestTimerDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_timer.xml";
|
||||
}
|
||||
@Override
|
||||
protected String getTestTimerDefinitionPath()
|
||||
{
|
||||
return "jbpmresources/test_timer.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected QName getAdhocProcessName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhoc");
|
||||
}
|
||||
@Override
|
||||
protected QName getAdhocProcessName()
|
||||
{
|
||||
return QName.createQName(NamespaceService.WORKFLOW_MODEL_1_0_URI, "adhoc");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user