List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.AccessPrivilegesInfoTest.java
/** * Test the fix for SLING-1090//from www.j a v a 2 s. c om */ @Test public void testSLING_1090() throws Exception { testUserId = H.createTestUser(); //grant jcr: removeChildNodes to the root node ArrayList<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:removeChildNodes", "granted")); Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin"); H.assertAuthenticatedPostStatus(adminCreds, HttpTest.HTTP_BASE_URL + "/.modifyAce.html", HttpServletResponse.SC_OK, postParams, null); //create a node as a child of the root folder testFolderUrl = H.getTestClient().createNode(HttpTest.HTTP_BASE_URL + "/testFolder" + random.nextInt() + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null); String postUrl = testFolderUrl + ".modifyAce.html"; //grant jcr:removeNode to the test node postParams = new ArrayList<NameValuePair>(); postParams.add(new NameValuePair("principalId", testUserId)); postParams.add(new NameValuePair("privilege@jcr:read", "granted")); postParams.add(new NameValuePair("privilege@jcr:removeNode", "granted")); H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null); //fetch the JSON for the test page to verify the settings. String getUrl = testFolderUrl + ".privileges-info.json"; Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd"); String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK); assertNotNull(json); JSONObject jsonObj = new JSONObject(json); assertEquals(true, jsonObj.getBoolean("canDelete")); }
From source file:org.apache.sling.launchpad.webapp.integrationtest.accessManager.GetAclTest.java
/** * Test for SLING-2600, Effective ACL servlet returns incorrect information *///from w w w. j av a 2s . c o m @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 = new JSONObject(json); JSONObject aceObject = jsonObject.optJSONObject(testUserId); assertNotNull(aceObject); String principalString = aceObject.optString("principal"); assertEquals(testUserId, principalString); JSONArray grantedArray = aceObject.optJSONArray("granted"); assertNotNull(grantedArray); assertEquals(1, 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:write"); JSONArray deniedArray = aceObject.optJSONArray("denied"); assertNull(deniedArray); JSONObject aceObject2 = jsonObject.optJSONObject(testUserId2); assertNotNull(aceObject2); String principalString2 = aceObject2.optString("principal"); assertEquals(testUserId2, principalString2); JSONArray grantedArray2 = aceObject2.optJSONArray("granted"); assertNotNull(grantedArray2); assertEquals(2, 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:write"); H.assertPrivilege(grantedPrivilegeNames2, true, "jcr:lockManagement"); JSONArray deniedArray2 = aceObject2.optJSONArray("denied"); assertNull(deniedArray2); }