diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index ee496c85ef..409f7a7ea6 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -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,6 +491,78 @@ public class AuditComponentImpl implements AuditComponent return recordAuditValuesWithUserFilter(rootPath, values, true); } + private void trimStringsIfNecessary(Object values) + { + if (values instanceof Map) + { + // trim string audited value + Map map = ((Map) values); + for (Map.Entry entry : map.entrySet()) + { + Serializable auditValue = entry.getValue(); + // Trim strings + if (auditValue == null) + { + // nothing to do + } + else if (auditValue instanceof String) + { + entry.setValue(SchemaBootstrap.trimStringForTextFields((String) auditValue)); + } + else if (auditValue instanceof MLText) + { + MLText mltext = (MLText) auditValue; + Set locales = mltext.getLocales(); + for (Locale locale : locales) + { + mltext.put(locale, SchemaBootstrap.trimStringForTextFields(mltext.getValue(locale))); + } + entry.setValue(mltext); + } + else if ((auditValue instanceof Map) || (auditValue instanceof Collection)) + { + trimStringsIfNecessary(auditValue); + } + } + } + else if (values instanceof Collection) + { + Collection collection = (Collection) values; + Iterator 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 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 recordAuditValuesWithUserFilter(String rootPath, Map values, boolean useUserFilter) { @@ -503,26 +576,8 @@ public class AuditComponentImpl implements AuditComponent return Collections.emptyMap(); } - // trim string audited value - for (Map.Entry entry : values.entrySet()) - { - Serializable auditValue = entry.getValue(); - // Trim strings - if (auditValue instanceof String) - { - entry.setValue(SchemaBootstrap.trimStringForTextFields((String) auditValue)); - } - else if (auditValue instanceof MLText) - { - MLText mltext = (MLText) auditValue; - Set locales = mltext.getLocales(); - for (Locale locale : locales) - { - mltext.put(locale, SchemaBootstrap.trimStringForTextFields(mltext.getValue(locale))); - } - entry.setValue(mltext); - } - } + // MNT-12196 + trimStringsIfNecessary(values); // Log inbound values if (loggerInbound.isDebugEnabled()) diff --git a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java index f744cada6a..7891ad8ccc 100644 --- a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java +++ b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java @@ -987,10 +987,24 @@ public class AuditComponentTest extends TestCase MLText mlTextValue = new MLText(); mlTextValue.put(Locale.ENGLISH, sb.toString()); + + HashMap map = new HashMap(); + map.put("String", sb.toString()); + MLText mlTextValue1 = new MLText(); + mlTextValue1.put(Locale.ENGLISH, sb.toString()); + map.put("MLText", mlTextValue1); + ArrayList list = new ArrayList(); + list.add(sb.toString()); + MLText mlTextValue2 = new MLText(); + mlTextValue2.put(Locale.ENGLISH, sb.toString()); + list.add(mlTextValue2); + Map values = new HashMap(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);