use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.
the class FileUploadServletTest method testFileUploadAuthTokenCsrfEnabled.
@Test
public void testFileUploadAuthTokenCsrfEnabled() throws Exception {
URL url = new URL("http://localhost:7070/service/upload?lbfums=");
ByteBuilder bb = new ByteBuilder(CharsetUtil.UTF_8);
addFormField(bb, "_charset_", "");
addFormField(bb, "filename1", filename1);
addFormFile(bb, filename1, "text/plain", content1);
endForm(bb);
byte[] form = bb.toByteArray();
HashMap<String, String> headers = new HashMap<String, String>();
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
XMLElement req = new XMLElement(AccountConstants.AUTH_REQUEST);
req.addAttribute(AccountConstants.A_CSRF_SUPPORT, "1");
com.zimbra.common.soap.Element a = req.addUniqueElement(AccountConstants.E_ACCOUNT);
a.addAttribute(AccountConstants.A_BY, "name");
a.setText(acct.getName());
req.addUniqueElement(AccountConstants.E_PASSWORD).setText("secret");
Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
MockHttpServletRequest authReq = (MockHttpServletRequest) context.get(SoapServlet.SERVLET_REQUEST);
authReq.setAttribute(Provisioning.A_zimbraCsrfTokenCheckEnabled, Boolean.TRUE);
Random nonceGen = new Random();
authReq.setAttribute(CsrfFilter.CSRF_SALT, nonceGen.nextInt() + 1);
Element response = new Auth().handle(req, context);
String authToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
String csrfToken = response.getElement("csrfToken").getText();
headers.put(Constants.CSRF_TOKEN, csrfToken);
MockHttpServletRequest mockreq = new MockHttpServletRequest(form, url, "multipart/form-data; boundary=" + boundary, 7070, "test", headers);
mockreq.setAttribute(CsrfFilter.CSRF_TOKEN_CHECK, Boolean.TRUE);
Cookie cookie = new Cookie("ZM_AUTH_TOKEN", authToken);
mockreq.setCookies(cookie);
MockHttpServletResponse resp = new MockHttpServletResponse();
servlet.doPost(mockreq, resp);
String respStrg = resp.output.toString();
System.out.println(respStrg);
assertTrue(respStrg.contains("200"));
}
use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.
the class FbCli method pushFreeBusyForDomain.
public void pushFreeBusyForDomain(String domain) throws ServiceException, IOException, HttpException {
try {
auth();
XMLElement req = new XMLElement(AdminConstants.PUSH_FREE_BUSY_REQUEST);
req.addElement(AdminConstants.E_DOMAIN).addAttribute(AdminConstants.A_NAME, domain);
mTransport.invoke(req);
} finally {
mTransport.shutdown();
}
}
use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.
the class SoapAccount method reload.
public void reload(SoapProvisioning prov) throws ServiceException {
XMLElement req = new XMLElement(AdminConstants.GET_ACCOUNT_REQUEST);
Element a = req.addElement(AdminConstants.E_ACCOUNT);
a.setText(getId());
a.addAttribute(AdminConstants.A_BY, AccountBy.id.name());
setAttrs(SoapProvisioning.getAttrs(prov.invoke(req).getElement(AdminConstants.E_ACCOUNT)));
}
use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.
the class SoapCalendarResource method modifyAttrs.
public void modifyAttrs(SoapProvisioning prov, Map<String, ? extends Object> attrs, boolean checkImmutable) throws ServiceException {
XMLElement req = new XMLElement(AdminConstants.MODIFY_CALENDAR_RESOURCE_REQUEST);
req.addElement(AdminConstants.E_ID).setText(getId());
SoapProvisioning.addAttrElements(req, attrs);
setAttrs(SoapProvisioning.getAttrs(prov.invoke(req).getElement(AdminConstants.E_CALENDAR_RESOURCE)));
}
use of com.zimbra.common.soap.Element.XMLElement in project zm-mailbox by Zimbra.
the class SoapDynamicGroup method modifyAttrs.
public void modifyAttrs(SoapProvisioning prov, Map<String, ? extends Object> attrs, boolean checkImmutable) throws ServiceException {
XMLElement req = new XMLElement(AdminConstants.MODIFY_DISTRIBUTION_LIST_REQUEST);
req.addElement(AdminConstants.E_ID).setText(getId());
SoapProvisioning.addAttrElements(req, attrs);
Element dl = prov.invoke(req).getElement(AdminConstants.E_DL);
Map<String, Object> newAttrs = SoapProvisioning.getAttrs(dl);
addDlm(dl, newAttrs);
setAttrs(newAttrs);
}
Aggregations