Search in sources :

Example 41 with UsernamePasswordCredentials

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

the class CreateGroupTest method testCreateGroupResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
public void testCreateGroupResponseAsJSON() throws IOException, JsonException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.json";
    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    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 42 with UsernamePasswordCredentials

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

the class CreateUserTest method testCreateUserMissingUserId.

@Test
public void testCreateUserMissingUserId() throws IOException {
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) 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 43 with UsernamePasswordCredentials

use of org.apache.commons.httpclient.UsernamePasswordCredentials 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 44 with UsernamePasswordCredentials

use of org.apache.commons.httpclient.UsernamePasswordCredentials 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 45 with UsernamePasswordCredentials

use of org.apache.commons.httpclient.UsernamePasswordCredentials 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)

Aggregations

UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)113 Credentials (org.apache.commons.httpclient.Credentials)97 ArrayList (java.util.ArrayList)65 NameValuePair (org.apache.commons.httpclient.NameValuePair)61 JsonObject (javax.json.JsonObject)52 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)51 Test (org.junit.Test)51 JsonArray (javax.json.JsonArray)19 HttpClient (org.apache.commons.httpclient.HttpClient)19 AuthScope (org.apache.commons.httpclient.auth.AuthScope)17 HashSet (java.util.HashSet)14 GetMethod (org.apache.commons.httpclient.methods.GetMethod)14 HttpException (org.apache.commons.httpclient.HttpException)9 IOException (java.io.IOException)8 HttpMethod (org.apache.commons.httpclient.HttpMethod)8 HttpState (org.apache.commons.httpclient.HttpState)6 PostMethod (org.apache.commons.httpclient.methods.PostMethod)6 URL (java.net.URL)5 RepositoryException (org.apache.sling.ide.transport.RepositoryException)5 Header (org.apache.commons.httpclient.Header)4