use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class ModifyAceTest method testAddAceOrderByBefore.
/**
* Test to verify adding an ACE before an existing ACE
* the ACL
*/
@Test
public void testAddAceOrderByBefore() throws IOException, JsonException {
createAceOrderTestFolderWithOneAce();
testGroupId = H.createTestGroup();
addOrUpdateAce(testFolderUrl, testGroupId, true, "before " + 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 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"));
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class ModifyAceTest method createAceOrderTestFolderWithOneAce.
/**
* Helper to create a test folder with a single ACE pre-created
*/
private void createAceOrderTestFolderWithOneAce() throws IOException, JsonException {
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
addOrUpdateAce(testFolderUrl, testUserId, true, null);
//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(1, jsonObject.size());
JsonObject user = jsonObject.getJsonObject(testUserId);
assertNotNull(user);
assertEquals(testUserId, user.getString("principal"));
assertEquals(0, user.getInt("order"));
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class RemoveAcesTest method testRemoveAces.
//test removing multiple aces
public void testRemoveAces() throws IOException, JsonException {
String folderUrl = createFolderWithAces(true);
//remove the ace for the testUser principal
String postUrl = folderUrl + ".deleteAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", testUserId));
postParams.add(new NameValuePair(":applyTo", testGroupId));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = folderUrl + ".acl.json";
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
assertEquals(0, jsonObject.size());
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class AnonymousAccessTest method testAnonymousContent.
public void testAnonymousContent() throws Exception {
// disable credentials -> anonymous session
final URL url = new URL(HTTP_BASE_URL);
final AuthScope scope = new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM);
httpClient.getParams().setAuthenticationPreemptive(false);
httpClient.getState().setCredentials(scope, null);
try {
assertContent();
} finally {
// re-enable credentials -> admin session
httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
httpClient.getState().setCredentials(scope, defaultcreds);
}
}
use of org.apache.commons.httpclient.Credentials in project sling by apache.
the class RemoveAcesTest method testRemoveAce.
//test removing a single ace
public void testRemoveAce() throws IOException, JsonException {
String folderUrl = createFolderWithAces(false);
//remove the ace for the testUser principal
String postUrl = folderUrl + ".deleteAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", testUserId));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = folderUrl + ".acl.json";
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
assertEquals(0, jsonObject.size());
}
Aggregations