use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TestServiceServlet method testDeployAdminExtension.
@Test
public void testDeployAdminExtension() throws Exception {
deployAdminVersionCheck();
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
HttpClient client = new HttpClient();
String url = baseURL + "deployzimlet";
PostMethod method = new PostMethod(url);
addAuthTokenHeader(method, mbox.getAuthToken().getValue());
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_phone");
//standard zimlet, should always be there. No harm in redeploying it
File zimletFile = new File("/opt/zimbra/zimlets/com_zimbra_adminversioncheck.zip");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
int respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting error code with user's auth token", HttpStatus.SC_UNAUTHORIZED, respCode);
method = new PostMethod(url);
addAuthTokenHeader(method, getAdminAuthToken(delegatedAdminWithRights.getName()));
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_adminversioncheck");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting code 401 with permitted delegated admin's auth token", HttpStatus.SC_UNAUTHORIZED, respCode);
method = new PostMethod(url);
addAuthTokenHeader(method, getAdminAuthToken(delegatedAdminWithoutRights.getName()));
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_adminversioncheck");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting code 401 with unpermitted delegated admin's auth token", HttpStatus.SC_UNAUTHORIZED, respCode);
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TestServiceServlet method testDeployZimlet.
@Test
public void testDeployZimlet() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
HttpClient client = new HttpClient();
String url = baseURL + "deployzimlet";
PostMethod method = new PostMethod(url);
addAuthTokenHeader(method, mbox.getAuthToken().getValue());
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_phone");
//standard zimlet, should always be there. No harm in redeploying it
File zimletFile = new File("/opt/zimbra/zimlets/com_zimbra_phone.zip");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
int respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting error code with user's auth token", HttpStatus.SC_UNAUTHORIZED, respCode);
method = new PostMethod(url);
addAuthTokenHeader(method, AuthProvider.getAdminAuthToken().getEncoded());
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_phone");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting code 200 with super admin's auth token", HttpStatus.SC_OK, respCode);
method = new PostMethod(url);
addAuthTokenHeader(method, getAdminAuthToken(delegatedAdminWithRights.getName()));
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_phone");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting code 200 with permitted delegated admin's auth token", HttpStatus.SC_OK, respCode);
method = new PostMethod(url);
addAuthTokenHeader(method, getAdminAuthToken(delegatedAdminWithoutRights.getName()));
method.addRequestHeader(ZimletUtil.PARAM_ZIMLET, "com_zimbra_phone");
if (zimletFile.exists()) {
InputStream targetStream = new FileInputStream(zimletFile);
method.setRequestBody(targetStream);
}
respCode = HttpClientUtil.executeMethod(client, method);
Assert.assertEquals("Should be getting code 401 with unpermitted delegated admin's auth token", HttpStatus.SC_UNAUTHORIZED, respCode);
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class ExchangeFreeBusyProvider method formAuth.
private boolean formAuth(HttpClient client, ServerInfo info) throws IOException {
StringBuilder buf = new StringBuilder();
buf.append("destination=");
buf.append(URLEncoder.encode(info.url, "UTF-8"));
buf.append("&username=");
buf.append(info.authUsername);
buf.append("&password=");
buf.append(URLEncoder.encode(info.authPassword, "UTF-8"));
buf.append("&flags=0");
buf.append("&SubmitCreds=Log On");
buf.append("&trusted=0");
String url = info.url + LC.calendar_exchange_form_auth_url.value();
PostMethod method = new PostMethod(url);
ByteArrayRequestEntity re = new ByteArrayRequestEntity(buf.toString().getBytes(), "x-www-form-urlencoded");
method.setRequestEntity(re);
HttpState state = new HttpState();
client.setState(state);
try {
int status = HttpClientUtil.executeMethod(client, method);
if (status >= 400) {
ZimbraLog.fb.error("form auth to Exchange returned an error: " + status);
return false;
}
} finally {
method.releaseConnection();
}
return true;
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TestCalDav method doFreeBusyCheck.
public HttpMethodExecutor doFreeBusyCheck(Account organizer, List<Account> attendees, Date start, Date end) throws ServiceException, IOException {
HttpClient client = new HttpClient();
String outboxurl = getSchedulingOutboxUrl(organizer, organizer);
PostMethod postMethod = new PostMethod(outboxurl);
postMethod.addRequestHeader("Content-Type", "text/calendar");
postMethod.addRequestHeader("Originator", "mailto:" + organizer.getName());
for (Account attendee : attendees) {
postMethod.addRequestHeader("Recipient", "mailto:" + attendee.getName());
}
addBasicAuthHeaderForUser(postMethod, organizer);
String fbIcal = makeFreeBusyRequestIcal(organizer, attendees, start, end);
postMethod.setRequestEntity(new ByteArrayRequestEntity(fbIcal.getBytes(), MimeConstants.CT_TEXT_CALENDAR));
return HttpMethodExecutor.execute(client, postMethod, HttpStatus.SC_OK);
}
use of org.apache.commons.httpclient.methods.PostMethod in project zm-mailbox by Zimbra.
the class TestCalDav method testPostToSchedulingOutbox.
@Test
public void testPostToSchedulingOutbox() throws Exception {
Account dav1 = users[1].create();
Account dav2 = users[2].create();
Account dav3 = users[3].create();
String url = getSchedulingOutboxUrl(dav1, dav1);
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
addBasicAuthHeaderForUser(method, dav1);
method.addRequestHeader("Content-Type", "text/calendar");
method.addRequestHeader("Originator", "mailto:" + dav1.getName());
method.addRequestHeader("Recipient", "mailto:" + dav2.getName());
method.addRequestHeader("Recipient", "mailto:" + dav3.getName());
method.setRequestEntity(new ByteArrayRequestEntity(exampleCancelIcal(dav1, dav2, dav3).getBytes(), MimeConstants.CT_TEXT_CALENDAR));
HttpMethodExecutor.execute(client, method, HttpStatus.SC_OK);
}
Aggregations