Search in sources :

Example 11 with SoapHttpTransport

use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.

the class GetQuotaUsage method delegateRequestToAllServers.

private List<AccountQuota> delegateRequestToAllServers(final Element request, final ZAuthToken authToken, String sortBy, boolean sortAscending, Provisioning prov) throws ServiceException {
    // first set "allServers" to false
    request.addAttribute(AdminConstants.A_ALL_SERVERS, false);
    // don't set any "limit" in the delegated requests
    request.addAttribute(AdminConstants.A_LIMIT, 0);
    request.addAttribute(AdminConstants.A_OFFSET, 0);
    List<Server> servers = prov.getAllMailClientServers();
    // make number of threads in pool configurable?
    ExecutorService executor = Executors.newFixedThreadPool(10);
    List<Future<List<AccountQuota>>> futures = new LinkedList<Future<List<AccountQuota>>>();
    for (final Server server : servers) {
        futures.add(executor.submit(new Callable<List<AccountQuota>>() {

            @Override
            public List<AccountQuota> call() throws Exception {
                ZimbraLog.misc.debug("Invoking %s on server %s", AdminConstants.E_GET_QUOTA_USAGE_REQUEST, server.getName());
                String adminUrl = URLUtil.getAdminURL(server, AdminConstants.ADMIN_SERVICE_URI);
                SoapHttpTransport mTransport = new SoapHttpTransport(adminUrl);
                mTransport.setAuthToken(authToken);
                Element resp;
                try {
                    resp = mTransport.invoke(request.clone());
                } catch (Exception e) {
                    throw new Exception("Error in invoking " + AdminConstants.E_GET_QUOTA_USAGE_REQUEST + " on server " + server.getName(), e);
                }
                List<Element> accountElts = resp.getPathElementList(new String[] { AdminConstants.E_ACCOUNT });
                List<AccountQuota> retList = new ArrayList<AccountQuota>();
                for (Element accountElt : accountElts) {
                    AccountQuota quota = new AccountQuota();
                    quota.name = accountElt.getAttribute(AdminConstants.A_NAME);
                    quota.id = accountElt.getAttribute(AdminConstants.A_ID);
                    quota.quotaUsed = accountElt.getAttributeLong(AdminConstants.A_QUOTA_USED);
                    quota.quotaLimit = accountElt.getAttributeLong(AdminConstants.A_QUOTA_LIMIT);
                    quota.percentQuotaUsed = quota.quotaLimit > 0 ? (quota.quotaUsed / (float) quota.quotaLimit) : 0;
                    retList.add(quota);
                }
                return retList;
            }
        }));
    }
    shutdownAndAwaitTermination(executor);
    // Aggregate all results
    List<AccountQuota> retList = new ArrayList<AccountQuota>();
    for (Future<List<AccountQuota>> future : futures) {
        List<AccountQuota> result;
        try {
            result = future.get();
        } catch (Exception e) {
            throw ServiceException.FAILURE("Error in getting task execution result", e);
        }
        retList.addAll(result);
    }
    boolean sortByTotal = sortBy.equals(SORT_TOTAL_USED);
    boolean sortByQuota = sortBy.equals(SORT_QUOTA_LIMIT);
    boolean sortByAccount = sortBy.equals(SORT_ACCOUNT);
    Comparator<AccountQuota> comparator = new QuotaComparator(sortByTotal, sortByQuota, sortByAccount, sortAscending);
    Collections.sort(retList, comparator);
    return retList;
}
Also used : Server(com.zimbra.cs.account.Server) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Callable(java.util.concurrent.Callable) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 12 with SoapHttpTransport

use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.

the class TestCommunityIntegration method testGetInfo.

public void testGetInfo() throws Exception {
    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.name.name()).setText(testUser.getName());
    request.addElement(AccountConstants.E_PASSWORD).setText(TestUtil.DEFAULT_PASSWORD);
    Element response = transport.invoke(request);
    String authToken = response.getElement(AccountConstants.E_AUTH_TOKEN).getText();
    transport.setAuthToken(authToken);
    request = Element.create(transport.getRequestProtocol(), AccountConstants.GET_INFO_REQUEST);
    response = transport.invoke(request);
    String communityURL = response.getAttribute(AccountConstants.E_COMMUNITY_URL);
    assertNotNull(communityURL);
    assertTrue("community URL begin with " + COMMUNITY_BASE_URL, communityURL.startsWith(COMMUNITY_BASE_URL));
    assertTrue("community URL should contain username=" + testUser.getUid(), communityURL.contains(String.format("username=%s", testUser.getUid())));
    assertTrue("community URL should contain redirect_uri=" + COMMUNITY_HOME_URL + " actual: " + communityURL, communityURL.contains(String.format("redirect_uri=%s", URLEncoder.encode(COMMUNITY_BASE_URL.concat(COMMUNITY_HOME_URL), "UTF8"))));
    assertTrue("community URL should contain configured client_id=" + COMMUNITY_CLIENT_ID, communityURL.contains(String.format("client_id=%s&", COMMUNITY_CLIENT_ID)));
}
Also used : Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 13 with SoapHttpTransport

use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.

the class ProxyTarget method dispatch.

public Element dispatch(Element request) throws ServiceException {
    SoapProtocol proto = request instanceof Element.JSONElement ? SoapProtocol.SoapJS : SoapProtocol.Soap12;
    SoapHttpTransport transport = new SoapHttpTransport(mURL);
    try {
        transport.setAuthToken(mAuthToken.toZAuthToken());
        transport.setRequestProtocol(proto);
        return transport.invokeWithoutSession(request);
    } catch (IOException e) {
        throw ServiceException.PROXY_ERROR(e, mURL);
    } finally {
        transport.shutdown();
    }
}
Also used : Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) IOException(java.io.IOException)

Example 14 with SoapHttpTransport

use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.

the class SoapCommandUtil method getTransport.

private SoapHttpTransport getTransport(boolean isAdmin) {
    if (mTransport == null || !Objects.equal(mTransport.getURI(), mUrl)) {
        mTransport = new SoapHttpTransport(mUrl);
    }
    mTransport.setAdmin(isAdmin);
    mTransport.setAuthToken(mAuthToken);
    mTransport.setSessionId(mSessionId);
    mTransport.setDebugListener(this);
    mTransport.setTimeout(0);
    return mTransport;
}
Also used : SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Example 15 with SoapHttpTransport

use of com.zimbra.common.soap.SoapHttpTransport in project zm-mailbox by Zimbra.

the class TestAuthentication method testAccountLockout.

public void testAccountLockout() throws Exception {
    String wrongPassword1 = "test1234";
    String wrongPassword2 = "test12345";
    Account acct = TestUtil.getAccount(USER_NAME);
    acct.setPasswordLockoutMaxFailures(2);
    acct.setPasswordLockoutEnabled(true);
    SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
    AccountSelector acctSel = new AccountSelector(com.zimbra.soap.type.AccountBy.name, acct.getName());
    AuthRequest req = new AuthRequest(acctSel, wrongPassword1);
    // Verify lockout happen after 2 invalid login using same password.
    Element resp;
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
    // Add Soap protocol to PasswordLockoutSuppressionProtocols
    acct.setPasswordLockoutSuppressionProtocols(PasswordLockoutSuppressionProtocols.soap);
    // Verify lock out should not happen after 2 invalid login using same password and next login with different invalid password should be locked out.
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not active", acct.getAccountStatus().equals(AccountStatus.active));
    req = new AuthRequest(acctSel, wrongPassword2);
    try {
        resp = transport.invoke(JaxbUtil.jaxbToElement(req, SoapProtocol.SoapJS.getFactory()));
    } catch (ServiceException e) {
    }
    Assert.assertTrue("account is not lockedout", verifyLockedoutAndReactivateAccount(acct, transport));
    acct.setPasswordLockoutSuppressionEnabled(false);
}
Also used : Account(com.zimbra.cs.account.Account) AuthRequest(com.zimbra.soap.account.message.AuthRequest) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport)

Aggregations

SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)69 Element (com.zimbra.common.soap.Element)54 Test (org.junit.Test)32 SoapFaultException (com.zimbra.common.soap.SoapFaultException)16 ServiceException (com.zimbra.common.service.ServiceException)13 Account (com.zimbra.cs.account.Account)13 DeployZimletRequest (com.zimbra.soap.admin.message.DeployZimletRequest)13 AuthRequest (com.zimbra.soap.account.message.AuthRequest)12 AttachmentIdAttrib (com.zimbra.soap.admin.type.AttachmentIdAttrib)12 XMLElement (com.zimbra.common.soap.Element.XMLElement)11 AuthToken (com.zimbra.cs.account.AuthToken)10 ZAuthToken (com.zimbra.common.auth.ZAuthToken)8 AuthResponse (com.zimbra.soap.account.message.AuthResponse)8 IOException (java.io.IOException)8 ZMailbox (com.zimbra.client.ZMailbox)7 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)6 AccountSelector (com.zimbra.soap.type.AccountSelector)6 HashMap (java.util.HashMap)5 Domain (com.zimbra.cs.account.Domain)4 Server (com.zimbra.cs.account.Server)4