From c93ae4a719d597bc833ce4d8bf0bec6484a37f8c Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 31 Jan 2015 09:46:35 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20HEAD-BUG-FIX=20(5.1/Cloud)=20to=20HEAD?= =?UTF-8?q?=20(5.0/Cloud)=20=20=20=2087698:=20Merged=20V4.2-BUG-FIX=20(4.2?= =?UTF-8?q?.4)=20to=20HEAD-BUG-FIX=20(5.0/Cloud)=20=20=20=20=20=20=2086372?= =?UTF-8?q?:=20Merged=20DEV=20to=20V4.2-BUG-FIX=20(4.2.4)=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=2086152=20:=20MNT-12196=20:=20Exception=20generate?= =?UTF-8?q?d=20in=20=E2=80=9CAccessAuditor=E2=80=9D=20when=20length=20of?= =?UTF-8?q?=20custom=20property=20string=20in=20Javascript=20is=20bigger?= =?UTF-8?q?=20than=201024=20in=20Postgres=20database=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20-=20Added=20trimming=20audit=20values=20(Stri?= =?UTF-8?q?ng=20and=20MLText)=20to=20not=20exceed=20system.maximumStringLe?= =?UTF-8?q?ngth=20=20=20=20=20=20=20=20=20=2086284=20:=20MNT-12196=20:=20E?= =?UTF-8?q?xception=20generated=20in=20=E2=80=9CAccessAuditor=E2=80=9D=20w?= =?UTF-8?q?hen=20length=20of=20custom=20property=20string=20in=20Javascrip?= =?UTF-8?q?t=20is=20bigger=20than=201024=20in=20Postgres=20database=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=2086286=20:=20MNT-12196=20:=20Exception?= =?UTF-8?q?=20generated=20in=20=E2=80=9CAccessAuditor=E2=80=9D=20when=20le?= =?UTF-8?q?ngth=20of=20custom=20property=20string=20in=20Javascript=20is?= =?UTF-8?q?=20bigger=20than=201024=20in=20Postgres=20database=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=2086303=20:=20MNT-12196=20:=20Exception=20gener?= =?UTF-8?q?ated=20in=20=E2=80=9CAccessAuditor=E2=80=9D=20when=20length=20o?= =?UTF-8?q?f=20custom=20property=20string=20in=20Javascript=20is=20bigger?= =?UTF-8?q?=20than=201024=20in=20Postgres=20database=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20=20=20-=20Add=20check=20for=20Map=20and=20Collectio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94537 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/audit/AuditComponentImpl.java | 95 +++++++++++++++---- .../repo/audit/AuditComponentTest.java | 14 +++ 2 files changed, 89 insertions(+), 20 deletions(-) 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);