mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)
87698: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 86372: Merged DEV to V4.2-BUG-FIX (4.2.4) 86152 : MNT-12196 : Exception generated in “AccessAuditor” when length of custom property string in Javascript is bigger than 1024 in Postgres database - Added trimming audit values (String and MLText) to not exceed system.maximumStringLength 86284 : MNT-12196 : Exception generated in “AccessAuditor” when length of custom property string in Javascript is bigger than 1024 in Postgres database 86286 : MNT-12196 : Exception generated in “AccessAuditor” when length of custom property string in Javascript is bigger than 1024 in Postgres database 86303 : MNT-12196 : Exception generated in “AccessAuditor” when length of custom property string in Javascript is bigger than 1024 in Postgres database - Add check for Map and Collection git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94537 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.repo.audit;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -490,25 +491,21 @@ public class AuditComponentImpl implements AuditComponent
|
||||
return recordAuditValuesWithUserFilter(rootPath, values, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter)
|
||||
private void trimStringsIfNecessary(Object values)
|
||||
{
|
||||
ParameterCheck.mandatory("rootPath", rootPath);
|
||||
AuditApplication.checkPathFormat(rootPath);
|
||||
|
||||
String username = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (values == null || values.isEmpty() || !areAuditValuesRequired()
|
||||
|| !(userAuditFilter.acceptUser(username) || !useUserFilter) || !auditFilter.accept(rootPath, values))
|
||||
if (values instanceof Map<?, ?>)
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// trim string audited value
|
||||
for (Map.Entry<String, Serializable> entry : values.entrySet())
|
||||
Map<String, Serializable> map = ((Map<String, Serializable>) values);
|
||||
for (Map.Entry<String, Serializable> entry : map.entrySet())
|
||||
{
|
||||
Serializable auditValue = entry.getValue();
|
||||
// Trim strings
|
||||
if (auditValue instanceof String)
|
||||
if (auditValue == null)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
else if (auditValue instanceof String)
|
||||
{
|
||||
entry.setValue(SchemaBootstrap.trimStringForTextFields((String) auditValue));
|
||||
}
|
||||
@@ -522,7 +519,65 @@ public class AuditComponentImpl implements AuditComponent
|
||||
}
|
||||
entry.setValue(mltext);
|
||||
}
|
||||
else if ((auditValue instanceof Map<?, ?>) || (auditValue instanceof Collection<?>))
|
||||
{
|
||||
trimStringsIfNecessary(auditValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (values instanceof Collection<?>)
|
||||
{
|
||||
Collection<Object> collection = (Collection<Object>) values;
|
||||
Iterator<Object> iterator = collection.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Object auditValue = iterator.next();
|
||||
// Trim strings
|
||||
if (auditValue == null)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
else if (auditValue instanceof String)
|
||||
{
|
||||
String trimmed = SchemaBootstrap.trimStringForTextFields((String) auditValue);
|
||||
if (!trimmed.equals(auditValue))
|
||||
{
|
||||
collection.remove(auditValue);
|
||||
collection.add(trimmed);
|
||||
}
|
||||
}
|
||||
else if (auditValue instanceof MLText)
|
||||
{
|
||||
MLText mltext = (MLText) auditValue;
|
||||
Set<Locale> locales = mltext.getLocales();
|
||||
for (Locale locale : locales)
|
||||
{
|
||||
mltext.put(locale, SchemaBootstrap.trimStringForTextFields(mltext.getValue(locale)));
|
||||
}
|
||||
}
|
||||
else if ((auditValue instanceof Map<?, ?>) || (auditValue instanceof Collection<?>))
|
||||
{
|
||||
trimStringsIfNecessary(auditValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter)
|
||||
{
|
||||
ParameterCheck.mandatory("rootPath", rootPath);
|
||||
AuditApplication.checkPathFormat(rootPath);
|
||||
|
||||
String username = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (values == null || values.isEmpty() || !areAuditValuesRequired()
|
||||
|| !(userAuditFilter.acceptUser(username) || !useUserFilter) || !auditFilter.accept(rootPath, values))
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// MNT-12196
|
||||
trimStringsIfNecessary(values);
|
||||
|
||||
// Log inbound values
|
||||
if (loggerInbound.isDebugEnabled())
|
||||
|
@@ -988,9 +988,23 @@ public class AuditComponentTest extends TestCase
|
||||
MLText mlTextValue = new MLText();
|
||||
mlTextValue.put(Locale.ENGLISH, sb.toString());
|
||||
|
||||
HashMap<String, Serializable> map = new HashMap<String, Serializable>();
|
||||
map.put("String", sb.toString());
|
||||
MLText mlTextValue1 = new MLText();
|
||||
mlTextValue1.put(Locale.ENGLISH, sb.toString());
|
||||
map.put("MLText", mlTextValue1);
|
||||
|
||||
ArrayList<Serializable> list = new ArrayList<Serializable>();
|
||||
list.add(sb.toString());
|
||||
MLText mlTextValue2 = new MLText();
|
||||
mlTextValue2.put(Locale.ENGLISH, sb.toString());
|
||||
list.add(mlTextValue2);
|
||||
|
||||
Map<String, Serializable> values = new HashMap<String, Serializable>(13);
|
||||
values.put("/3.1/4.1", sb.toString());
|
||||
values.put("/3.1/4.2", mlTextValue);
|
||||
values.put("map", map);
|
||||
values.put("collection", list);
|
||||
|
||||
auditComponent.recordAuditValues("/test/one.one/two.one", values);
|
||||
|
||||
|
Reference in New Issue
Block a user