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;
}
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)));
}
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();
}
}
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;
}
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);
}
Aggregations