diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
index 7c1a972bc9..bdae2bc7aa 100644
--- a/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
+++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/caveat-context.xml
@@ -17,7 +17,8 @@
-
+
+
diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
index 69e980cb76..546309510a 100644
--- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
+++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSON.java
@@ -36,6 +36,7 @@ import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.Malform
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroupType;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatMark;
+import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.io.IOUtils;
@@ -78,6 +79,7 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
/** The location of the configuration file relative to the classpath. */
private String configLocation;
+ private DictionaryService dictionaryService;
private NamespaceService namespaceService;
/** Set the location of the configuration file relative to the classpath. */
@@ -90,6 +92,10 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
{
this.namespaceService = service;
}
+ public void setDictionaryService(DictionaryService service)
+ {
+ this.dictionaryService = service;
+ }
/**
* {@inheritDoc}
@@ -224,12 +230,40 @@ public class CaveatDAOFromJSON implements CaveatDAOInterface
// Instantiate the group (and associate the marks with the group).
CaveatGroup caveatGroup = new CaveatGroup(id, displayLabelKey, descriptionKey,
- modelProperty == null ? null : createQName(modelProperty, namespaceService),
+ validatedPropertyName(modelProperty),
caveatGroupType, caveatMarks);
return caveatGroup;
}
+ /**
+ * Validates that the provided qname string is a valid model property.
+ * @param qnameString the short form qname string e.g. {@code cm:content} or {@code null}.
+ * @return the valid {@link QName} or {@code null} if the qnameString was {@code null}.
+ * @throws MalformedConfiguration if the provided qnameString was not {@code null} and was not a valid property name.
+ */
+ private QName validatedPropertyName(String qnameString)
+ {
+ if (qnameString == null)
+ {
+ return null;
+ }
+ else
+ {
+ final QName qname = createQName(qnameString, namespaceService);
+ final boolean isProperty = dictionaryService.getProperty(qname) != null;
+
+ if (isProperty)
+ {
+ return qname;
+ }
+ else
+ {
+ throw new MalformedConfiguration("Property name not recognised: '" + qnameString + "'");
+ }
+ }
+ }
+
/**
* Create a caveat mark from the supplied JSON. This does not set the group id of the caveat mark.
*
diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
index 758a5a15ef..0c822a8227 100644
--- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
+++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/caveat/dao/CaveatDAOFromJSONUnitTest.java
@@ -21,6 +21,7 @@ package org.alfresco.module.org_alfresco_module_rm.caveat.dao;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,7 +30,10 @@ import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.caveat.CaveatException.MalformedConfiguration;
import org.alfresco.module.org_alfresco_module_rm.caveat.scheme.CaveatGroup;
+import org.alfresco.service.cmr.dictionary.DictionaryService;
+import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
@@ -49,6 +53,11 @@ public class CaveatDAOFromJSONUnitTest
NamespaceService namespaceService = mock(NamespaceService.class);
when(namespaceService.getNamespaceURI(anyString())).thenReturn("{mockedNamespace}");
+ DictionaryService dictionaryService = mock(DictionaryService.class);
+ PropertyDefinition mockProperty = mock(PropertyDefinition.class);
+ when(dictionaryService.getProperty(any(QName.class))).thenReturn(mockProperty);
+
+ caveatDAOFromJSON.setDictionaryService(dictionaryService);
caveatDAOFromJSON.setNamespaceService(namespaceService);
}