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);
}
}
}
}
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"));
}
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"));
}
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);
}
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"));
}
}
Aggregations