Search in sources :

Example 6 with XMLElement

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"));
}
Also used : Cookie(javax.servlet.http.Cookie) Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement) URL(java.net.URL) ByteBuilder(com.zimbra.common.mime.HeaderUtils.ByteBuilder) Random(java.util.Random) Auth(com.zimbra.cs.service.account.Auth) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 7 with XMLElement

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();
    }
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 8 with XMLElement

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)));
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 9 with XMLElement

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)));
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement)

Example 10 with XMLElement

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);
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement)

Aggregations

XMLElement (com.zimbra.common.soap.Element.XMLElement)146 Element (com.zimbra.common.soap.Element)116 JSONElement (com.zimbra.common.soap.Element.JSONElement)33 Test (org.junit.Test)32 XmlAnyElement (javax.xml.bind.annotation.XmlAnyElement)28 XmlElement (javax.xml.bind.annotation.XmlElement)28 FilterTest (com.zimbra.soap.mail.type.FilterTest)26 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)9 HashMap (java.util.HashMap)8 KeyValuePair (com.zimbra.soap.type.KeyValuePair)7 ArrayList (java.util.ArrayList)7 Account (com.zimbra.cs.account.Account)6 ZAuthToken (com.zimbra.common.auth.ZAuthToken)5 ByteBuilder (com.zimbra.common.mime.HeaderUtils.ByteBuilder)4 ServiceException (com.zimbra.common.service.ServiceException)4 DataSource (com.zimbra.cs.account.DataSource)4 Auth (com.zimbra.cs.service.account.Auth)4 URL (java.net.URL)4 Cookie (javax.servlet.http.Cookie)4 HttpException (org.apache.http.HttpException)4