use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class AccessPrivilegesInfoTest 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);
}
for (String script : toDelete) {
H.getTestClient().delete(script);
}
}
use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class GetAclTest method testEffectiveAclForUser.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclForUser() throws IOException, JsonException {
testUserId = H.createTestUser();
testUserId2 = 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);
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId2));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testUserId2));
postParams.add(new NameValuePair("privilege@jcr:lockManagement", "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:write");
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
JsonObject aceObject2 = jsonObject.getJsonObject(testUserId2);
assertNotNull(aceObject2);
String principalString2 = aceObject2.getString("principal");
assertEquals(testUserId2, principalString2);
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:write");
H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:lockManagement");
Object deniedArray2 = aceObject2.get("denied");
assertNull(deniedArray2);
}
use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class GetAclTest method testEffectiveAclMergeForUser_SubsetOfPrivilegesDeniedOnChild2.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclMergeForUser_SubsetOfPrivilegesDeniedOnChild2() 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:all", "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:removeNode", "denied"));
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);
assertTrue(grantedArray.size() >= 11);
Set<String> grantedPrivilegeNames = new HashSet<String>();
for (int i = 0; i < grantedArray.size(); i++) {
grantedPrivilegeNames.add(grantedArray.getString(i));
}
H.assertPrivilege(grantedPrivilegeNames, false, "jcr:all");
H.assertPrivilege(grantedPrivilegeNames, false, "jcr:write");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:read");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:readAccessControl");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyAccessControl");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:lockManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:versionManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:nodeTypeManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:retentionManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:lifecycleManagement");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:modifyProperties");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:addChildNodes");
H.assertPrivilege(grantedPrivilegeNames, true, "jcr:removeChildNodes");
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:removeNode");
}
use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class GetAclTest method testEffectiveAclMergeForUser_SupersetOfPrivilegesDeniedOnChild2.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclMergeForUser_SupersetOfPrivilegesDeniedOnChild2() 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:modifyProperties", "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", "denied"));
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);
Object grantedArray = aceObject.get("granted");
assertNull(grantedArray);
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:all");
}
use of org.apache.commons.httpclient.NameValuePair in project sling by apache.
the class GetAclTest method testEffectiveAclMergeForUser_ReplacePrivilegeOnChild.
/**
* Test for SLING-2600, Effective ACL servlet returns incorrect information
*/
@Test
public void testEffectiveAclMergeForUser_ReplacePrivilegeOnChild() 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", "denied"));
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:write", "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:write");
Object deniedArray = aceObject.get("denied");
assertNull(deniedArray);
}
Aggregations