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;
|
package org.alfresco.repo.audit;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -490,6 +491,78 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
return recordAuditValuesWithUserFilter(rootPath, values, true);
|
return recordAuditValuesWithUserFilter(rootPath, values, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void trimStringsIfNecessary(Object values)
|
||||||
|
{
|
||||||
|
if (values instanceof Map<?, ?>)
|
||||||
|
{
|
||||||
|
// trim string audited value
|
||||||
|
Map<String, Serializable> map = ((Map<String, Serializable>) values);
|
||||||
|
for (Map.Entry<String, Serializable> 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<Locale> 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<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
|
@Override
|
||||||
public Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter)
|
public Map<String, Serializable> recordAuditValuesWithUserFilter(String rootPath, Map<String, Serializable> values, boolean useUserFilter)
|
||||||
{
|
{
|
||||||
@@ -503,26 +576,8 @@ public class AuditComponentImpl implements AuditComponent
|
|||||||
return Collections.emptyMap();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// trim string audited value
|
// MNT-12196
|
||||||
for (Map.Entry<String, Serializable> entry : values.entrySet())
|
trimStringsIfNecessary(values);
|
||||||
{
|
|
||||||
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<Locale> locales = mltext.getLocales();
|
|
||||||
for (Locale locale : locales)
|
|
||||||
{
|
|
||||||
mltext.put(locale, SchemaBootstrap.trimStringForTextFields(mltext.getValue(locale)));
|
|
||||||
}
|
|
||||||
entry.setValue(mltext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Log inbound values
|
// Log inbound values
|
||||||
if (loggerInbound.isDebugEnabled())
|
if (loggerInbound.isDebugEnabled())
|
||||||
|
@@ -987,10 +987,24 @@ public class AuditComponentTest extends TestCase
|
|||||||
|
|
||||||
MLText mlTextValue = new MLText();
|
MLText mlTextValue = new MLText();
|
||||||
mlTextValue.put(Locale.ENGLISH, sb.toString());
|
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);
|
Map<String, Serializable> values = new HashMap<String, Serializable>(13);
|
||||||
values.put("/3.1/4.1", sb.toString());
|
values.put("/3.1/4.1", sb.toString());
|
||||||
values.put("/3.1/4.2", mlTextValue);
|
values.put("/3.1/4.2", mlTextValue);
|
||||||
|
values.put("map", map);
|
||||||
|
values.put("collection", list);
|
||||||
|
|
||||||
auditComponent.recordAuditValues("/test/one.one/two.one", values);
|
auditComponent.recordAuditValues("/test/one.one/two.one", values);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user