diff --git a/source/java/org/alfresco/repo/audit/AuditComponent.java b/source/java/org/alfresco/repo/audit/AuditComponent.java index ea9966c9c5..b2ef856122 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponent.java +++ b/source/java/org/alfresco/repo/audit/AuditComponent.java @@ -75,8 +75,6 @@ public interface AuditComponent * this method might return false are: auditing is disabled; no audit applications * have been registered. Sometimes, depending on the log level, this method may always * return true. - *

- * false will always be returned if the server is read-only. * * * @return Returns true if the calling code (data producers) diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index 57404fd1f5..55a80708c4 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -42,6 +42,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState; +import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.audit.AuditQueryParameters; import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; @@ -247,16 +248,8 @@ public class AuditComponentImpl implements AuditComponent */ public boolean areAuditValuesRequired() { - if (transactionService.isReadOnly()) - { - return false; - } - else - { - return - (loggerInbound.isDebugEnabled()) || + return (loggerInbound.isDebugEnabled()) || (isAuditEnabled() && !auditModelRegistry.getAuditPathMapper().isEmpty()); - } } /** @@ -580,7 +573,9 @@ public class AuditComponentImpl implements AuditComponent return recordAuditValuesImpl(mappedValues); } }; - return transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true); + RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); + txnHelper.setForceWritable(true); + return txnHelper.doInTransaction(callback, false, true); case TXN_READ_WRITE: return recordAuditValuesImpl(mappedValues); default: diff --git a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java index ba09319dbd..b5f86b2493 100644 --- a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java +++ b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -43,6 +43,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.repo.transaction.TransactionServiceImpl; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.audit.AuditQueryParameters; import org.alfresco.service.cmr.audit.AuditService; @@ -94,6 +95,7 @@ public class AuditComponentTest extends TestCase private AuditService auditService; private ServiceRegistry serviceRegistry; private TransactionService transactionService; + private TransactionServiceImpl transactionServiceImpl; private NodeService nodeService; private FileFolderService fileFolderService; @@ -113,6 +115,7 @@ public class AuditComponentTest extends TestCase serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); auditService = serviceRegistry.getAuditService(); transactionService = serviceRegistry.getTransactionService(); + transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService"); nodeService = serviceRegistry.getNodeService(); fileFolderService = serviceRegistry.getFileFolderService(); @@ -263,7 +266,7 @@ public class AuditComponentTest extends TestCase return auditComponent.recordAuditValues(actionPath, adjustedValues); } }; - return transactionService.getRetryingTransactionHelper().doInTransaction(auditCallback); + return transactionService.getRetryingTransactionHelper().doInTransaction(auditCallback, true, false); } /** @@ -987,4 +990,22 @@ public class AuditComponentTest extends TestCase }; AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminRoleName()); } + + /** + * Test for MNT-11072 + * @throws Exception + */ + public void testAuditInReadOnly() throws Exception + { + QName veto = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "TestVeto"); + transactionServiceImpl.setAllowWrite(false, veto); + try + { + auditAction02("action-02"); + } + finally + { + transactionServiceImpl.setAllowWrite(true, veto); + } + } }