Search in sources :

Example 61 with Credentials

use of org.apache.commons.httpclient.Credentials in project maven-plugins by apache.

the class AbstractCheckDocumentationMojo method setupProxy.

/**
     * Setup proxy access if needed.
     */
private void setupProxy() {
    Proxy settingsProxy = settings.getActiveProxy();
    if (settingsProxy != null) {
        String proxyUsername = settingsProxy.getUsername();
        String proxyPassword = settingsProxy.getPassword();
        String proxyHost = settingsProxy.getHost();
        int proxyPort = settingsProxy.getPort();
        if (StringUtils.isNotEmpty(proxyHost)) {
            httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
            getLog().info("Using proxy [" + proxyHost + "] at port [" + proxyPort + "].");
            if (StringUtils.isNotEmpty(proxyUsername)) {
                getLog().info("Using proxy user [" + proxyUsername + "].");
                Credentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
                httpClient.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), creds);
                httpClient.getParams().setAuthenticationPreemptive(true);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy) AuthScope(org.apache.commons.httpclient.auth.AuthScope) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 62 with Credentials

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

the class CreateGroupTest method testCreateGroup.

public void testCreateGroup() throws IOException, JsonException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the group profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(testGroupId, jsonObj.getString("marker"));
}
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 63 with Credentials

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

the class CreateGroupTest method testCreateGroupWithExtraProperties.

public void testCreateGroupWithExtraProperties() throws IOException, JsonException {
    String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
    testGroupId = "testGroup" + random.nextInt();
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":name", testGroupId));
    postParams.add(new NameValuePair("marker", testGroupId));
    postParams.add(new NameValuePair("displayName", "My Test Group"));
    postParams.add(new NameValuePair("url", "http://www.apache.org"));
    assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the group profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(testGroupId, jsonObj.getString("marker"));
    assertEquals("My Test Group", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org", jsonObj.getString("url"));
}
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 64 with Credentials

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

the class CreateUserTest method testCreateUserResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
@Test
public void testCreateUserResponseAsJSON() throws IOException, JsonException {
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";
    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"));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.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) 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 65 with Credentials

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

the class CreateUserTest method testCreateUser.

/*
		<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>
		   <input type="submit" value="Submit" />
		</form>
	 */
@Test
public void testCreateUser() throws IOException, JsonException {
    testUserId = "testUser" + random.nextInt() + System.currentTimeMillis();
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
    final 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"));
    final Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    H.assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    {
        // fetch the user profile json to verify the settings
        final String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
        final String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
        assertNotNull(json);
        final JsonObject jsonObj = JsonUtil.parseObject(json);
        assertEquals(testUserId, jsonObj.getString("marker"));
        assertFalse(jsonObj.containsKey(":name"));
        assertFalse(jsonObj.containsKey("pwd"));
        assertFalse(jsonObj.containsKey("pwdConfirm"));
    }
    {
        // fetch the session info to verify that the user can log in
        final Credentials newUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
        final String getUrl = HttpTest.HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
        final String json = H.getAuthenticatedContent(newUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
        assertNotNull(json);
        final JsonObject jsonObj = JsonUtil.parseObject(json);
        assertEquals(testUserId, jsonObj.getString("userID"));
    }
}
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)

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