assertEquals(testUserId, principalString);
int order = aceObject.optInt("order");
assertEquals(0, order);
JSONArray grantedArray = aceObject.optJSONArray("granted");
assertNotNull(grantedArray);
assertEquals(3, grantedArray.length());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i=0; i < grantedArray.length(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:readAccessControl");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:addChildNodes");
JSONArray deniedArray = aceObject.optJSONArray("denied");
assertNotNull(deniedArray);
assertEquals(2, deniedArray.length());
Set<String> deniedPrivilegeNames = new HashSet<String>();
for (int i=0; i < deniedArray.length(); i++) {
deniedPrivilegeNames.add(deniedArray.getString(i));
}
H.assertPrivilege(deniedPrivilegeNames, true, "jcr:modifyAccessControl");
H.assertPrivilege(deniedPrivilegeNames, true, "jcr:removeChildNodes");
//2. post a new set of privileges to merge with the existing privileges
List<NameValuePair> postParams2 = new ArrayList<NameValuePair>();
postParams2.add(new NameValuePair("principalId", testUserId));
//jcr:read and jcr:addChildNodes are not posted, so they should remain in the granted ACE
postParams2.add(new NameValuePair("privilege@jcr:readAccessControl", "none")); //clear the existing privilege
postParams2.add(new NameValuePair("privilege@jcr:modifyProperties", "granted")); //add a new privilege
//jcr:modifyAccessControl is not posted, so it should remain in the denied ACE
postParams2.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied")); //deny the modifyAccessControl privilege
postParams2.add(new NameValuePair("privilege@jcr:removeChildNodes", "none")); //clear the existing privilege
postParams2.add(new NameValuePair("privilege@jcr:removeNode", "denied")); //deny a new privilege
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams2, null);
//fetch the JSON for the acl to verify the settings.
String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json2);
JSONObject jsonObject2 = new JSONObject(json2);
assertEquals(1, jsonObject2.length());
JSONObject aceObject2 = jsonObject2.optJSONObject(testUserId);
assertNotNull(aceObject2);
String principalString2 = aceObject2.optString("principal");
assertEquals(testUserId, principalString2);
JSONArray grantedArray2 = aceObject2.optJSONArray("granted");
assertNotNull(grantedArray2);
assertEquals(3, grantedArray2.length());
Set<String> grantedPrivilegeNames2 = new HashSet<String>();
for (int i=0; i < grantedArray2.length(); i++) {
grantedPrivilegeNames2.add(grantedArray2.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:addChildNodes");
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:modifyProperties");
JSONArray deniedArray2 = aceObject2.optJSONArray("denied");
assertNotNull(deniedArray2);
assertEquals(2, deniedArray2.length());
Set<String> deniedPrivilegeNames2 = new HashSet<String>();
for (int i=0; i < deniedArray2.length(); i++) {
deniedPrivilegeNames2.add(deniedArray2.getString(i));
}
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:modifyAccessControl");
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:removeNode");
}