use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class GalSyncAccountUtil method addGalSyncDataSource.
private Element addGalSyncDataSource(String accountName, String dsName, String domain, String type, String folder, String pollingInterval) throws ServiceException, IOException {
mTransport = null;
try {
mTransport = new SoapHttpTransport(mAdminURL);
auth();
mTransport.setAuthToken(mAuth);
XMLElement req = new XMLElement(AdminConstants.ADD_GAL_SYNC_DATASOURCE_REQUEST);
req.addAttribute(AdminConstants.A_NAME, dsName);
req.addAttribute(AdminConstants.A_DOMAIN, domain);
req.addAttribute(AdminConstants.A_TYPE, type);
if (folder != null)
req.addAttribute(AdminConstants.E_FOLDER, folder);
Element acct = req.addElement(AdminConstants.E_ACCOUNT);
acct.addAttribute(AdminConstants.A_BY, AccountBy.name.name());
acct.setText(accountName);
if (pollingInterval != null)
req.addElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_zimbraDataSourcePollingInterval).setText(pollingInterval);
return mTransport.invokeWithoutSession(req);
} finally {
if (mTransport != null)
mTransport.shutdown();
}
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class ProxyTarget method execute.
public Pair<Element, Element> execute(Element request, ZimbraSoapContext zsc) throws ServiceException {
if (zsc == null)
return new Pair<Element, Element>(null, dispatch(request));
SoapProtocol proto = request instanceof Element.JSONElement ? SoapProtocol.SoapJS : SoapProtocol.Soap12;
if (proto == SoapProtocol.Soap12 && zsc.getRequestProtocol() == SoapProtocol.Soap11) {
proto = SoapProtocol.Soap11;
}
/* Bug 77604 When a user has been configured to change their password on next login, the resulting proxied
* ChangePasswordRequest was failing because account was specified in context but no authentication token
* was supplied. The server handler rejects a context which has account information but no authentication
* info - see ZimbraSoapContext constructor - solution is to exclude the account info from the context.
*/
boolean excludeAccountDetails = AccountConstants.CHANGE_PASSWORD_REQUEST.equals(request.getQName());
Element envelope = proto.soapEnvelope(request, zsc.toProxyContext(proto, excludeAccountDetails));
SoapHttpTransport transport = null;
try {
transport = new SoapHttpTransport(mURL);
transport.setTargetAcctId(zsc.getRequestedAccountId());
if (mMaxAttempts > 0)
transport.setRetryCount(mMaxAttempts);
if (mTimeout >= 0)
transport.setTimeout((int) Math.min(mTimeout, Integer.MAX_VALUE));
transport.setResponseProtocol(zsc.getResponseProtocol());
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
if (authToken != null && !StringUtil.isNullOrEmpty(authToken.getProxyAuthToken())) {
transport.setAuthToken(authToken.getProxyAuthToken());
}
if (ZimbraLog.soap.isDebugEnabled()) {
ZimbraLog.soap.debug("Proxying request: proxy=%s targetAcctId=%s", toString(), zsc.getRequestedAccountId());
}
disableCsrfFlagInAuthToken(envelope, authToken, request.getQName());
Element response = transport.invokeRaw(envelope);
Element body = transport.extractBodyElement(response);
return new Pair<Element, Element>(transport.getZimbraContext(), body);
} catch (IOException e) {
throw ServiceException.PROXY_ERROR(e, mURL);
} finally {
if (transport != null)
transport.shutdown();
}
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestFileUpload method testAdminUploadWithCsrfInFormField.
@Test
public void testAdminUploadWithCsrfInFormField() throws Exception {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
com.zimbra.soap.admin.message.AuthRequest req = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
req.setCsrfSupported(true);
Element response = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
String authToken = authResp.getAuthToken();
String csrfToken = authResp.getCsrfToken();
int port = 7071;
try {
port = Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraAdminPort, 0);
} catch (ServiceException e) {
ZimbraLog.test.error("Unable to get admin SOAP port", e);
}
String Url = "https://localhost:" + port + ADMIN_UPLOAD_URL;
PostMethod post = new PostMethod(Url);
FilePart part = new FilePart(FILE_NAME, new ByteArrayPartSource(FILE_NAME, "some file content".getBytes()));
Part csrfPart = new StringPart("csrfToken", csrfToken);
String contentType = "application/x-msdownload";
part.setContentType(contentType);
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
HttpState state = new HttpState();
state.addCookie(new org.apache.commons.httpclient.Cookie("localhost", ZimbraCookie.authTokenCookieName(true), authToken, "/", null, false));
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
client.setState(state);
post.setRequestEntity(new MultipartRequestEntity(new Part[] { part, csrfPart }, post.getParams()));
int statusCode = HttpClientUtil.executeMethod(client, post);
Assert.assertEquals("This request should succeed. Getting status code " + statusCode, HttpStatus.SC_OK, statusCode);
String resp = post.getResponseBodyAsString();
Assert.assertNotNull("Response should not be empty", resp);
Assert.assertTrue("Incorrect HTML response", resp.contains(RESP_STR));
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestDeployZimlet method testZipWithInvalidCharacter.
@Test
public void testZipWithInvalidCharacter() throws Exception {
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
com.zimbra.soap.admin.message.AuthRequest authReq = new com.zimbra.soap.admin.message.AuthRequest(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
authReq.setCsrfSupported(false);
Element response = transport.invoke(JaxbUtil.jaxbToElement(authReq, SoapProtocol.SoapJS.getFactory()));
com.zimbra.soap.admin.message.AuthResponse authResp = JaxbUtil.elementToJaxb(response);
String authToken = authResp.getAuthToken();
String aid = adminUpload(authToken, "jelmer.zip", "/opt/zimbra/unittest/zimlets/jelmer.zip");
assertNotNull("Attachment ID should not be null", aid);
AttachmentIdAttrib att = new AttachmentIdAttrib(aid);
transport.setAdmin(true);
transport.setAuthToken(authToken);
DeployZimletRequest deployReq = new DeployZimletRequest(AdminConstants.A_DEPLOYLOCAL, false, true, att);
Element req = JaxbUtil.jaxbToElement(deployReq);
try {
Element res = transport.invoke(req);
JaxbUtil.elementToJaxb(res);
fail("Should throw SoapFaultException");
} catch (SoapFaultException e) {
//expected
}
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestAuth method authTokenCookieMaxAge.
@Test
public void authTokenCookieMaxAge() throws Exception {
// 1 hour, has to match code in VerifyCookieExpireListener
String authTokenLifetime = "1h";
/*
* test admin Auth
*/
Account admin = provUtil.createGlobalAdmin(genAcctNameLocalPart("admin"), domain);
// set the account's auth token lifetime to a short period
admin.setAdminAuthTokenLifetime(authTokenLifetime);
SoapHttpTransport transportAdmin = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
transportAdmin.setHttpDebugListener(new VerifyCookieExpireListener(ZimbraCookie.COOKIE_ZM_ADMIN_AUTH_TOKEN));
com.zimbra.soap.admin.message.AuthRequest reqAdmin = new com.zimbra.soap.admin.message.AuthRequest(admin.getName(), "test123");
reqAdmin.setPersistAuthTokenCookie(Boolean.TRUE);
com.zimbra.soap.admin.message.AuthResponse respAdmin = invokeJaxb(transportAdmin, reqAdmin);
/*
* test account auth
*/
Account acct = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
// set the account's auth token lifetime to a short period
acct.setAuthTokenLifetime(authTokenLifetime);
SoapHttpTransport transportAcct = new SoapHttpTransport(TestUtil.getSoapUrl());
transportAcct.setHttpDebugListener(new VerifyCookieExpireListener(ZimbraCookie.COOKIE_ZM_AUTH_TOKEN));
com.zimbra.soap.account.message.AuthRequest reqAcct = new com.zimbra.soap.account.message.AuthRequest(AccountSelector.fromName(acct.getName()), "test123");
reqAcct.setPersistAuthTokenCookie(Boolean.TRUE);
com.zimbra.soap.account.message.AuthResponse respAcct = invokeJaxb(transportAcct, reqAcct);
provUtil.deleteAccount(admin);
provUtil.deleteAccount(acct);
}
Aggregations