Search in sources :

Example 96 with Credentials

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

the class CreateUserTest method testCreateUserWithExtraProperties.

/*
	<form action="/system/userManager/user.create.html" method="POST">
	   <div>Name: <input type="text" name=":name" value="testUser" /></div>
	   <div>Password: <input type="text" name="pwd" value="testUser" /></div>
	   <div>Password Confirm: <input type="text" name="pwdConfirm" value="testUser" /></div>
	   <div>Extra Property #1: <input type="text" name="displayName" value="My Test User" /></div>
	   <div>Extra Property #2: <input type="text" name="url" value="http://www.apache.org" /></div>
	   <input type="submit" value="Submit" />
	</form>
	*/
@Test
public void testCreateUserWithExtraProperties() throws IOException, JsonException {
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
    testUserId = "testUser" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testUserId));
    postParams.add(new NameValuePair("marker", testUserId));
    postParams.add(new NameValuePair("pwd", "testPwd"));
    postParams.add(new NameValuePair("pwdConfirm", "testPwd"));
    postParams.add(new NameValuePair("displayName", "My Test User"));
    postParams.add(new NameValuePair("url", "http://www.apache.org"));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the user profile json to verify the settings
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
    String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(testUserId, jsonObj.getString("marker"));
    assertEquals("My Test User", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org", jsonObj.getString("url"));
    assertFalse(jsonObj.containsKey(":name"));
    assertFalse(jsonObj.containsKey("pwd"));
    assertFalse(jsonObj.containsKey("pwdConfirm"));
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) 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 97 with Credentials

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

the class RemoveAuthorizablesTest method testRemoveAuthorizables.

public void testRemoveAuthorizables() throws IOException {
    String userId = createTestUser();
    String groupId = createTestGroup();
    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);
    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.delete.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
    postParams.add(new NameValuePair(":applyTo", "user/" + userId));
    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);
    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 98 with Credentials

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

the class RemoveAuthorizablesTest method testRemoveGroupWithMembers.

/**
	 * Test the problem reported as SLING-1237
	 */
public void testRemoveGroupWithMembers() throws IOException {
    String groupId = createTestGroup();
    String userId = createTestUser();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String addMemberPostUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".update.html";
    List<NameValuePair> addMemberPostParams = new ArrayList<NameValuePair>();
    addMemberPostParams.add(new NameValuePair(":member", userId));
    assertAuthenticatedPostStatus(creds, addMemberPostUrl, HttpServletResponse.SC_OK, addMemberPostParams, null);
    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 99 with Credentials

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

the class UpdateGroupTest method testUpdateGroupMembers.

public void testUpdateGroupMembers() throws IOException, JsonException {
    testGroupId = createTestGroup();
    testUserId = createTestUser();
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    // verify that the members array exists, but is empty
    JsonArray members = getTestGroupMembers(creds);
    assertEquals(0, members.size());
    JsonArray memberships = getTestUserMemberships(creds);
    assertEquals(0, memberships.size());
    String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
    // add a group member
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":member", testUserId));
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    members = getTestGroupMembers(creds);
    assertEquals(1, members.size());
    assertEquals("/system/userManager/user/" + testUserId, members.getString(0));
    memberships = getTestUserMemberships(creds);
    assertEquals(1, memberships.size());
    assertEquals("/system/userManager/group/" + testGroupId, memberships.getString(0));
    // delete a group member
    postParams.clear();
    postParams.add(new NameValuePair(":member@Delete", testUserId));
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    members = getTestGroupMembers(creds);
    assertEquals(0, members.size());
    memberships = getTestUserMemberships(creds);
    assertEquals(0, memberships.size());
}
Also used : JsonArray(javax.json.JsonArray) 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 100 with Credentials

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

the class UserPrivilegesInfoTest 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);
    }
    for (String script : toDelete) {
        H.getTestClient().delete(script);
    }
}
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) After(org.junit.After)

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