use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestDeployZimlet method testEmptyAid.
@Test
public void testEmptyAid() 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();
transport.setAdmin(true);
transport.setAuthToken(authToken);
AttachmentIdAttrib att = new AttachmentIdAttrib("");
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 TestUtil method getAdminSoapTransport.
/**
* Returns an authenticated transport for the <tt>zimbra</tt> account.
*/
public static SoapTransport getAdminSoapTransport() throws SoapFaultException, IOException, ServiceException {
SoapHttpTransport transport = new SoapHttpTransport(getAdminSoapUrl());
// Create auth element
Element auth = new XMLElement(AdminConstants.AUTH_REQUEST);
auth.addNonUniqueElement(AdminConstants.E_NAME).setText(LC.zimbra_ldap_user.value());
auth.addNonUniqueElement(AdminConstants.E_PASSWORD).setText(LC.zimbra_ldap_password.value());
// Authenticate and get auth token
Element response = transport.invoke(auth);
String authToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
transport.setAuthToken(authToken);
transport.setAdmin(true);
return transport;
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestAuth method OAuth.
@Test
public void OAuth() throws Exception {
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
Element eAuthReq = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
// <authtoken>
Element eAuthToken = eAuthReq.addElement(AccountConstants.E_AUTH_TOKEN);
eAuthToken.addAttribute(AccountConstants.A_TYPE, "oauth");
String accessToken = "whatever";
Element eAccessToken = eAuthToken.addElement(AccountConstants.E_A);
eAccessToken.addAttribute(AccountConstants.A_N, ZimbraOAuthProvider.OAUTH_ACCESS_TOKEN);
eAccessToken.setText(accessToken);
// <account>
Element eAcct = eAuthReq.addElement(AccountConstants.E_ACCOUNT);
eAcct.addAttribute(AccountConstants.A_BY, AccountBy.name.name());
eAcct.setText(acct.getName());
Element eResp = transport.invoke(eAuthReq);
Element eAuthTokenResp = eResp.getElement(AccountConstants.E_AUTH_TOKEN);
String authToken = eAuthTokenResp.getText();
assertNotNull(authToken);
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestAutoProvision method authRequestByKrb5.
/*
* Note: need to restart server each time before re-run. Otherwise server would still
* have the account created in previous run cached.
*/
@Test
// need to setup KDC
@Ignore
public void authRequestByKrb5() throws Exception {
String testName = getTestName();
String externalPassword = "test456";
String extAcctLocalPart = testName;
String extAcctName = createExternalAcctEntry(extAcctLocalPart, externalPassword, null);
String krb5Realm = "MYREALM";
Map<String, Object> zimbraDomainAttrs = commonZimbraDomainAttrs();
// setup auto prov
StringUtil.addToMultiMap(zimbraDomainAttrs, Provisioning.A_zimbraAutoProvAuthMech, AutoProvAuthMech.KRB5.name());
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchBase, extDomainDn);
zimbraDomainAttrs.put(Provisioning.A_zimbraAutoProvLdapSearchFilter, "(uid=%u)");
// setup auth mech and krb5 realm on domain
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthMech, AuthMech.kerberos5.name());
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthKerberos5Realm, krb5Realm);
zimbraDomainAttrs.put(Provisioning.A_zimbraAuthKerberos5Realm, krb5Realm);
Domain zimbraDomain = createZimbraDomain(testName, zimbraDomainAttrs);
String loginName = extAcctLocalPart + "@" + krb5Realm;
// make the soap request
SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
request.addElement(AccountConstants.E_ACCOUNT).addAttribute(AccountConstants.A_BY, AccountBy.krb5Principal.name()).setText(loginName);
request.addElement(AccountConstants.E_PASSWORD).setText(externalPassword);
Element response = transport.invoke(request);
String encodedAuthToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
assertNotNull(encodedAuthToken);
String acctId = getAuthTokenAcctId(encodedAuthToken);
Account acct = prov.get(AccountBy.id, acctId);
verifyAcctAutoProvisioned(acct, loginName.toLowerCase());
}
use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.
the class TestFileUpload method testAdminUploadWithCsrfInHeader.
@Test
public void testAdminUploadWithCsrfInHeader() 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()));
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 }, post.getParams()));
post.addRequestHeader(Constants.CSRF_TOKEN, csrfToken);
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));
}
Aggregations