Search in sources :

Example 86 with UsernamePasswordCredentials

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

the class AuthenticationResponseCodeTest method testValidatingIncorrectHttpBasicCredentials.

@Test
public void testValidatingIncorrectHttpBasicCredentials() throws Exception {
    // assume http and webdav are on the same host + port
    URL url = new URL(HttpTest.HTTP_BASE_URL);
    Credentials defaultcreds = new UsernamePasswordCredentials("garbage", "garbage");
    H.getHttpClient().getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new NameValuePair("j_validate", "true"));
    HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_FORBIDDEN, params, null);
    assertXReason(post);
    HttpMethod get = H.assertHttpStatus(HttpTest.HTTP_BASE_URL + "/?j_validate=true", HttpServletResponse.SC_FORBIDDEN);
    assertXReason(get);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) AuthScope(org.apache.commons.httpclient.auth.AuthScope) ArrayList(java.util.ArrayList) URL(java.net.URL) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) HttpMethod(org.apache.commons.httpclient.HttpMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 87 with UsernamePasswordCredentials

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

the class ModifyAceTest method testAddAceOrderByFirst.

/**
	 * Test to verify adding an ACE in the first position of 
	 * the ACL
	 */
@Test
public void testAddAceOrderByFirst() throws IOException, JsonException {
    createAceOrderTestFolderWithOneAce();
    testGroupId = H.createTestGroup();
    addOrUpdateAce(testFolderUrl, testGroupId, true, "first");
    //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)

Example 88 with UsernamePasswordCredentials

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

the class RemoveAcesTest method testRemoveAcesResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
public void testRemoveAcesResponseAsJSON() throws IOException, JsonException {
    String folderUrl = createFolderWithAces(true);
    //remove the ace for the testUser principal
    String postUrl = folderUrl + ".deleteAce.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair(":applyTo", testUserId));
    postParams.add(new NameValuePair(":applyTo", 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 jsonObject = JsonUtil.parseObject(json);
    assertNotNull(jsonObject);
}
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 89 with UsernamePasswordCredentials

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

the class ModifyAceTest method testModifyAceResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
@Test
public void testModifyAceResponseAsJSON() throws IOException, JsonException {
    testUserId = H.createTestUser();
    testFolderUrl = H.createTestFolder();
    String postUrl = testFolderUrl + ".modifyAce.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("principalId", testUserId));
    postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
    postParams.add(new NameValuePair("privilege@jcr:write", "denied"));
    //invalid value should be ignored.
    postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "bogus"));
    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 jsonObject = JsonUtil.parseObject(json);
    assertNotNull(jsonObject);
}
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 90 with UsernamePasswordCredentials

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

the class ModifyAceTest method testAddAceOrderByAfter.

/**
	 * Test to verify adding an ACE after an existing ACE 
	 * the ACL
	 */
@Test
public void testAddAceOrderByAfter() throws IOException, JsonException {
    createAceOrderTestFolderWithOneAce();
    testGroupId = H.createTestGroup();
    addOrUpdateAce(testFolderUrl, testGroupId, true, "after " + testUserId);
    //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 user = jsonObject.getJsonObject(testUserId);
    assertNotNull(user);
    assertEquals(testUserId, user.getString("principal"));
    assertEquals(0, user.getInt("order"));
    JsonObject group = jsonObject.getJsonObject(testGroupId);
    assertNotNull(group);
    assertEquals(testGroupId, group.getString("principal"));
    assertEquals(1, group.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

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