Search in sources :

Example 36 with Credentials

use of org.apache.commons.httpclient.Credentials in project sling by apache.

the class RemoveAuthorizablesTest method testRemoveUser.

public void testRemoveUser() throws IOException {
    String userId = createTestUser();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
    String postUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".delete.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 37 with Credentials

use of org.apache.commons.httpclient.Credentials in project sling by apache.

the class RemoveAuthorizablesTest method testRemoveAuthorizablesResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
public void testRemoveAuthorizablesResponseAsJSON() throws IOException, JsonException {
    String userId = createTestUser();
    String groupId = createTestGroup();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String postUrl = HTTP_BASE_URL + "/system/userManager.delete.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
    postParams.add(new NameValuePair(":applyTo", "user/" + userId));
    String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
    //make sure the json response can be parsed as a JSON object
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 38 with Credentials

use of org.apache.commons.httpclient.Credentials in project sling by apache.

the class RemoveAuthorizablesTest method testRemoveGroup.

public void testRemoveGroup() throws IOException {
    String groupId = createTestGroup();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
    String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".delete.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 39 with Credentials

use of org.apache.commons.httpclient.Credentials 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"));
}
Also used : JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 40 with Credentials

use of org.apache.commons.httpclient.Credentials 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"));
}
Also used : JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

Credentials (org.apache.commons.httpclient.Credentials)102 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)102 ArrayList (java.util.ArrayList)64 NameValuePair (org.apache.commons.httpclient.NameValuePair)64 JsonObject (javax.json.JsonObject)52 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)51 Test (org.junit.Test)51 JsonArray (javax.json.JsonArray)19 AuthScope (org.apache.commons.httpclient.auth.AuthScope)17 HashSet (java.util.HashSet)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 HttpClient (org.apache.commons.httpclient.HttpClient)11 URL (java.net.URL)9 HttpMethod (org.apache.commons.httpclient.HttpMethod)5 IOException (java.io.IOException)4 HttpState (org.apache.commons.httpclient.HttpState)4 After (org.junit.After)4 InputStream (java.io.InputStream)3 Header (org.apache.commons.httpclient.Header)3 HttpException (org.apache.commons.httpclient.HttpException)3