Merge branch 'master' of https://github.com/Alfresco/alfresco-community-repo into MNT-23926_add_sevenpass_dod_5220.22-M_ags_deletion

This commit is contained in:
Vedant Mehra
2025-03-12 13:05:29 +05:30
29 changed files with 656 additions and 565 deletions

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId> <artifactId>alfresco-community-repo-amps</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId> <artifactId>alfresco-governance-services-community-parent</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-automation-community-repo</artifactId> <artifactId>alfresco-governance-services-automation-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<build> <build>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-parent</artifactId> <artifactId>alfresco-governance-services-community-parent</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -1,3 +1,3 @@
SOLR6_TAG=2.0.14 SOLR6_TAG=2.0.15
POSTGRES_TAG=16.6 POSTGRES_TAG=16.6
ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8 ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8

View File

@@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId> <artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-governance-services-community-repo-parent</artifactId> <artifactId>alfresco-governance-services-community-repo-parent</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<build> <build>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-amps</artifactId> <artifactId>alfresco-community-repo-amps</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

View File

@@ -23,10 +23,6 @@ function runAction(p_params)
if (p_params.destNode.hasAspect("cm:lockable") && !p_params.destNode.hasAspect("trx:transferred")) if (p_params.destNode.hasAspect("cm:lockable") && !p_params.destNode.hasAspect("trx:transferred"))
{ {
p_params.destNode.unlock(); p_params.destNode.unlock();
if(p_params.destNode.hasAspect("gd2:editingInGoogle"))
{
p_params.destNode.removeAspect("gd2:editingInGoogle");
}
} }
var resultId = originalDoc.name, var resultId = originalDoc.name,

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<dependencies> <dependencies>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<dependencies> <dependencies>

View File

@@ -9,6 +9,6 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId> <artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
</project> </project>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId> <artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -1,3 +1,3 @@
SOLR6_TAG=2.0.14 SOLR6_TAG=2.0.15
POSTGRES_TAG=16.6 POSTGRES_TAG=16.6
ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8 ACTIVEMQ_TAG=5.18.3-jre17-rockylinux8

View File

@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId> <artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<modules> <modules>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId> <artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<organization> <organization>

View File

@@ -9,7 +9,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId> <artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<developers> <developers>

View File

@@ -9,7 +9,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId> <artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<developers> <developers>

View File

@@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId> <artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

View File

@@ -9,7 +9,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-tests</artifactId> <artifactId>alfresco-community-repo-tests</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<developers> <developers>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo-packaging</artifactId> <artifactId>alfresco-community-repo-packaging</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<properties> <properties>

10
pom.xml
View File

@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Alfresco Community Repo Parent</name> <name>Alfresco Community Repo Parent</name>
@@ -51,8 +51,8 @@
<dependency.alfresco-server-root.version>7.0.1</dependency.alfresco-server-root.version> <dependency.alfresco-server-root.version>7.0.1</dependency.alfresco-server-root.version>
<dependency.activiti-engine.version>5.23.0</dependency.activiti-engine.version> <dependency.activiti-engine.version>5.23.0</dependency.activiti-engine.version>
<dependency.activiti.version>5.23.0</dependency.activiti.version> <dependency.activiti.version>5.23.0</dependency.activiti.version>
<dependency.alfresco-transform-core.version>5.1.7-A.3</dependency.alfresco-transform-core.version> <dependency.alfresco-transform-core.version>5.1.7</dependency.alfresco-transform-core.version>
<dependency.alfresco-transform-service.version>4.1.7-A.1</dependency.alfresco-transform-service.version> <dependency.alfresco-transform-service.version>4.1.7</dependency.alfresco-transform-service.version>
<dependency.alfresco-greenmail.version>7.1</dependency.alfresco-greenmail.version> <dependency.alfresco-greenmail.version>7.1</dependency.alfresco-greenmail.version>
<dependency.acs-event-model.version>1.0.2</dependency.acs-event-model.version> <dependency.acs-event-model.version>1.0.2</dependency.acs-event-model.version>
@@ -112,10 +112,10 @@
<dependency.jakarta-ee-json-api.version>2.1.3</dependency.jakarta-ee-json-api.version> <dependency.jakarta-ee-json-api.version>2.1.3</dependency.jakarta-ee-json-api.version>
<dependency.jakarta-ee-json-impl.version>1.1.7</dependency.jakarta-ee-json-impl.version> <dependency.jakarta-ee-json-impl.version>1.1.7</dependency.jakarta-ee-json-impl.version>
<dependency.jakarta-json-path.version>2.9.0</dependency.jakarta-json-path.version> <dependency.jakarta-json-path.version>2.9.0</dependency.jakarta-json-path.version>
<dependency.json-smart.version>2.5.1</dependency.json-smart.version> <dependency.json-smart.version>2.5.2</dependency.json-smart.version>
<alfresco.googledrive.version>4.1.0</alfresco.googledrive.version> <alfresco.googledrive.version>4.1.0</alfresco.googledrive.version>
<alfresco.aos-module.version>3.2.0</alfresco.aos-module.version> <alfresco.aos-module.version>3.2.0</alfresco.aos-module.version>
<alfresco.api-explorer.version>25.1.0-A1</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share --> <alfresco.api-explorer.version>25.1.0</alfresco.api-explorer.version> <!-- Also in alfresco-enterprise-share -->
<alfresco.maven-plugin.version>2.2.0</alfresco.maven-plugin.version> <alfresco.maven-plugin.version>2.2.0</alfresco.maven-plugin.version>
<license-maven-plugin.version>2.4.0</license-maven-plugin.version> <license-maven-plugin.version>2.4.0</license-maven-plugin.version>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<dependencies> <dependencies>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.alfresco</groupId> <groupId>org.alfresco</groupId>
<artifactId>alfresco-community-repo</artifactId> <artifactId>alfresco-community-repo</artifactId>
<version>25.1.0.61-SNAPSHOT</version> <version>25.1.0.70-SNAPSHOT</version>
</parent> </parent>
<dependencies> <dependencies>

View File

@@ -28,11 +28,17 @@ package org.alfresco.repo.workflow.activiti.script;
import java.util.Map; import java.util.Map;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.delegate.VariableScope; import org.activiti.engine.delegate.VariableScope;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl; import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context; import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.el.Expression; import org.activiti.engine.impl.el.Expression;
import org.activiti.engine.impl.persistence.entity.DeploymentEntity; import org.activiti.engine.impl.persistence.entity.DeploymentEntity;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.repository.ProcessDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.workflow.WorkflowDeployer; import org.alfresco.repo.workflow.WorkflowDeployer;
@@ -45,8 +51,7 @@ import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowException; import org.alfresco.service.cmr.workflow.WorkflowException;
/** /**
* Base class for execution scripts, using {@link ScriptService} as part of * Base class for execution scripts, using {@link ScriptService} as part of activiti workflow.
* activiti workflow.
* *
* @author Frederik Heremans * @author Frederik Heremans
* @since 3.4.e * @since 3.4.e
@@ -61,6 +66,8 @@ public class ActivitiScriptBase
protected Expression runAs; protected Expression runAs;
protected Expression scriptProcessor; protected Expression scriptProcessor;
private static final Logger LOGGER = LoggerFactory.getLogger(ActivitiScriptBase.class);
protected Object executeScript(String theScript, Map<String, Object> model, String scriptProcessorName, String runAsUser) protected Object executeScript(String theScript, Map<String, Object> model, String scriptProcessorName, String runAsUser)
{ {
String user = AuthenticationUtil.getFullyAuthenticatedUser(); String user = AuthenticationUtil.getFullyAuthenticatedUser();
@@ -91,8 +98,7 @@ public class ActivitiScriptBase
protected Object executeScriptAsUser(final String theScript, final Map<String, Object> model, final String scriptProcessorName, final String runAsUser) protected Object executeScriptAsUser(final String theScript, final Map<String, Object> model, final String scriptProcessorName, final String runAsUser)
{ {
// execute as specified runAsUser // execute as specified runAsUser
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<>() {
{
public Object doWork() throws Exception public Object doWork() throws Exception
{ {
return executeScript(theScript, model, scriptProcessorName); return executeScript(theScript, model, scriptProcessorName);
@@ -106,7 +112,7 @@ public class ActivitiScriptBase
Object scriptResult = null; Object scriptResult = null;
// Checks if current workflow is secure // Checks if current workflow is secure
boolean secure = isSecure(); boolean secure = isSecure(model);
if (scriptProcessorName != null) if (scriptProcessorName != null)
{ {
@@ -140,8 +146,8 @@ public class ActivitiScriptBase
if (registry == null) if (registry == null)
{ {
throw new RuntimeException( throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" + "Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
} }
return registry; return registry;
} }
@@ -149,41 +155,135 @@ public class ActivitiScriptBase
} }
/** /**
* Checks whether the workflow must be considered secure or not - based on {@link DeploymentEntity} category. * Checks whether the workflow must be considered secure or not - based on {@link DeploymentEntity} category. If it is not considered secure, the workflow will be executed in sandbox context with more restrictions
* If it is not considered secure, the workflow will be executed in sandbox context with more restrictions
* *
* @return true if workflow is considered secure, false otherwise * @return true if workflow is considered secure, false otherwise
*/ */
private boolean isSecure() private boolean isSecure(Map<String, Object> model)
{
String category = getDeploymentCategory(model);
// iF The deployment category matches the condition (either internal or full access) the workflow is considered secure
return category != null && (WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL.equals(category) || WorkflowDeployer.CATEGORY_FULL_ACCESS.equals(category));
}
/**
* Gets the deployment category from the execution context. If no execution context is available, a query to obtain the deployment is performed so the category can be returned.
*
* @param model
* a map with workflow model
* @return the deployment category
*/
private String getDeploymentCategory(Map<String, Object> model)
{
String category = getDeploymentCategoryFromContext();
if (category == null)
{
String deploymentId = null;
String processDefinitionId = null;
if (model != null && model.containsKey(EXECUTION_BINDING_NAME) && model.get(EXECUTION_BINDING_NAME) instanceof ExecutionEntity)
{
ExecutionEntity executionEntity = (ExecutionEntity) model.get(EXECUTION_BINDING_NAME);
deploymentId = executionEntity.getDeploymentId();
processDefinitionId = executionEntity.getProcessDefinitionId();
}
category = getDeploymentCategoryFromQuery(deploymentId, processDefinitionId);
}
return category;
}
/**
* Obtains the deployment category from current execution context
*
* @return the category for current execution deployment, otherwise null
*/
private String getDeploymentCategoryFromContext()
{ {
String category = null; String category = null;
try try
{ {
if (Context.isExecutionContextActive()) if (Context.isExecutionContextActive())
{ {
category = Context.getExecutionContext().getDeployment().getCategory(); category = Context.getExecutionContext().getDeployment().getCategory();
} }
else
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("No execution context available");
}
}
} }
catch (Exception e) catch (Exception e)
{ {
// No action required if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Could not obtain deployment category from execution context: {}", e.getMessage());
}
} }
// If the workflow is considered secure, the deployment entity category matches the condition (either internal or full access) return category;
return category != null && (WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL.equals(category) || WorkflowDeployer.CATEGORY_FULL_ACCESS.equals(category));
} }
/** /**
* Checks that the specified 'runAs' field * Obtains the deployment category through a query
* specifies a valid username. *
* @param deploymentId
* the deployment id to obtain the category from
* @param processDefinitionId
* if no deployment id is provided, the process definition id can be used to obtain the deployment
* @return the category for the obtained deployment, otherwise null
*/
private String getDeploymentCategoryFromQuery(String deploymentId, String processDefinitionId)
{
String category = null;
try
{
RepositoryService repositoryService = Context.getProcessEngineConfiguration().getRepositoryService();
if (deploymentId == null && processDefinitionId != null)
{
ProcessDefinition processDefnition = repositoryService.getProcessDefinition(processDefinitionId);
if (processDefnition != null)
{
deploymentId = processDefnition.getDeploymentId();
}
}
if (deploymentId != null)
{
DeploymentEntity deployment = (DeploymentEntity) repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment != null)
{
category = deployment.getCategory();
}
}
}
catch (Exception e)
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Could not obtain deployment category through a query: {}", e.getMessage());
}
}
return category;
}
/**
* Checks that the specified 'runAs' field specifies a valid username.
*/ */
private void validateRunAsUser(final String runAsUser) private void validateRunAsUser(final String runAsUser)
{ {
Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>() Boolean runAsExists = AuthenticationUtil.runAs(new RunAsWork<>() {
{
// Validate using System user to ensure sufficient permissions available to access person node. // Validate using System user to ensure sufficient permissions available to access person node.
@Override
public Boolean doWork() throws Exception public Boolean doWork() throws Exception
{ {
return getServiceRegistry().getPersonService().personExists(runAsUser); return getServiceRegistry().getPersonService().personExists(runAsUser);
@@ -209,7 +309,7 @@ public class ActivitiScriptBase
} }
// The "System" user is a special case, which has no person object associated with it. // The "System" user is a special case, which has no person object associated with it.
if(userName != null && !AuthenticationUtil.SYSTEM_USER_NAME.equals(userName)) if (userName != null && !AuthenticationUtil.SYSTEM_USER_NAME.equals(userName))
{ {
ServiceRegistry services = getServiceRegistry(); ServiceRegistry services = getServiceRegistry();
PersonService personService = services.getPersonService(); PersonService personService = services.getPersonService();

View File

@@ -25,29 +25,30 @@
*/ */
package org.alfresco.repo.lock.mem; package org.alfresco.repo.lock.mem;
import java.util.Date; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.Date;
import jakarta.transaction.NotSupportedException; import jakarta.transaction.NotSupportedException;
import jakarta.transaction.SystemException; import jakarta.transaction.SystemException;
import jakarta.transaction.UserTransaction; import jakarta.transaction.UserTransaction;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.lock.LockType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.dao.ConcurrencyFailureException; import org.springframework.dao.ConcurrencyFailureException;
import static org.junit.Assert.assertEquals; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import static org.junit.Assert.assertNull; import org.alfresco.service.cmr.lock.LockType;
import static org.junit.Assert.fail; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
/** /**
* Integration tests that check transaction related functionality of {@link LockStore} implementations. * Integration tests that check transaction related functionality of {@link LockStore} implementations.
*
* @author Matt Ward * @author Matt Ward
*/ */
public abstract class AbstractLockStoreTxTest<T extends LockStore> public abstract class AbstractLockStoreTxTest<T extends LockStore>
@@ -82,10 +83,10 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
/** /**
* <ul> * <ul>
* <li>Start outer txn</li> * <li>Start outer txn</li>
* <li>Modify lock in outer txn</li> * <li>Modify lock in outer txn</li>
* <li>Start inner txn</li> * <li>Start inner txn</li>
* <li>Modify lock in inner txn</li> * <li>Modify lock in inner txn</li>
* </ul> * </ul>
* Inner transaction should fail while outer succeeds * Inner transaction should fail while outer succeeds
*/ */
@@ -106,11 +107,9 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
Date now = new Date(); Date now = new Date();
Date expires = new Date(now.getTime() + 180000); Date expires = new Date(now.getTime() + 180000);
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"jbloggs", expires, Lifetime.EPHEMERAL, null); "jbloggs", expires, Lifetime.EPHEMERAL, null);
Thread txB = new Thread("TxB") {
Thread txB = new Thread("TxB")
{
@Override @Override
public void run() public void run()
{ {
@@ -138,7 +137,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
// txB sets a value, already seen as non-existent lock by txA // txB sets a value, already seen as non-existent lock by txA
lockStore.set(nodeRef2, LockState.createLock(nodeRef2, LockType.WRITE_LOCK, lockStore.set(nodeRef2, LockState.createLock(nodeRef2, LockType.WRITE_LOCK,
"csmith", null, Lifetime.EPHEMERAL, null)); "csmith", null, Lifetime.EPHEMERAL, null));
} }
finally finally
{ {
@@ -152,7 +151,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
finally finally
{ {
// Stop 'main' from waiting // Stop 'main' from waiting
synchronized(main) synchronized (main)
{ {
main.notifyAll(); main.notifyAll();
} }
@@ -166,6 +165,9 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
// txA set lock state 1 // txA set lock state 1
lockStore.set(nodeRef, lockState1); lockStore.set(nodeRef, lockState1);
// Perform a read, that we know will retrieve a null value (and null will be cached for this transaction)
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
// Wait while txB reads and checks the LockState // Wait while txB reads and checks the LockState
txB.setDaemon(true); txB.setDaemon(true);
txB.start(); txB.start();
@@ -186,13 +188,10 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
// Check we can see the update. // Check we can see the update.
assertEquals("bsmith", lockStore.get(nodeRef).getOwner()); assertEquals("bsmith", lockStore.get(nodeRef).getOwner());
// Perform a read, that we know will retrieve a null value
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
// Wait while txB populates the store with a value for nodeRef2 // Wait while txB populates the store with a value for nodeRef2
passControl(this, txB); passControl(this, txB);
// Perform the read again - update should not be visible in this transaction // Perform the read again - update should not be visible in this transaction (was already cached)
assertNull("nodeRef2 LockState", lockStore.get(nodeRef2)); assertNull("nodeRef2 LockState", lockStore.get(nodeRef2));
} }
finally finally
@@ -203,16 +202,16 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
protected void passControl(Object from, Object to) protected void passControl(Object from, Object to)
{ {
synchronized(to) synchronized (to)
{ {
to.notifyAll(); to.notifyAll();
} }
synchronized(from) synchronized (from)
{ {
try try
{ {
// TODO: wait should be called in a loop with repeated wait condition check, // TODO: wait should be called in a loop with repeated wait condition check,
// but what's the condition we're waiting on? // but what's the condition we're waiting on?
from.wait(10000); from.wait(10000);
} }
catch (InterruptedException error) catch (InterruptedException error)
@@ -231,11 +230,9 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
Date now = new Date(); Date now = new Date();
Date expires = new Date(now.getTime() + 180000); Date expires = new Date(now.getTime() + 180000);
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"jbloggs", expires, Lifetime.EPHEMERAL, null); "jbloggs", expires, Lifetime.EPHEMERAL, null);
Thread txB = new Thread("TxB") {
Thread txB = new Thread("TxB")
{
@Override @Override
public void run() public void run()
{ {
@@ -260,7 +257,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
// when it has been modified by another tx since this tx last inspected it. // when it has been modified by another tx since this tx last inspected it.
AuthenticationUtil.setFullyAuthenticatedUser("jbloggs"); // Current lock owner AuthenticationUtil.setFullyAuthenticatedUser("jbloggs"); // Current lock owner
lockStore.set(nodeRef, LockState.createLock(nodeRef, LockType.WRITE_LOCK, lockStore.set(nodeRef, LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"csmith", null, Lifetime.EPHEMERAL, null)); "csmith", null, Lifetime.EPHEMERAL, null));
fail("Exception should have been thrown but was not."); fail("Exception should have been thrown but was not.");
} }
catch (ConcurrencyFailureException e) catch (ConcurrencyFailureException e)
@@ -280,7 +277,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
finally finally
{ {
// Stop 'main' from waiting // Stop 'main' from waiting
synchronized(main) synchronized (main)
{ {
main.notifyAll(); main.notifyAll();
} }
@@ -325,12 +322,11 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
final Date now = new Date(); final Date now = new Date();
Date expired = new Date(now.getTime() - 180000); Date expired = new Date(now.getTime() - 180000);
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"jbloggs", expired, Lifetime.EPHEMERAL, null); "jbloggs", expired, Lifetime.EPHEMERAL, null);
final LockState lockState2 = LockState.createWithOwner(lockState1, "another"); final LockState lockState2 = LockState.createWithOwner(lockState1, "another");
Thread txB = new Thread("TxB") Thread txB = new Thread("TxB") {
{
@Override @Override
public void run() public void run()
{ {
@@ -351,7 +347,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
// (but not since this tx's initial read) // (but not since this tx's initial read)
Date expiresFuture = new Date(now.getTime() + 180000); Date expiresFuture = new Date(now.getTime() + 180000);
final LockState newUserLockState = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState newUserLockState = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"new-user", expiresFuture, Lifetime.EPHEMERAL, null); "new-user", expiresFuture, Lifetime.EPHEMERAL, null);
lockStore.set(nodeRef, newUserLockState); lockStore.set(nodeRef, newUserLockState);
// Read // Read
@@ -369,7 +365,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
finally finally
{ {
// Stop 'main' from waiting // Stop 'main' from waiting
synchronized(main) synchronized (main)
{ {
main.notifyAll(); main.notifyAll();
} }
@@ -404,7 +400,6 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
} }
} }
@Test @Test
public void testNotOnlyCurrentLockOwnerCanChangeInfo() throws NotSupportedException, SystemException public void testNotOnlyCurrentLockOwnerCanChangeInfo() throws NotSupportedException, SystemException
{ {
@@ -414,7 +409,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
Date now = new Date(); Date now = new Date();
Date expires = new Date(now.getTime() + 180000); Date expires = new Date(now.getTime() + 180000);
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"jbloggs", expires, Lifetime.EPHEMERAL, null); "jbloggs", expires, Lifetime.EPHEMERAL, null);
txA.begin(); txA.begin();
try try
@@ -455,7 +450,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
Date now = new Date(); Date now = new Date();
Date expired = new Date(now.getTime() - 900); Date expired = new Date(now.getTime() - 900);
final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState1 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"jbloggs", expired, Lifetime.EPHEMERAL, null); "jbloggs", expired, Lifetime.EPHEMERAL, null);
txA.begin(); txA.begin();
try try
@@ -469,7 +464,7 @@ public abstract class AbstractLockStoreTxTest<T extends LockStore>
AuthenticationUtil.setFullyAuthenticatedUser("csmith"); AuthenticationUtil.setFullyAuthenticatedUser("csmith");
Date expiresFuture = new Date(now.getTime() + 180000); Date expiresFuture = new Date(now.getTime() + 180000);
final LockState lockState2 = LockState.createLock(nodeRef, LockType.WRITE_LOCK, final LockState lockState2 = LockState.createLock(nodeRef, LockType.WRITE_LOCK,
"csmith", expiresFuture, Lifetime.EPHEMERAL, null); "csmith", expiresFuture, Lifetime.EPHEMERAL, null);
lockStore.set(nodeRef, lockState2); lockStore.set(nodeRef, lockState2);
// Updated, since lock had expired. // Updated, since lock had expired.