use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testAddAceOrderByNumeric.
/**
* Test to verify adding an ACE at a specific index inside
* the ACL
*/
@Test
public void testAddAceOrderByNumeric() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "0");
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(0, group.getInt("order"));
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(1, user.getInt("order"));
//add another principal between the testGroupId and testUserId
testUserId2 = H.createTestUser();
addOrUpdateAce(testFolderUrl, testUserId2, true, "1");
String json2 = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json2);
JsonObject jsonObject2 = JsonUtil.parseObject(json2);
assertEquals(3, jsonObject2.size());
JsonObject group2 = jsonObject2.getJsonObject(testGroupId);
assertNotNull(group2);
assertEquals(testGroupId, group2.getString("principal"));
assertEquals(0, group2.getInt("order"));
JsonObject user3 = jsonObject2.getJsonObject(testUserId2);
assertNotNull(user3);
assertEquals(testUserId2, user3.getString("principal"));
assertEquals(1, user3.getInt("order"));
JsonObject user2 = jsonObject2.getJsonObject(testUserId);
assertNotNull(user2);
assertEquals(testUserId, user2.getString("principal"));
assertEquals(2, user2.getInt("order"));
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testUpdateAcePreservePosition.
/**
* Test to make sure modifying an existing ace without changing the order
* leaves the ACE in the same position in the ACL
*/
@Test
public void testUpdateAcePreservePosition() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "first");
//update the ace to make sure the update does not change the ACE order
addOrUpdateAce(testFolderUrl, testGroupId, false, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = testFolderUrl + ".acl.json";
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertEquals(2, jsonObject.size());
JsonObject group = jsonObject.getJsonObject(testGroupId);
assertNotNull(group);
assertEquals(testGroupId, group.getString("principal"));
assertEquals(0, group.getInt("order"));
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(1, user.getInt("order"));
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testMergeAceForUserGrantNestedAggregatePrivilegeAfterDenySuperAggregatePrivilege.
/**
* Test for SLING-3010
*/
@Test
public void testMergeAceForUserGrantNestedAggregatePrivilegeAfterDenySuperAggregatePrivilege() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.json";
//1. setup an initial set of denied privileges for the test user
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "denied"));
postParams.add(new NameValuePair("privilege@jcr:read", "denied"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied"));
postParams.add(new NameValuePair("privilege@rep:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//2. now grant the jcr:write subset from the rep:write aggregate privilege
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "granted"));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));
//sub-aggregate of rep:write
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//3. verify that the acl has the correct values
//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(4, 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:versionManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:write");
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));
}
//the leftovers from the denied rep:write that were not granted with jcr:write
H.assertPrivilege(deniedPrivilegeNames, true, "jcr:nodeTypeManagement");
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testMergeAceForUserGrantAggregatePrivilegePartsAfterDenyAggregatePrivilege.
/**
* Test for SLING-3010
*/
@Test
public void testMergeAceForUserGrantAggregatePrivilegePartsAfterDenyAggregatePrivilege() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.json";
//1. setup an initial set of denied privileges for the test user
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "denied"));
postParams.add(new NameValuePair("privilege@jcr:read", "denied"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "denied"));
postParams.add(new NameValuePair("privilege@rep:write", "denied"));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//2. now grant the all the privileges contained in the rep:write privilege
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId));
postParams.add(new NameValuePair("privilege@jcr:versionManagement", "granted"));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));
//sub-privilege of rep:write
postParams.add(new NameValuePair("privilege@jcr:nodeTypeManagement", "granted"));
//sub-aggregate of rep:write
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
/*String json = */
H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//3. verify that the acl has the correct values
//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);
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
//jcr:nodeTypeManagement + jcr:write
H.assertPrivilege(grantedPrivilegeNames, true, "rep:write");
assertEquals("Expecting the correct number of privileges in " + grantedPrivilegeNames, 4, grantedPrivilegeNames.size());
//should be nothing left in the denied set.
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
}
use of javax.json.JsonObject in project sling by apache.
the class ModifyAceTest method testModifyAceForUser.
@Test
public void testModifyAceForUser() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
String postUrl = testFolderUrl + ".modifyAce.html";
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"));
//invalid value should be ignored.
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "bogus"));
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);
String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
int order = aceObject.getInt("order");
assertEquals(0, order);
JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals(1, grantedArray.size());
assertEquals("jcr:read", grantedArray.getString(0));
JsonArray deniedArray = aceObject.getJsonArray("denied");
assertNotNull(deniedArray);
assertEquals(1, deniedArray.size());
assertEquals("jcr:write", deniedArray.getString(0));
}
Aggregations