@Override public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); String action = request.getAttribute(AdminConstants.A_ACTION).toLowerCase(); Element content = request.getElement(MailConstants.E_CONTENT); String aid = content.getAttribute(MailConstants.A_ATTACHMENT_ID, null); boolean flushCache = request.getAttributeBool(AdminConstants.A_FLUSH, false); boolean synchronous = request.getAttributeBool(AdminConstants.A_SYNCHRONOUS, false); if (action.equals(AdminConstants.A_STATUS)) { // just print the status } else if (action.equals(AdminConstants.A_DEPLOYALL)) { for (Server server : Provisioning.getInstance().getAllServers()) { checkRight(zsc, context, server, Admin.R_deployZimlet); } deploy(zsc, aid, zsc.getRawAuthToken(), flushCache, synchronous); if (flushCache) { if (ZimbraLog.misc.isDebugEnabled()) { ZimbraLog.misc.debug("DeployZimlet: flushing zimlet cache"); } checkRight(zsc, context, Provisioning.getInstance().getLocalServer(), Admin.R_flushCache); FlushCache.sendFlushRequest(context, "/service", "/zimlet/res/all.js"); } } else if (action.equals(AdminConstants.A_DEPLOYLOCAL)) { Server localServer = Provisioning.getInstance().getLocalServer(); checkRight(zsc, context, localServer, Admin.R_deployZimlet); deploy(zsc, aid, null, false, synchronous); if (flushCache) { if (ZimbraLog.misc.isDebugEnabled()) { ZimbraLog.misc.debug("DeployZimlet: flushing zimlet cache"); } checkRight(zsc, context, localServer, Admin.R_flushCache); FlushCache.sendFlushRequest(context, "/service", "/zimlet/res/all.js"); } } else { throw ServiceException.INVALID_REQUEST("invalid action " + action, null); } Element response = zsc.createElement(AdminConstants.DEPLOY_ZIMLET_RESPONSE); Progress progress = (Progress) mProgressMap.get(aid); if (progress != null) progress.writeResponse(response); return response; }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); Provisioning prov = Provisioning.getInstance(); boolean applyConfig = request.getAttributeBool(AdminConstants.A_APPLY_CONFIG, true); Set<String> reqAttrs = getReqAttrs(request, AttributeClass.server); Element d = request.getElement(AdminConstants.E_SERVER); String method = d.getAttribute(AdminConstants.A_BY); String name = d.getText(); if (name == null || name.equals("")) throw ServiceException.INVALID_REQUEST("must specify a value for a server", null); Server server = prov.get(ServerBy.fromString(method), name); if (server == null) throw AccountServiceException.NO_SUCH_SERVER(name); AdminAccessControl aac = checkRight(zsc, context, server, AdminRight.PR_ALWAYS_ALLOW); // reload the server prov.reload(server); Element response = zsc.createElement(AdminConstants.GET_SERVER_RESPONSE); encodeServer(response, server, applyConfig, reqAttrs, aac.getAttrRightChecker(server)); return response; }
public ZAce(Element e) throws ServiceException { mRight = e.getAttribute(MailConstants.A_RIGHT); mDeny = e.getAttributeBool(MailConstants.A_DENY, false); mGranteeName = e.getAttribute(MailConstants.A_DISPLAY, null); mGranteeId = e.getAttribute(MailConstants.A_ZIMBRA_ID, null); mGranteeType = GranteeType.fromString(e.getAttribute(MailConstants.A_GRANT_TYPE)); mSecret = e.getAttribute(MailConstants.A_PASSWORD, null); }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { HttpServletRequest servletRequest = (HttpServletRequest) context.get(SoapServlet.SERVLET_REQUEST); boolean isResumed = !ContinuationSupport.getContinuation(servletRequest).isInitial(); if (!isResumed) { OfflineSyncManager.getInstance().clientPing(); } boolean wait = request.getAttributeBool(MailConstants.A_WAIT, false); long start = System.currentTimeMillis(); if (!isResumed) { servletRequest.setAttribute(TIME_KEY, start); } Element response = super.handle(request, context); response.addAttribute(MailConstants.A_WAIT, wait); response.addAttribute( MailConstants.A_TIME, System.currentTimeMillis() - (Long) servletRequest.getAttribute(TIME_KEY)); return response; }
public Element handle(Element request, Map<String, Object> context) throws ServiceException { ZimbraSoapContext zsc = getZimbraSoapContext(context); Provisioning prov = Provisioning.getInstance(); boolean applyConfig = request.getAttributeBool(AdminConstants.A_APPLY_CONFIG, true); List domains = prov.getAllDomains(); AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc); Element response = zsc.createElement(AdminConstants.GET_ALL_DOMAINS_RESPONSE); for (Iterator it = domains.iterator(); it.hasNext(); ) { Domain domain = (Domain) it.next(); if (aac.hasRightsToList(domain, Admin.R_listDomain, null)) GetDomain.encodeDomain( response, domain, applyConfig, null, aac.getAttrRightChecker(domain)); } return response; }
public Element handleNetworkRequest(Element document, Map context) throws ServiceException { Element backup; String method; String bkupTarget; String label; Element response; Log.backup.info("Backup request started"); ZimbraSoapContext lc = getZimbraSoapContext(context); checkRights(lc, context); backup = document.getElement("backup"); method = backup.getAttribute("method"); bkupTarget = backup.getAttribute("target", null); label = backup.getAttribute("label", null); response = lc.createElement(BackupService.BACKUP_RESPONSE); BackupManager mgr; BackupTarget backupTarget; boolean sync; boolean sentReportEmail; ServiceException error; mgr = BackupManager.getInstance(); if(bkupTarget != null && "incremental".equals(method)) throw ServiceException.FAILURE("Custom backup target is not allowed for incremental backup", null); backupTarget = mgr.getBackupTarget(bkupTarget, true); if("abort".equals(method)) { BackupSet bak = backupTarget.getBackupSet(label); bak.abortFullBackup(); break MISSING_BLOCK_LABEL_852; } if("delete".equals(method)) { String val = backup.getAttribute("before"); long cutoffTime = getCutoffTime(val, backupTarget); mgr.deleteBackups(backupTarget, cutoffTime); break MISSING_BLOCK_LABEL_852; } sync = backup.getAttributeBool("sync", false); sentReportEmail = false; error = null; BackupParams params; List syncBackups; BackupSet fullBak; BackupSet incrBak; params = new BackupParams(); params.sync = sync; parseComponentIncludeExcludeAttrs(backup, params); Element fcOptsElem = backup.getOptionalElement("fileCopier"); if(fcOptsElem != null) params.fcOpts = ParseXML.parseFileCopierOptions(fcOptsElem); syncBackups = new ArrayList(); fullBak = null; incrBak = null; int size; try { com.zimbra.cs.backup.BackupManager.BackupMode backupMode = mgr.getBackupMode(); boolean autoGroupedMode = com.zimbra.cs.backup.BackupManager.BackupMode.AUTO_GROUPED.equals(backupMode); if("full".equals(method)) { params.zip = backup.getAttributeBool("zip", true); params.zipStore = backup.getAttributeBool("zipStore", true); List acctElems = backup.listElements("account"); if(acctElems.size() > 0) { params.redologs = false; List acctNames = parseAccountNames(acctElems); boolean all = acctNames.size() == 1 && "all".equals(acctNames.get(0)); if(all) { if(!sync) fullBak = mgr.startBackupFull(backupTarget, params); else fullBak = mgr.backupFull(backupTarget, params, syncBackups); } else { com.zimbra.cs.account.Account accounts[] = mgr.lookupAccounts(acctNames, com.zimbra.cs.account.Provisioning.AccountBy.name, backupTarget); if(!sync) fullBak = mgr.startBackupFull(accounts, backupTarget, params); else fullBak = mgr.backupFull(accounts, backupTarget, params, syncBackups); } } else if(autoGroupedMode) { if(backupTarget.isCustom()) throw ServiceException.FAILURE("Custom backup target is not allowed for auto-grouped backup", null); params.redologs = true; com.zimbra.cs.account.Account accounts[] = mgr.lookupAccountsByOldestBackup(backupTarget); if(accounts == null || accounts.length == 0) throw BackupServiceException.AUTO_GROUPED_BACKUP_TOO_SOON(); if(!sync) fullBak = mgr.startBackupFull(accounts, backupTarget, params); else fullBak = mgr.backupFull(accounts, backupTarget, params, syncBackups); } else { throw ServiceException.INVALID_REQUEST("Missing account list", null); } } else if("incremental".equals(method)) { params.zip = backup.getAttributeBool("zip", true); params.zipStore = backup.getAttributeBool("zipStore", true); BackupSet baks[] = mgr.backupIncremental(backupTarget, params, syncBackups); incrBak = baks[0]; fullBak = baks[1]; } else { throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("Invalid backup method: ").append(method).toString(), null); } } catch(IOException e) { throw ServiceException.FAILURE(e.getMessage(), e); } size = syncBackups.size(); if(size > 0) { BackupSet baks[] = new BackupSet[size]; syncBackups.toArray(baks); mgr.sendReportEmail(baks); sentReportEmail = true; } break MISSING_BLOCK_LABEL_756; Exception exception; exception; int size = syncBackups.size(); if(size > 0) { BackupSet baks[] = new BackupSet[size]; syncBackups.toArray(baks); mgr.sendReportEmail(baks); sentReportEmail = true; } throw exception; Element body = response.addElement("backup"); if(fullBak != null) body.addAttribute("label", fullBak.getLabel()); if(incrBak != null) body.addAttribute("incr-label", incrBak.getLabel()); if(error != null && !sentReportEmail) mgr.sendErrorReportEmail(error); break MISSING_BLOCK_LABEL_852; ServiceException e; e; error = e; throw e; Exception exception1; exception1; if(error != null && !sentReportEmail) mgr.sendErrorReportEmail(error); throw exception1; Log.backup.info("Backup request finished"); return response; IOException e; e; throw ServiceException.FAILURE(e.getMessage(), e); }
public static SetCalendarItemParseResult parseSetAppointmentRequest( Element request, ZimbraSoapContext zsc, OperationContext octxt, Folder folder, MailItem.Type type, boolean parseIds) throws ServiceException { Account acct = getRequestedAccount(zsc); Mailbox mbox = getRequestedMailbox(zsc); SetCalendarItemParseResult result = new SetCalendarItemParseResult(); ArrayList<SetCalendarItemData> exceptions = new ArrayList<SetCalendarItemData>(); Invite defInv = null; // First, the <default> { Element e = request.getOptionalElement(MailConstants.A_DEFAULT); if (e != null) { result.defaultInv = getSetCalendarItemData( zsc, octxt, acct, mbox, e, new SetCalendarItemInviteParser(false, false, folder, type)); defInv = result.defaultInv.invite; } } // for each <except> for (Element e : request.listElements(MailConstants.E_CAL_EXCEPT)) { SetCalendarItemData exDat = getSetCalendarItemData( zsc, octxt, acct, mbox, e, new SetCalendarItemInviteParser(true, false, folder, type)); exceptions.add(exDat); if (defInv == null) { defInv = exDat.invite; } } // for each <cancel> for (Element e : request.listElements(MailConstants.E_CAL_CANCEL)) { SetCalendarItemData exDat = getSetCalendarItemData( zsc, octxt, acct, mbox, e, new SetCalendarItemInviteParser(true, true, folder, type)); exceptions.add(exDat); if (defInv == null) { defInv = exDat.invite; } } if (exceptions.size() > 0) { result.exceptions = new SetCalendarItemData[exceptions.size()]; exceptions.toArray(result.exceptions); } else { if (result.defaultInv == null) throw ServiceException.INVALID_REQUEST("No default/except/cancel specified", null); } // <replies> Element repliesElem = request.getOptionalElement(MailConstants.E_CAL_REPLIES); if (repliesElem != null) result.replies = CalendarUtils.parseReplyList(repliesElem, defInv.getTimeZoneMap()); result.isTodo = defInv != null && defInv.isTodo(); boolean noNextAlarm = request.getAttributeBool(MailConstants.A_CAL_NO_NEXT_ALARM, false); if (noNextAlarm) result.nextAlarm = CalendarItem.NEXT_ALARM_ALL_DISMISSED; else result.nextAlarm = request.getAttributeLong( MailConstants.A_CAL_NEXT_ALARM, CalendarItem.NEXT_ALARM_KEEP_CURRENT); return result; }
public static ZFilterCondition getCondition(Element condEl) throws ServiceException { String name = condEl.getName(); boolean isNegative = condEl.getAttributeBool(MailConstants.A_NEGATIVE, false); if (name.equals(MailConstants.E_HEADER_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON); s = s.toLowerCase(); StringComparison comparison = StringComparison.fromString(s); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); String value = condEl.getAttribute(MailConstants.A_VALUE); return new ZHeaderCondition( header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value); } else if (name.equals(MailConstants.E_MIME_HEADER_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); String s = condEl.getAttribute(MailConstants.A_STRING_COMPARISON); s = s.toLowerCase(); StringComparison comparison = StringComparison.fromString(s); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); String value = condEl.getAttribute(MailConstants.A_VALUE); return new ZMimeHeaderCondition( header, HeaderOp.fromStringComparison(comparison, isNegative), caseSensitive, value); } else if (name.equals(MailConstants.E_HEADER_EXISTS_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); return new ZHeaderExistsCondition(header, !isNegative); } else if (name.equals(MailConstants.E_SIZE_TEST)) { String s = condEl.getAttribute(MailConstants.A_NUMBER_COMPARISON); s = s.toLowerCase(); NumberComparison comparison = NumberComparison.fromString(s); String size = condEl.getAttribute(MailConstants.A_SIZE); return new ZSizeCondition(SizeOp.fromNumberComparison(comparison, isNegative), size); } else if (name.equals(MailConstants.E_DATE_TEST)) { String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON); s = s.toLowerCase(); DateComparison comparison = DateComparison.fromString(s); Date date = new Date(condEl.getAttributeLong(MailConstants.A_DATE) * 1000); return new ZDateCondition(DateOp.fromDateComparison(comparison, isNegative), date); } else if (name.equals(MailConstants.E_CURRENT_TIME_TEST)) { String s = condEl.getAttribute(MailConstants.A_DATE_COMPARISON); s = s.toLowerCase(); DateComparison comparison = DateComparison.fromString(s); String timeStr = condEl.getAttribute(MailConstants.A_TIME); return new ZCurrentTimeCondition(DateOp.fromDateComparison(comparison, isNegative), timeStr); } else if (name.equals(MailConstants.E_BODY_TEST)) { String value = condEl.getAttribute(MailConstants.A_VALUE); BodyOp op = (isNegative ? BodyOp.NOT_CONTAINS : BodyOp.CONTAINS); boolean caseSensitive = condEl.getAttributeBool(MailConstants.A_CASE_SENSITIVE, false); return new ZBodyCondition(op, caseSensitive, value); } else if (name.equals(MailConstants.E_CURRENT_DAY_OF_WEEK_TEST)) { String value = condEl.getAttribute(MailConstants.A_VALUE); SimpleOp op = (isNegative ? SimpleOp.NOT_IS : SimpleOp.IS); return new ZCurrentDayOfWeekCondition(op, value); } else if (name.equals(MailConstants.E_ADDRESS_BOOK_TEST)) { String header = condEl.getAttribute(MailConstants.A_HEADER); // String folderPath = condEl.getAttribute(MailConstants.A_FOLDER_PATH); // TODO: support path to contacts folder AddressBookOp op = (isNegative ? AddressBookOp.NOT_IN : AddressBookOp.IN); return new ZAddressBookCondition(op, header); } else if (name.equals(MailConstants.E_ATTACHMENT_TEST)) { return new ZAttachmentExistsCondition(!isNegative); } else if (name.equals(MailConstants.E_INVITE_TEST)) { List<Element> eMethods = condEl.listElements(MailConstants.E_METHOD); if (eMethods.isEmpty()) { return new ZInviteCondition(!isNegative); } else { List<String> methods = new ArrayList<String>(); for (Element eMethod : eMethods) { methods.add(eMethod.getText()); } return new ZInviteCondition(!isNegative, methods); } } else if (name.equals(MailConstants.E_TRUE_TEST)) { return new ZTrueCondition(); } else { throw ZClientException.CLIENT_ERROR("unknown filter condition: " + name, null); } }
/** * Always does a request -- caller is responsible for checking to see if this is necessary or not */ private boolean bufferNextHits() throws ServiceException { if (atEndOfList || searchParams.getHopCount() > ZimbraSoapContext.MAX_HOP_COUNT) { return false; } bufferStartOffset = iterOffset; int chunkSizeToUse; if (singleShotRemoteRequest) { chunkSizeToUse = searchParams.getLimit(); } else { chunkSizeToUse = searchParams.getLimit() * 2; if (chunkSizeToUse < MIN_BUFFER_CHUNK_SIZE) { chunkSizeToUse = MIN_BUFFER_CHUNK_SIZE; } if (chunkSizeToUse > 500) { chunkSizeToUse = 500; } } bufferEndOffset = bufferStartOffset + chunkSizeToUse; hitBuffer = new ArrayList<ProxiedHit>(chunkSizeToUse); Element searchElt = Element.create(responseProto, MailConstants.SEARCH_REQUEST); searchParams.setOffset(bufferStartOffset); searchParams.setLimit(chunkSizeToUse); searchParams.encodeParams(searchElt); if (singleShotRemoteRequest && (searchParams.getCursor() != null)) { Element cursorElt = searchElt.addElement(MailConstants.E_CURSOR); cursorElt.addAttribute(MailConstants.A_ID, searchParams.getCursor().getItemId().getId()); if (searchParams.getCursor().getSortValue() != null) { cursorElt.addAttribute(MailConstants.A_SORTVAL, searchParams.getCursor().getSortValue()); } if (searchParams.getCursor().getEndSortValue() != null) { cursorElt.addAttribute( MailConstants.A_ENDSORTVAL, searchParams.getCursor().getEndSortValue()); } } // call the remote server now! Server targetServer = Provisioning.getInstance().get(Key.ServerBy.name, server); String baseurl = null; try { baseurl = URLUtil.getSoapURL(targetServer, false); } catch (ServiceException e) { } if (baseurl == null) { baseurl = URLUtil.getAdminURL(targetServer, AdminConstants.ADMIN_SERVICE_URI, true); } ProxyTarget proxy = new ProxyTarget(targetServer, authToken, baseurl + MailConstants.SEARCH_REQUEST.getName()); if (mTimeout != -1) { proxy.setTimeouts(mTimeout); } ZimbraSoapContext zscInbound = searchParams.getRequestContext(); ZimbraSoapContext zscProxy; if (zscInbound != null) { zscProxy = new ZimbraSoapContext(zscInbound, targetAcctId); } else { zscProxy = new ZimbraSoapContext( authToken, targetAcctId, responseProto, responseProto, searchParams.getHopCount() + 1); } long start = System.currentTimeMillis(); Element searchResp = null; try { searchResp = DocumentHandler.proxyWithNotification(searchElt, proxy, zscProxy, zscInbound); } catch (SoapFaultException sfe) { ZimbraLog.index.warn( "Unable to (" + sfe + ") fetch search results from remote server " + proxy); atEndOfList = true; bufferEndOffset = iterOffset; return false; } catch (ServiceException e) { if (ServiceException.PROXY_ERROR.equals(e.getCode())) { ZimbraLog.index.warn( "Unable to (" + e + ") fetch search results from remote server " + proxy); atEndOfList = true; bufferEndOffset = iterOffset; return false; } throw e; } finally { long elapsed = System.currentTimeMillis() - start; ZimbraLog.index.debug( "Remote query took " + elapsed + "ms; URL=" + proxy.toString() + "; QUERY=" + searchElt.toString()); } int hitOffset; if (singleShotRemoteRequest) { hitOffset = (int) searchResp.getAttributeLong(MailConstants.A_QUERY_OFFSET, bufferStartOffset); } else { hitOffset = (int) searchResp.getAttributeLong(MailConstants.A_QUERY_OFFSET); } boolean hasMore = searchResp.getAttributeBool(MailConstants.A_QUERY_MORE); assert (bufferStartOffset == hitOffset); SortBy sb = getSortBy(); // put these hits into our buffer! int bufferIdx = 0; int stop = bufferEndOffset - bufferStartOffset; for (Iterator<Element> iter = searchResp.elementIterator(); iter.hasNext() && bufferIdx < stop; ) { Element el = iter.next(); if (el.getName().equalsIgnoreCase(MailConstants.E_INFO)) { for (Element info : el.listElements()) { queryInfo.add(new ProxiedQueryInfo(info)); } } else { if (sb != null && ((SortBy.NAME_LOCALIZED_ASC.equals(sb)) || (SortBy.NAME_LOCALIZED_DESC.equals(sb)))) { hitBuffer.add( bufferIdx++, new ProxiedContactHit(this, el, el.getAttribute(MailConstants.A_FILE_AS_STR))); } else { hitBuffer.add( bufferIdx++, new ProxiedHit(this, el, el.getAttribute(MailConstants.A_SORT_FIELD))); } } } // are we at the end of the line here? if (bufferIdx < stop || !hasMore) { // update the buffer-end-pointer bufferEndOffset = bufferStartOffset + bufferIdx; if (hasMore) { assert (!hasMore); // if bufferIdx < stop then !hasMore should be set...server bug! } atEndOfList = true; } else { assert (bufferEndOffset == bufferStartOffset + bufferIdx); } if (singleShotRemoteRequest) { atEndOfList = true; } assert (bufferStartOffset <= iterOffset); // OK, we were successful if we managed to buffer the current hit return (bufferEndOffset > iterOffset); }