use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestSearchGal method binaryDataInEntry.
private void binaryDataInEntry(boolean ldap, String domainName, boolean wantSMIMECert) throws Exception {
SoapTransport transport = authUser(TestUtil.getAddress(AUTHED_USER, domainName));
Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_GAL_REQUEST);
if (wantSMIMECert) {
request.addAttribute(AccountConstants.A_NEED_SMIME_CERTS, true);
}
request.addElement(AccountConstants.E_NAME).setText(getAcctEmail(ACCOUNT_CONTAINS_BINARY_DATA, domainName));
Element response = transport.invoke(request);
List<GalContact> result = new ArrayList<GalContact>();
for (Element e : response.listElements(AdminConstants.E_CN)) {
result.add(new GalContact(AdminConstants.A_ID, SoapProvisioning.getAttrs(e)));
}
assertEquals(1, result.size());
GalContact galContact = result.get(0);
Map<String, Object> fields = galContact.getAttrs();
Object value = fields.get(BINARY_GALCONTACT_FIELD);
if (!wantSMIMECert) {
assertNull(value);
return;
}
assertTrue(value instanceof String[]);
String[] values = (String[]) value;
assertEquals(2, values.length);
boolean foundContent1 = false;
boolean foundContent2 = false;
for (String valueAsString : values) {
if (BINARY_CONTENT_1.equals(valueAsString)) {
foundContent1 = true;
}
if (BINARY_CONTENT_2.equals(valueAsString)) {
foundContent2 = true;
}
}
assertTrue(foundContent1);
assertTrue(foundContent2);
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestSetPassword method setPassword.
private String setPassword(Account authedAcct, Account targetAcct, boolean againstPolicy) throws Exception {
String newPassword = againstPolicy ? genBadPassword() : genGoodPassword();
SoapTransport transport = authAdmin(authedAcct.getName());
SetPasswordRequest req = new SetPasswordRequest(targetAcct.getId(), newPassword);
SetPasswordResponse resp = invokeJaxb(transport, req);
return newPassword;
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class SoapCLI method auth.
/**
* Authenticates using the provided ZAuthToken
* @throws IOException
* @throws com.zimbra.common.soap.SoapFaultException
* @throws ServiceException
*/
protected LmcSession auth(ZAuthToken zAuthToken) throws SoapFaultException, IOException, ServiceException {
if (zAuthToken == null)
return auth();
URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
mServerUrl = url.toExternalForm();
SoapTransport trans = getTransport();
mAuth = false;
Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
zAuthToken.encodeAuthReq(authReq, true);
try {
Element authResp = trans.invokeWithoutSession(authReq);
ZAuthToken zat = new ZAuthToken(authResp.getElement(AdminConstants.E_AUTH_TOKEN), true);
trans.setAuthToken(zat);
mAuth = true;
return new LmcSession(zat, null);
} catch (UnknownHostException e) {
// UnknownHostException's error message is not clear; rethrow with a more descriptive message
throw new IOException("Unknown host: " + mHost);
}
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class SoapCLI method auth.
/**
* Authenticates using the username and password from the local config.
* @throws IOException
* @throws com.zimbra.common.soap.SoapFaultException
* @throws ServiceException
*/
protected LmcSession auth() throws SoapFaultException, IOException, ServiceException {
URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
mServerUrl = url.toExternalForm();
SoapTransport trans = getTransport();
mAuth = false;
Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
authReq.addAttribute(AdminConstants.E_NAME, mUser, Element.Disposition.CONTENT);
authReq.addAttribute(AdminConstants.E_PASSWORD, mPassword, Element.Disposition.CONTENT);
try {
Element authResp = trans.invokeWithoutSession(authReq);
String authToken = authResp.getAttribute(AdminConstants.E_AUTH_TOKEN);
ZAuthToken zat = new ZAuthToken(null, authToken, null);
trans.setAuthToken(authToken);
mAuth = true;
return new LmcSession(zat, null);
} catch (UnknownHostException e) {
// UnknownHostException's error message is not clear; rethrow with a more descriptive message
throw new IOException("Unknown host: " + mHost);
}
}
use of com.zimbra.common.soap.SoapTransport in project zm-mailbox by Zimbra.
the class TestImapServerListener method testDestroyWaitset.
@Test
public void testDestroyWaitset() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
TestUtil.addMessage(mboxStore, "TestImapServerListener - testDestroyWaitset - init message", Integer.toString(Mailbox.ID_FOLDER_INBOX));
ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
remoteListener.addListener(session);
// wait for waitset session to be created
String waitSetId = remoteListener.getWSId();
TestUtil.waitForSessions(1, 1, 6000, waitSetId, remoteServer);
// delete waitset
ZimbraLog.test.debug("Destroying waitset %s", waitSetId);
AdminDestroyWaitSetRequest destroyReq = new AdminDestroyWaitSetRequest(waitSetId);
SoapTransport transport = TestUtil.getAdminSoapTransport(remoteServer);
AdminDestroyWaitSetResponse destroyResp = JaxbUtil.elementToJaxb(transport.invoke(JaxbUtil.jaxbToElement(destroyReq)));
Assert.assertNotNull("AdminDestroyWaitSetResponse should not be null", destroyResp);
Assert.assertNotNull("AdminDestroyWaitSetResponse::waitSetId should not be null", destroyResp.getWaitSetId());
Assert.assertEquals("AdminDestroyWaitSetResponse has wrong waitSetId", waitSetId, destroyResp.getWaitSetId());
// wait for ImapServerListener to create a new WaitSet
int maxWait = 5000;
while (maxWait > 0) {
if (remoteListener.getWSId() != null && !waitSetId.equalsIgnoreCase(remoteListener.getWSId())) {
break;
} else {
maxWait -= 500;
Thread.sleep(500);
}
}
Assert.assertFalse("ImapServerListener should have created a new waitset", waitSetId.equalsIgnoreCase(remoteListener.getWSId()));
// send a message
session.doneSignal = new CountDownLatch(1);
String subject = "TestImapServerListener - testDestroyWaitset - trigger message";
TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), TestUtil.getAddress("TestImapServerListener-testDestroyWaitset"));
TestUtil.waitForMessages(mboxStore, String.format("in:inbox is:unread \"%s\"", subject), 1, 1000);
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to NOT be triggered", session.wasTriggered());
assertFalse("ImapServerListener should have created a new waitset", remoteListener.getWSId().equalsIgnoreCase(waitSetId));
}
Aggregations