use of org.apache.jackrabbit.webdav.security.AclProperty.Ace in project lobcder by skoulouzis.
the class WebDAVSecurityTest method testAclMethod.
// @Test
// public void testGetCurrentUserPrivilegeSet() throws UnsupportedEncodingException, IOException, DavException {
// String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
// try {
//
// DeleteMethod delete = new DeleteMethod(testFileURI1);
// int status = client1.executeMethod(delete);
//
//
// PutMethod put = new PutMethod(testFileURI1);
// put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
// status = client1.executeMethod(put);
// assertEquals(HttpStatus.SC_CREATED, status);
//
// DavPropertyNameSet d = new DavPropertyNameSet();
// DavPropertyName userPriv = DavPropertyName.create("current-user-privilege-set");
// d.add(userPriv);
//
// PropFindMethod propFind = new PropFindMethod(testFileURI1, d, DavConstants.DEPTH_INFINITY);
// status = client1.executeMethod(propFind);
// assertEquals(HttpStatus.SC_MULTI_STATUS, status);
//
//
// MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
// MultiStatusResponse[] responses = multiStatus.getResponses();
//
// for (MultiStatusResponse r : responses) {
// System.out.println("Responce: " + r.getHref());
// DavPropertySet allProp = getProperties(r);
//
// DavPropertyIterator iter = allProp.iterator();
// while (iter.hasNext()) {
// DavProperty<?> p = iter.nextProperty();
// System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
// }
// }
//
// assertEquals(HttpStatus.SC_OK, responses[0].getStatus()[0].getStatusCode());
// DavPropertySet allProp = getProperties(responses[0]);
// DavProperty<?> prop = allProp.get(userPriv);
// assertEquals(userPriv, prop.getName());
//
// // ArrayList<org.apache.xerces.dom.DeferredElementNSImpl> value = (ArrayList<org.apache.xerces.dom.DeferredElementNSImpl>) prop.getValue();
// // for(org.apache.xerces.dom.DeferredElementNSImpl el : value){
// // System.out.println("DeferredElementNSImpl: "+el.getBaseURI());
// // System.out.println("getLocalName: "+el.getLocalName());
// // System.out.println("getNodeValue: "+el.getNodeValue());
// // }
// // String value = (String) prop.getValue();
// // assertTrue(value.contains("READ") || value.contains("ALL"));
// System.out.println("Name: " + prop.getName() + " Values " + prop.getValue() + " class: " + prop.getValue().getClass().getName() + " " + prop.getValue().getClass().getName());
// } finally {
// DeleteMethod delete = new DeleteMethod(testFileURI1);
// int status = client1.executeMethod(delete);
// assertTrue("DeleteMethod status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT);
// }
// }
//
// @Test
// public void testUnothorizedCreateFile() {
// try {
// String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1 + ".txt";
// PutMethod put = new PutMethod(testFileURI1);
// put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
//
// client2.getState().setCredentials(
// new AuthScope(uri.getHost(), uri.getPort()),
// new UsernamePasswordCredentials(username2, "WRONG_PASSWORD"));
//
// int status = client2.executeMethod(put);
// assertEquals(HttpStatus.SC_UNAUTHORIZED, status);
//
// } catch (IOException ex) {
// Logger.getLogger(WebDAVSecurityTest.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
//
// @Test
// public void testGetSetACL() throws IOException, DavException {
// String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
// DeleteMethod del = new DeleteMethod(testFileURI1);
// client1.executeMethod(del);
//
// PutMethod put = new PutMethod(testFileURI1);
// put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
// int status = client1.executeMethod(put);
// assertEquals(HttpStatus.SC_CREATED, status);
//
// DavPropertyNameSet d = new DavPropertyNameSet();
// d.add(SecurityConstants.ACL);
// PropFindMethod propFind = new PropFindMethod(testFileURI1, d, DavConstants.DEPTH_INFINITY);
//
// status = client1.executeMethod(propFind);
// assertEquals(HttpStatus.SC_MULTI_STATUS, status);
//
//
// MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
// MultiStatusResponse[] responses = multiStatus.getResponses();
//
// for (MultiStatusResponse r : responses) {
// System.out.println("Responce: " + r.getHref());
// DavPropertySet allProp = getProperties(r);
//
// DavPropertyIterator iter = allProp.iterator();
// while (iter.hasNext()) {
// DavProperty<?> p = iter.nextProperty();
// // assertNotNull(p.getValue());
// System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
// }
//
// }
// }
@Test
public void testAclMethod() throws IOException, DavException {
String testFileURI1 = uri.toASCIIString() + TestSettings.TEST_FILE_NAME1;
DeleteMethod del = new DeleteMethod(testFileURI1);
client1.executeMethod(del);
PutMethod put = new PutMethod(testFileURI1);
put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
int status = client1.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
Privilege[] privs = new Privilege[] { Privilege.PRIVILEGE_WRITE, // /Privilege.getPrivilege("schedule-query-freebusy", SecurityConstants.NAMESPACE)
Privilege.PRIVILEGE_READ };
Principal principal = Principal.getHrefPrincipal(username1);
Ace ace1 = AclProperty.createGrantAce(principal, privs, false, false, null);
Principal principal2 = Principal.getHrefPrincipal("someUser");
Ace ace2 = AclProperty.createDenyAce(principal2, privs, true, true, null);
AclMethod acl = new AclMethod(testFileURI1, new AclProperty(new Ace[] { ace1, ace2 }));
Header[] headers = acl.getRequestHeaders();
for (Header h : headers) {
System.out.println("getRequestHeaders: " + h.getName() + " : " + h.getValue());
}
status = client1.executeMethod(acl);
// assertEquals(HttpStatus.SC_OK, status);
// DavPropertyNameSet d = new DavPropertyNameSet();
// d.add(SecurityConstants.ACL);
// // d.add(SecurityConstants.ACL_RESTRICTIONS);
// // d.add(SecurityConstants.ALTERNATE_URI_SET);
// // d.add(SecurityConstants.CURRENT_USER_PRIVILEGE_SET);
// // d.add(SecurityConstants.GROUP);
// // d.add(SecurityConstants.GROUP_MEMBERSHIP);
// // d.add(SecurityConstants.GROUP_MEMBER_SET);
// // d.add(SecurityConstants.INHERITED_ACL_SET);
// // d.add(SecurityConstants.OWNER);
// // d.add(SecurityConstants.PRINCIPAL_COLLECTION_SET);
// // d.add(SecurityConstants.PRINCIPAL_URL);
// // d.add(SecurityConstants.SUPPORTED_PRIVILEGE_SET);
// PropFindMethod propFind = new PropFindMethod(testFileURI1, d, DavConstants.DEPTH_INFINITY);
//
// status = client1.executeMethod(propFind);
// assertEquals(HttpStatus.SC_MULTI_STATUS, status);
//
//
// MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
// MultiStatusResponse[] responses = multiStatus.getResponses();
//
// for (MultiStatusResponse r : responses) {
// System.out.println("Responce: " + r.getHref());
// DavPropertySet allProp = getProperties(r);
//
// DavPropertyIterator iter = allProp.iterator();
// while (iter.hasNext()) {
// DavProperty<?> p = iter.nextProperty();
// assertNotNull(p.getValue());
// System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
// }
// }
}
Aggregations