use of org.apache.jackrabbit.webdav.client.methods.DeleteMethod in project lobcder by skoulouzis.
the class Utils method deleteResource.
void deleteResource(String resource, boolean mustSucceed) throws IOException {
DeleteMethod delete = new DeleteMethod(resource);
int status = this.client.executeMethod(delete);
if (mustSucceed) {
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT);
} else {
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_FOUND);
}
}
use of org.apache.jackrabbit.webdav.client.methods.DeleteMethod 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());
// }
// }
}
use of org.apache.jackrabbit.webdav.client.methods.DeleteMethod in project lobcder by skoulouzis.
the class WebDAVTest method testGetDataDistribution.
@Test
public void testGetDataDistribution() throws UnsupportedEncodingException, IOException, DavException {
System.out.println("testGetDataDistribution");
String testcol1 = root + "testResourceForGetDataDistribution/";
String testuri1 = testcol1 + "file1";
String testuri2 = testcol1 + "file2";
String testuri3 = testcol1 + "file3";
String testcol2 = testcol1 + "folder4/";
String testuri4 = testcol2 + "file5";
try {
DeleteMethod delete = new DeleteMethod(testcol1);
int status = client.executeMethod(delete);
MkColMethod mkcol = new MkColMethod(testcol1);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
PutMethod put = new PutMethod(testuri1);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri2);
put.setRequestEntity(new StringRequestEntity("dar", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri3);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(testcol2);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri4);
put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
DavPropertyNameSet d = new DavPropertyNameSet();
DavPropertyName dataDist = DavPropertyName.create("data-distribution", Namespace.getNamespace("custom:"));
d.add(dataDist);
PropFindMethod propFind = new PropFindMethod(testcol1, d, DavConstants.DEPTH_INFINITY);
status = client.executeMethod(propFind);
assertEquals(HttpStatus.SC_MULTI_STATUS, status);
MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
for (MultiStatusResponse r : responses) {
// System.out.println("Response: " + r.getHref());
DavPropertySet allProp = utils.getProperties(r);
DavPropertyIterator iter = allProp.iterator();
while (iter.hasNext()) {
DavProperty<?> p = iter.nextProperty();
System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
// System.out.println("\tName: " + dataDist);
// System.out.println("\tName: " + dataDist.getName());
// System.out.println("\tName: " + dataDist.getNamespace());
assertEquals(dataDist.getName(), p.getName().getName());
assertNotNull(p.getValue());
}
}
} finally {
utils.deleteResource(testcol1, true);
}
}
use of org.apache.jackrabbit.webdav.client.methods.DeleteMethod in project lobcder by skoulouzis.
the class WebDAVTest method testPutIfLockToken.
@Test
public void testPutIfLockToken() throws HttpException, IOException, DavException, URISyntaxException {
String testuri = root + "iflocktest";
String locktoken = null;
int status;
try {
PutMethod put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("1"));
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT);
LockMethod lock = new LockMethod(testuri, new LockInfo(org.apache.jackrabbit.webdav.lock.Scope.EXCLUSIVE, org.apache.jackrabbit.webdav.lock.Type.WRITE, "testcase", 10000, true));
status = client.executeMethod(lock);
assertEquals("status", HttpStatus.SC_OK, status);
locktoken = lock.getLockToken();
assertNotNull(locktoken);
// try to read without lock token
GetMethod get = new GetMethod(testuri);
status = client.executeMethod(get);
assertEquals("status", HttpStatus.SC_OK, status);
// try to overwrite without lock token
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
status = client.executeMethod(put);
assertEquals("status: " + status, 423, status);
// try to overwrite using bad lock token
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
put.setRequestHeader("If", "(<" + "DAV:foobar" + ">)");
status = client.executeMethod(put);
assertEquals("status: " + status, 412, status);
// try to overwrite using correct lock token, using No-Tag-list format
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("2"));
put.setRequestHeader("If", "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
get = new GetMethod(testuri);
status = client.executeMethod(get);
assertEquals("status", HttpStatus.SC_OK, status);
String responce = get.getResponseBodyAsString();
assertEquals("2", responce);
// try to overwrite using correct lock token, using Tagged-list format
// and full URI
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("3"));
put.setRequestHeader("If", "<" + testuri + ">" + "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
// try to overwrite using correct lock token, using Tagged-list format
// and absolute path only
put = new PutMethod(testuri);
put.setRequestEntity(new StringRequestEntity("4"));
put.setRequestHeader("If", "<" + new URI(testuri).getRawPath() + ">" + "(<" + locktoken + ">)");
status = client.executeMethod(put);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED);
// // try to overwrite using correct lock token, using Tagged-list format
// // and bad path
// put = new PutMethod(testuri);
// put.setRequestEntity(new StringRequestEntity("5"));
// put.setRequestHeader("If", "</foobar>" + "(<" + locktoken + ">)");
// status = client.executeMethod(put);
// assertTrue("status: " + status, status == HttpStatus.SC_NOT_FOUND || status == 412);
UnLockMethod unlock = new UnLockMethod(testuri, "wrong");
status = client.executeMethod(unlock);
assertTrue("status: " + status, status == HttpStatus.SC_FAILED_DEPENDENCY || status == HttpStatus.SC_PRECONDITION_FAILED);
unlock = new UnLockMethod(testuri, locktoken);
status = client.executeMethod(unlock);
assertTrue("status: " + status, status == HttpStatus.SC_NO_CONTENT);
} finally {
DeleteMethod delete = new DeleteMethod(testuri);
if (locktoken != null) {
delete.setRequestHeader("If", "(<" + locktoken + ">)");
}
status = client.executeMethod(delete);
assertTrue("status: " + status, status == HttpStatus.SC_OK || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_FOUND);
}
}
use of org.apache.jackrabbit.webdav.client.methods.DeleteMethod in project lobcder by skoulouzis.
the class WebDAVTest method testGetSetDRISupervisedProp.
@Test
public void testGetSetDRISupervisedProp() throws UnsupportedEncodingException, IOException, DavException {
System.out.println("testGetSetDRISupervisedProp");
String testcol1 = root + "testResourceForGetSetDRISupervisedPro/";
String testuri1 = testcol1 + "file1";
String testuri2 = testcol1 + "file2";
String testuri3 = testcol1 + "file3";
String testcol2 = testcol1 + "folder4/";
String testuri4 = testcol2 + "file5";
Boolean v;
try {
DeleteMethod delete = new DeleteMethod(testcol1);
int status = client.executeMethod(delete);
MkColMethod mkcol = new MkColMethod(testcol1);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
PutMethod put = new PutMethod(testuri1);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri2);
put.setRequestEntity(new StringRequestEntity("dar", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri3);
put.setRequestEntity(new StringRequestEntity("foo", "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
mkcol = new MkColMethod(testcol2);
status = client.executeMethod(mkcol);
assertEquals(HttpStatus.SC_CREATED, status);
put = new PutMethod(testuri4);
put.setRequestEntity(new StringRequestEntity(TestSettings.TEST_DATA, "text/plain", "UTF-8"));
status = client.executeMethod(put);
assertEquals(HttpStatus.SC_CREATED, status);
DavPropertyNameSet driSupervisedNameSet = new DavPropertyNameSet();
DavPropertyName driSupervisedName = DavPropertyName.create("dri-supervised", Namespace.getNamespace("custom:"));
driSupervisedNameSet.add(driSupervisedName);
PropFindMethod propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
status = client.executeMethod(propFind);
assertEquals(HttpStatus.SC_MULTI_STATUS, status);
MultiStatus multiStatus = propFind.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
for (MultiStatusResponse r : responses) {
// System.out.println("Response: " + r.getHref());
DavPropertySet allProp = utils.getProperties(r);
DavPropertyIterator iter = allProp.iterator();
while (iter.hasNext()) {
DavProperty<?> p = iter.nextProperty();
assertEquals(p.getName(), driSupervisedName);
// System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
assertNotNull(p.getValue());
v = Boolean.valueOf(Boolean.valueOf((String) p.getValue()));
assertFalse(v);
}
}
DavPropertySet driSuper = new DavPropertySet();
DavProperty<Boolean> driProp = new DefaultDavProperty<Boolean>(driSupervisedName, Boolean.TRUE);
driSuper.add(driProp);
PropPatchMethod proPatch = new PropPatchMethod(testcol1, driSuper, driSupervisedNameSet);
status = client.executeMethod(proPatch);
assertEquals(HttpStatus.SC_MULTI_STATUS, status);
// multiStatus = proPatch.getResponseBodyAsMultiStatus();
// responses = multiStatus.getResponses();
//
// for (MultiStatusResponse r : responses) {
// System.out.println("Response: " + r.getHref());
// DavPropertySet allProp = utils.getProperties(r);
//
// DavPropertyIterator iter = allProp.iterator();
// while (iter.hasNext()) {
// DavProperty<?> p = iter.nextProperty();
// System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
// }
// }
propFind = new PropFindMethod(testcol1, driSupervisedNameSet, DavConstants.DEPTH_INFINITY);
status = client.executeMethod(propFind);
assertEquals(HttpStatus.SC_MULTI_STATUS, status);
multiStatus = propFind.getResponseBodyAsMultiStatus();
responses = multiStatus.getResponses();
for (MultiStatusResponse r : responses) {
DavPropertySet allProp = utils.getProperties(r);
DavPropertyIterator iter = allProp.iterator();
while (iter.hasNext()) {
DavProperty<?> p = iter.nextProperty();
assertEquals(p.getName(), driSupervisedName);
System.out.println("\tName: " + p.getName() + " Values " + p.getValue());
assertNotNull(p.getValue());
boolean val = Boolean.valueOf(p.getValue().toString());
if (new URL(testcol1).getPath().equals(r.getHref())) {
assertTrue(val);
} else {
assertFalse(val);
}
}
}
} finally {
utils.deleteResource(testcol1, true);
}
}
Aggregations