use of javax.json.JsonArray in project sling by apache.
the class GetAclTest method testEffectiveAclMergeForUser_MorePrivilegesGrantedOnChild.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclMergeForUser_MorePrivilegesGrantedOnChild() throws IOException, JsonException {
testUserId = H.createTestUser();
String testFolderUrl = H.createTestFolder("{ \"jcr:primaryType\": \"nt:unstructured\", \"propOne\" : \"propOneValue\", \"child\" : { \"childPropOne\" : true } }");
String postUrl = testFolderUrl + ".modifyAce.html";
//1. create an initial set of privileges
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:all", "granted"));
postUrl = testFolderUrl + "/child.modifyAce.html";
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the eacl to verify the settings.
String getUrl = testFolderUrl + "/child.eacl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:all");
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
}
use of javax.json.JsonArray in project sling by apache.
the class ModifyAceTest method testMergeAceForUserDenyPrivilegeAfterGrantPrivilege.
/**
* Test ACE update with a deny privilege for an ACE that already contains
* a grant privilege
*/
@Test
public void testMergeAceForUserDenyPrivilegeAfterGrantPrivilege() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.html";
//1. create an initial set of privileges
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(1, jsonObject.size());
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(testUserId, aceObject.getString("principal"));
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:write");
assertFalse(aceObject.containsKey("denied"));
//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:write is not posted, so it should remain in the granted ACE
//deny the jcr:nodeTypeManagement privilege, which should merge with the
//existing ACE.
//add a new privilege
postParams2.add(new NameValuePair("privilege@jcr:nodeTypeManagement", "denied"));
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 = JsonUtil.parseObject(json2);
assertEquals(1, jsonObject2.size());
JsonObject aceObject2 = jsonObject2.getJsonObject(testUserId);
assertNotNull(aceObject2);
assertEquals(testUserId, aceObject2.getString("principal"));
JsonArray grantedArray2 = aceObject2.getJsonArray("granted");
assertNotNull(grantedArray2);
assertEquals(1, grantedArray2.size());
Set<String> grantedPrivilegeNames2 = new HashSet<String>();
for (int i = 0; i < grantedArray2.size(); i++) {
grantedPrivilegeNames2.add(grantedArray2.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:write");
JsonArray deniedArray2 = aceObject2.getJsonArray("denied");
assertNotNull(deniedArray2);
assertEquals(1, deniedArray2.size());
Set<String> deniedPrivilegeNames2 = new HashSet<String>();
for (int i = 0; i < deniedArray2.size(); i++) {
deniedPrivilegeNames2.add(deniedArray2.getString(i));
}
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:nodeTypeManagement");
}
use of javax.json.JsonArray in project sling by apache.
the class ModifyAceTest method testMergeAceForUserSplitAggregatePrincipal.
/**
* Test for SLING-997, preserve privileges that were not posted with the modifyAce
* request.
*/
@Test
public void testMergeAceForUserSplitAggregatePrincipal() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.html";
//1. create an initial set of privileges
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(1, jsonObject.size());
JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(testUserId, aceObject.getString("principal"));
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
JsonArray deniedArray = aceObject.getJsonArray("denied");
assertNotNull(deniedArray);
assertEquals(1, deniedArray.size());
Set<String> deniedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < deniedArray.size(); i++) {
deniedPrivilegeNames.add(deniedArray.getString(i));
}
H.assertPrivilege(deniedPrivilegeNames, true, "jcr:write");
//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 is not posted, so it should remain in the granted ACE
//add a new privilege
postParams2.add(new NameValuePair("privilege@jcr:modifyProperties", "granted"));
//jcr:write is not posted, but one of the aggregate privileges is now granted, so the aggregate priviledge should be disagreaged into
// the remaining denied privileges in the denied ACE
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 = JsonUtil.parseObject(json2);
assertEquals(1, jsonObject2.size());
JsonObject aceObject2 = jsonObject2.getJsonObject(testUserId);
assertNotNull(aceObject2);
assertEquals(testUserId, aceObject2.getString("principal"));
JsonArray grantedArray2 = aceObject2.getJsonArray("granted");
assertNotNull(grantedArray2);
assertEquals(2, grantedArray2.size());
Set<String> grantedPrivilegeNames2 = new HashSet<String>();
for (int i = 0; i < grantedArray2.size(); i++) {
grantedPrivilegeNames2.add(grantedArray2.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:modifyProperties");
JsonArray deniedArray2 = aceObject2.getJsonArray("denied");
assertNotNull(deniedArray2);
assertEquals(3, deniedArray2.size());
Set<String> deniedPrivilegeNames2 = new HashSet<String>();
for (int i = 0; i < deniedArray2.size(); i++) {
deniedPrivilegeNames2.add(deniedArray2.getString(i));
}
H.assertPrivilege(deniedPrivilegeNames2, false, "jcr:write");
//only the remaining privileges from the disaggregated jcr:write collection should remain.
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:addChildNodes");
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:removeNode");
H.assertPrivilege(deniedPrivilegeNames2, true, "jcr:removeChildNodes");
}
use of javax.json.JsonArray in project sling by apache.
the class PostServletImportTest method assertExpectedJSON.
protected void assertExpectedJSON(JsonObject expectedJson, JsonObject actualJson) throws JsonException {
Iterator<String> keys = expectedJson.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
Object object = expectedJson.get(key);
Object object2 = actualJson.get(key);
if (object instanceof JsonObject) {
assertTrue(object2 instanceof JsonObject);
assertExpectedJSON((JsonObject) object, (JsonObject) object2);
} else if (object instanceof JsonArray) {
//compare the array
assertTrue(object2 instanceof JsonArray);
JsonArray actualArray = (JsonArray) object2;
Set<Object> actualValuesSet = new HashSet<Object>();
for (int i = 0; i < actualArray.size(); i++) {
actualValuesSet.add(actualArray.get(i));
}
JsonArray expectedArray = (JsonArray) object;
for (int i = 0; i < expectedArray.size(); i++) {
assertTrue(actualValuesSet.contains(expectedArray.get(i)));
}
} else {
assertEquals("Value of key: " + key, object, object2);
}
}
}
use of javax.json.JsonArray in project sling by apache.
the class ReferenceTypeHintTest method getPropertyArray.
private String[] getPropertyArray(String url, String name) throws Exception {
JsonObject jo = JsonUtil.parseObject(getContent(url + "/" + name + ".json", CONTENT_TYPE_JSON));
JsonArray arr = jo.getJsonArray(name);
String[] result = new String[arr.size()];
for (int i = 0; i < arr.size(); i++) {
result[i] = arr.getString(i);
}
return result;
}
Aggregations