use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class ModifyAceTest method addOrUpdateAce.
/**
* Helper to add or update an ace for testing
*/
private void addOrUpdateAce(String folderUrl, String principalId, boolean readGranted, String order) throws IOException, JsonException {
String postUrl = folderUrl + ".modifyAce.html";
//1. create an initial set of privileges
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", principalId));
postParams.add(new NameValuePair("privilege@jcr:read", readGranted ? "granted" : "denied"));
postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
if (order != null) {
postParams.add(new NameValuePair("order", order));
}
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
use of org.apache.commons.httpclient.NameValuePair 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 org.apache.commons.httpclient.NameValuePair 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 org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class ModifyAceTest method cleanup.
@After
public void cleanup() throws Exception {
H.tearDown();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
if (testFolderUrl != null) {
//remove the test user if it exists.
String postUrl = testFolderUrl;
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":operation", "delete"));
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testGroupId != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testUserId != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
if (testUserId2 != null) {
//remove the test user if it exists.
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId2 + ".delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
}
}
use of org.apache.commons.httpclient.NameValuePair 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