REPO-2191 : Service Pack: MNT-17523: Loss of information, field values truncated when auditing long strings (implement fix)

- string value with length grater than the DB max string length is saved as serializable
   - removed unneeded trimStringsIfNecessary and tests added in MNT-12196

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@135761 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Cristian Turlica
2017-03-13 07:58:14 +00:00
parent b4b391199d
commit f180ab89c8
6 changed files with 257 additions and 451 deletions

View File

@@ -1,28 +1,28 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
package org.alfresco.repo.audit;
import java.io.Serializable;
@@ -36,6 +36,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.repo.audit.model.AuditApplication;
import org.alfresco.repo.audit.model.AuditModelException;
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
import org.alfresco.repo.domain.schema.SchemaBootstrap;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
@@ -62,6 +63,7 @@ import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.EqualsHelper;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.mutable.MutableInt;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -694,44 +696,44 @@ public class AuditComponentTest extends TestCase
logger.debug(sb.toString());
assertEquals("Explicit audit entries were not deleted", 0, results.size());
}
public void testAuditQuery_MinId() throws Exception
{
AuditQueryCallback auditQueryCallback = new AuditQueryCallback()
{
public boolean valuesRequired()
{
return true;
}
public boolean handleAuditEntry(
Long entryId,
String applicationName,
String user,
long time,
Map<String, Serializable> values)
{
if (logger.isDebugEnabled())
{
logger.debug(
"Audit Entry " + entryId + ": " + applicationName + ", " + user + ", " + new Date(time) + "\n" +
" Data: " + values);
}
return true;
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error)
{
throw new AlfrescoRuntimeException(errorMsg, error);
}
};
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(APPLICATION_API_TEST);
params.setForward(false);
params.setToId(Long.MAX_VALUE);
queryAuditLog(auditQueryCallback, params, 1);
}
public void testAuditQuery_MinId() throws Exception
{
AuditQueryCallback auditQueryCallback = new AuditQueryCallback()
{
public boolean valuesRequired()
{
return true;
}
public boolean handleAuditEntry(
Long entryId,
String applicationName,
String user,
long time,
Map<String, Serializable> values)
{
if (logger.isDebugEnabled())
{
logger.debug(
"Audit Entry " + entryId + ": " + applicationName + ", " + user + ", " + new Date(time) + "\n" +
" Data: " + values);
}
return true;
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error)
{
throw new AlfrescoRuntimeException(errorMsg, error);
}
};
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(APPLICATION_API_TEST);
params.setForward(false);
params.setToId(Long.MAX_VALUE);
queryAuditLog(auditQueryCallback, params, 1);
}
public void testAuditQuery_MaxId() throws Exception
{
@@ -1146,4 +1148,39 @@ public class AuditComponentTest extends TestCase
transactionServiceImpl.setAllowWrite(true, veto);
}
}
public void testAuditTruncatedValues()
{
final String rootPath = "/test/one.one/two.one";
// String value with length grater then the DB supported threshold.
final String stringValue = RandomStringUtils.randomAlphanumeric(SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH + 1);
final MLText mlTextValue = new MLText();
mlTextValue.put(Locale.ENGLISH, stringValue);
final RetryingTransactionCallback<Map<String, Serializable>> testCallback = new RetryingTransactionCallback<Map<String, Serializable>>()
{
public Map<String, Serializable> execute() throws Throwable
{
final Map<String, Serializable> values = new HashMap<>();
values.put("/3.1/4.1", stringValue);
values.put("/3.1/4.2", mlTextValue);
return auditComponent.recordAuditValues(rootPath, values);
}
};
RunAsWork<Map<String, Serializable>> testRunAs = new RunAsWork< Map<String, Serializable>>()
{
public Map<String, Serializable> doWork() throws Exception
{
return transactionService.getRetryingTransactionHelper().doInTransaction(testCallback);
}
};
Map<String, Serializable> result = AuthenticationUtil.runAs(testRunAs, "SomeOtherUser");
// Check that the values aren't truncated.
assertEquals(stringValue, result.get("/test/1.1/2.1/3.1/4.1/value.1"));
assertEquals(mlTextValue, result.get("/test/1.1/2.1/3.1/4.2/value.2"));
}
}