Search in sources :

Example 36 with SoapTransport

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);
}
Also used : GalContact(com.zimbra.cs.account.GalContact) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 37 with SoapTransport

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;
}
Also used : SetPasswordResponse(com.zimbra.soap.admin.message.SetPasswordResponse) SetPasswordRequest(com.zimbra.soap.admin.message.SetPasswordRequest) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 38 with SoapTransport

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Element(com.zimbra.common.soap.Element) LmcSession(com.zimbra.cs.client.LmcSession) IOException(java.io.IOException) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URL(java.net.URL) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 39 with SoapTransport

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Element(com.zimbra.common.soap.Element) LmcSession(com.zimbra.cs.client.LmcSession) IOException(java.io.IOException) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URL(java.net.URL) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 40 with SoapTransport

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));
}
Also used : ImapFolder(com.zimbra.cs.imap.ImapFolder) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) AdminDestroyWaitSetRequest(com.zimbra.soap.admin.message.AdminDestroyWaitSetRequest) AdminDestroyWaitSetResponse(com.zimbra.soap.admin.message.AdminDestroyWaitSetResponse) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Aggregations

SoapTransport (com.zimbra.common.soap.SoapTransport)89 Test (org.junit.Test)69 Account (com.zimbra.cs.account.Account)38 Element (com.zimbra.common.soap.Element)24 Group (com.zimbra.cs.account.Group)23 ServiceException (com.zimbra.common.service.ServiceException)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 AccountServiceException (com.zimbra.cs.account.AccountServiceException)11 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)10 ArrayList (java.util.ArrayList)10 SoapProtocol (com.zimbra.common.soap.SoapProtocol)9 Bug (com.zimbra.qa.QA.Bug)9 CreateSignatureRequest (com.zimbra.soap.account.message.CreateSignatureRequest)9 Signature (com.zimbra.soap.account.type.Signature)9 Domain (com.zimbra.cs.account.Domain)8 GetDistributionListRequest (com.zimbra.soap.account.message.GetDistributionListRequest)8 GetDistributionListResponse (com.zimbra.soap.account.message.GetDistributionListResponse)6