/**
  * Returns an AuthToken by auth data in the <authToken> element.
  *
  * @param authTokenElem
  * @param acct TODO: This may not be needed if we can get account info from the OAuth access
  *     token.
  * @return
  * @throws AuthProviderException
  * @throws AuthTokenException
  */
 protected AuthToken authToken(Element authTokenElem, Account acct)
     throws AuthProviderException, AuthTokenException {
   // default implementation just extracts the text and calls the authToken(String)
   // the acct parameter is ignored.
   String token = authTokenElem.getText();
   return authToken(token);
 }
  Entry getTargetEntry(Provisioning prov, Element eTarget, TargetType targetType)
      throws ServiceException {
    TargetBy targetBy = TargetBy.fromString(eTarget.getAttribute(AdminConstants.A_BY));
    String target = eTarget.getText();

    return TargetType.lookupTarget(prov, targetType, targetBy, target);
  }
Exemple #3
0
  /* (non-Javadoc)
   * @see com.zimbra.soap.DocumentHandler#handle(org.dom4j.Element, java.util.Map)
   */
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);

    Element a = request.getElement(AdminConstants.E_ACCOUNT);
    String key = a.getAttribute(AdminConstants.A_BY);
    String value = a.getText();

    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.fromString(key), value, zsc.getAuthToken());

    if (account == null) throw AccountServiceException.NO_SUCH_ACCOUNT(value);

    if (account.isCalendarResource()) {
      // need a CalendarResource instance for RightChecker
      CalendarResource resource = prov.get(CalendarResourceBy.id, account.getId());
      checkCalendarResourceRight(zsc, resource, Admin.R_getCalendarResourceInfo);
    } else checkAccountRight(zsc, account, Admin.R_getAccountInfo);

    Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_INFO_RESPONSE);
    response.addElement(AdminConstants.E_NAME).setText(account.getName());
    addAttr(response, Provisioning.A_zimbraId, account.getId());
    addAttr(
        response, Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost));

    doCos(account, response);
    addUrls(response, account);

    return response;
  }
Exemple #4
0
  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;
  }
Exemple #5
0
 protected void validateElement(Element elem) throws ZimletException {
   if (elem.getName().equals(ZIMLET_TAG_CONTENT_OBJECT)) {
     mContentObject = elem.toString();
   } else if (elem.getName().equals(ZIMLET_TAG_PANEL_ITEM)) {
     mPanelItem = elem.toString();
   } else if (elem.getName().equals(ZIMLET_TAG_SERVER_EXTENSION)) {
     parseServerExtension(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_SCRIPT)) {
     parseResource(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_CSS)) {
     parseCss(elem);
   } else if (elem.getName().equals(ZIMLET_TAG_TARGET)) {
     mTargets.add(elem.getText());
   } else if (elem.getName().equals(ZIMLET_DISABLE_UI_UNDEPLOY)) {
     mDisableUIUndeploy = elem.getText();
   }
 }
  NamedEntry getGranteeEntry(Provisioning prov, Element eGrantee, GranteeType granteeType)
      throws ServiceException {
    if (!granteeType.allowedForAdminRights())
      throw ServiceException.INVALID_REQUEST(
          "unsupported grantee type: " + granteeType.getCode(), null);

    GranteeBy granteeBy = GranteeBy.fromString(eGrantee.getAttribute(AdminConstants.A_BY));
    String grantee = eGrantee.getText();

    return GranteeType.lookupGrantee(prov, granteeType, granteeBy, grantee);
  }
Exemple #7
0
  public static SignatureItem importFromSOAP(Element sig) throws HarnessException {

    if (sig == null) throw new HarnessException("Element cannot be null");

    SignatureItem item = null;

    try {

      // Make sure we only have the <tag/> part
      Element t = ZimbraAccount.SoapClient.selectNode(sig, "//acct:signature");
      if (t == null) throw new HarnessException("Element does not contain an <tag/> element");

      // Create the object
      item = new SignatureItem();

      // Set the ID
      item.setId(t.getAttribute("id", null));
      // Set tag name
      item.setName(t.getAttribute("name", null));

      Element contentBodyHtml =
          ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/html']");
      Element contentBodyText =
          ZimbraAccount.SoapClient.selectNode(sig, "//acct:content[@type='text/plain']");
      if (contentBodyHtml != null) {
        item.dBodyHtmlText = contentBodyHtml.getText().trim();
      } else if (contentBodyText != null) {
        item.dBodyText = contentBodyText.getText().trim();
      }

      return (item);

    } catch (Exception e) {
      throw new HarnessException("Could not parse GetMsgResponse: " + sig.prettyPrint(), e);
    } finally {
      if (item != null) logger.info(item.prettyPrint());
    }
  }
Exemple #8
0
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);

    Element a = request.getElement(AdminConstants.E_ACCOUNT);
    String key = a.getAttribute(AdminConstants.A_BY);
    String value = a.getText();

    long lifetime =
        request.getAttributeLong(AdminConstants.A_DURATION, DEFAULT_AUTH_LIFETIME) * 1000;

    Provisioning prov = Provisioning.getInstance();

    Account account = null;

    if (key.equals(BY_NAME)) {
      account = prov.get(AccountBy.name, value, zsc.getAuthToken());
    } else if (key.equals(BY_ID)) {
      account = prov.get(AccountBy.id, value, zsc.getAuthToken());
    } else {
      throw ServiceException.INVALID_REQUEST("unknown value for by: " + key, null);
    }

    if (account == null) throw AccountServiceException.NO_SUCH_ACCOUNT(value);

    checkAdminLoginAsRight(zsc, prov, account);

    ZimbraLog.security.info(
        ZimbraLog.encodeAttrs(
            new String[] {
              "cmd", "DelegateAuth", "accountId", account.getId(), "accountName", account.getName()
            }));

    Element response = zsc.createElement(AdminConstants.DELEGATE_AUTH_RESPONSE);
    long maxLifetime =
        account.getTimeInterval(
            Provisioning.A_zimbraAuthTokenLifetime, DEFAULT_AUTH_LIFETIME * 1000);

    // take the min of requested lifetime vs maxLifetime
    long expires = System.currentTimeMillis() + Math.min(lifetime, maxLifetime);
    String token;
    Account adminAcct = prov.get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
    if (adminAcct == null)
      throw AccountServiceException.NO_SUCH_ACCOUNT(zsc.getAuthtokenAccountId());

    AuthToken at = AuthProvider.getAuthToken(account, expires, false, adminAcct);
    at.encodeAuthResp(response, true);
    response.addAttribute(AdminConstants.E_LIFETIME, lifetime, Element.Disposition.CONTENT);
    return response;
  }
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(getZimbraSoapContext(context));

    int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, 0);
    if (limit < 0) {
      throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
    }

    int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
    if (offset < 0) {
      throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
    }

    Element d = request.getElement(AdminConstants.E_DL);
    String dlName = d.getText();
    Contact con = GalSyncUtil.getGalDlistContact((OfflineAccount) account, dlName);
    ContactDLMembers dlMembers = new ContactDLMembers(con);
    return processDLMembers(zsc, dlName, account, limit, offset, dlMembers);
  }
Exemple #10
0
  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);
    }
  }
Exemple #11
0
 private void parseCss(Element css) throws ZimletException {
   mStyleSheets.add(css.getText());
 }
Exemple #12
0
 private void parseResource(Element resource) throws ZimletException {
   mScripts.add(resource.getText());
 }
Exemple #13
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    if (true) throw WikiServiceException.ERROR("Deprecated");
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    OperationContext octxt = getOperationContext(zsc, context);

    Element msgElem = request.getElement(MailConstants.E_WIKIWORD);
    String subject = msgElem.getAttribute(MailConstants.A_NAME, null);
    String id = msgElem.getAttribute(MailConstants.A_ID, null);
    int ver = (int) msgElem.getAttributeLong(MailConstants.A_VERSION, 0);
    int itemId;
    if (id == null) {
      itemId = 0;
    } else {
      ItemId iid = new ItemId(id, zsc);
      itemId = iid.getId();
    }

    ItemId fid = getRequestedFolder(request, zsc);
    ByteArrayInputStream is = null;
    try {
      byte[] rawData = msgElem.getText().getBytes("UTF-8");
      is = new ByteArrayInputStream(rawData);
    } catch (IOException ioe) {
      throw ServiceException.FAILURE("can't get the content", ioe);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(zsc.getRequestedAccountId());
    Document wikiItem = null;
    WikiPage.WikiContext ctxt = new WikiPage.WikiContext(octxt, zsc.getAuthToken());
    if (itemId == 0) {
      // create a new page
      wikiItem =
          mbox.createDocument(
              octxt,
              fid.getId(),
              subject,
              WikiItem.WIKI_CONTENT_TYPE,
              getAuthor(zsc),
              null,
              true,
              is,
              MailItem.TYPE_WIKI);
    } else {
      // add a new revision
      WikiPage oldPage = WikiPage.findPage(ctxt, zsc.getRequestedAccountId(), itemId);
      if (oldPage == null)
        throw new WikiServiceException.NoSuchWikiException("page id=" + id + " not found");
      if (oldPage.getLastVersion() != ver) {
        throw MailServiceException.MODIFY_CONFLICT(
            new Argument(MailConstants.A_NAME, subject, Argument.Type.STR),
            new Argument(MailConstants.A_ID, oldPage.getId(), Argument.Type.IID),
            new Argument(MailConstants.A_VERSION, oldPage.getLastVersion(), Argument.Type.NUM));
      }
      wikiItem = mbox.addDocumentRevision(octxt, itemId, getAuthor(zsc), subject, null, true, is);
    }

    Element response = zsc.createElement(MailConstants.SAVE_WIKI_RESPONSE);
    Element m = response.addElement(MailConstants.E_WIKIWORD);
    m.addAttribute(MailConstants.A_ID, new ItemIdFormatter(zsc).formatItemId(wikiItem));
    m.addAttribute(MailConstants.A_VERSION, wikiItem.getVersion());
    return response;
  }
Exemple #14
0
  public Element sendRequest(
      Element request,
      boolean requiresAuth,
      boolean noSession,
      int timeout,
      SoapProtocol resProto,
      Map<String, ElementHandler> saxHandlers,
      String uri,
      ZAuthToken authToken,
      boolean sendAcctId)
      throws ServiceException {
    OfflineAccount acct = getOfflineAccount();
    SoapHttpTransport transport = new SoapHttpTransport(uri);
    try {
      transport.setUserAgent(OfflineLC.zdesktop_name.value(), OfflineLC.getFullVersion());
      transport.setTimeout(timeout);
      if (requiresAuth) transport.setAuthToken(authToken == null ? getAuthToken() : authToken);
      transport.setRequestProtocol(SoapProtocol.Soap12);
      if (resProto != null) transport.setResponseProtocol(resProto);

      if (acct.isDebugTraceEnabled()) {
        Element elt = null;
        String pswd = null;
        if (request.getName().equals(AccountConstants.AUTH_REQUEST.getName())) {
          elt = request.getElement(AccountConstants.E_PASSWORD);
          pswd = elt.getText();
          elt.setText("*");
        }

        OfflineLog.request.debug(request);

        if (pswd != null) elt.setText(pswd);
      }

      Element response = null;
      if (saxHandlers != null) {
        response =
            transport.invoke(
                request.detach(),
                false,
                true,
                null,
                null,
                null,
                new SoapHttpTransport.SAXResponseHandler(saxHandlers));
      } else if (noSession) {
        if (sendAcctId) response = transport.invoke(request.detach(), false, true, acct.getId());
        else response = transport.invokeWithoutSession(request.detach());
      } else {
        if (mSessionId != null) transport.setSessionId(mSessionId);
        response = transport.invoke(request.detach());
      }
      if (acct.isDebugTraceEnabled() && response != null) OfflineLog.response.debug(response);

      // update sessionId if changed
      if (transport.getSessionId() != null) mSessionId = transport.getSessionId();

      return response;
    } catch (IOException e) {
      throw ServiceException.PROXY_ERROR(e, uri);
    }
  }
Exemple #15
0
  public ZAlarm(Element alarmElem) throws ServiceException {
    ZAction action = ZAction.DISPLAY;
    ZTriggerType triggerType = ZTriggerType.RELATIVE;
    ZRelated triggerRelated = null;
    ParsedDuration triggerRelative = null;
    ParsedDateTime triggerAbsolute = null;
    ParsedDuration repeatDuration = null;
    int repeatCount = 0;
    String description = null;
    String summary = null;
    Attach attach = null;
    List<ZAttendee> attendees = null;

    String val;
    val = alarmElem.getAttribute(MailConstants.A_CAL_ALARM_ACTION);
    action = ZAction.lookup(val);
    if (action == null)
      throw ServiceException.INVALID_REQUEST(
          "Invalid " + MailConstants.A_CAL_ALARM_ACTION + " value " + val, null);

    Element triggerElem = alarmElem.getElement(MailConstants.E_CAL_ALARM_TRIGGER);
    Element triggerRelativeElem =
        triggerElem.getOptionalElement(MailConstants.E_CAL_ALARM_RELATIVE);
    if (triggerRelativeElem != null) {
      triggerType = ZTriggerType.RELATIVE;
      String related = triggerRelativeElem.getAttribute(MailConstants.A_CAL_ALARM_RELATED, null);
      if (related != null) {
        triggerRelated = ZRelated.lookup(related);
        if (triggerRelated == null)
          throw ServiceException.INVALID_REQUEST(
              "Invalid " + MailConstants.A_CAL_ALARM_RELATED + " value " + val, null);
      }
      triggerRelative = ParsedDuration.parse(triggerRelativeElem);
    } else {
      triggerType = ZTriggerType.ABSOLUTE;
      Element triggerAbsoluteElem =
          triggerElem.getOptionalElement(MailConstants.E_CAL_ALARM_ABSOLUTE);
      if (triggerAbsoluteElem == null)
        throw ServiceException.INVALID_REQUEST(
            "<"
                + MailConstants.E_CAL_ALARM_TRIGGER
                + "> must have either <"
                + MailConstants.E_CAL_ALARM_RELATIVE
                + "> or <"
                + MailConstants.E_CAL_ALARM_ABSOLUTE
                + "> child element",
            null);
      String datetime = triggerAbsoluteElem.getAttribute(MailConstants.A_DATE);
      try {
        triggerAbsolute = ParsedDateTime.parseUtcOnly(datetime);
      } catch (ParseException e) {
        throw ServiceException.INVALID_REQUEST("Invalid absolute trigger value " + val, e);
      }
    }

    Element repeatElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_REPEAT);
    if (repeatElem != null) {
      repeatDuration = ParsedDuration.parse(repeatElem);
      repeatCount = (int) repeatElem.getAttributeLong(MailConstants.A_CAL_ALARM_COUNT, 0);
    }

    Element descElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_DESCRIPTION);
    if (descElem != null) {
      description = descElem.getText();
    }

    Element summaryElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ALARM_SUMMARY);
    if (summaryElem != null) {
      summary = summaryElem.getText();
    }

    Element attachElem = alarmElem.getOptionalElement(MailConstants.E_CAL_ATTACH);
    if (attachElem != null) attach = Attach.parse(attachElem);

    Iterator<Element> attendeesIter = alarmElem.elementIterator(MailConstants.E_CAL_ATTENDEE);
    while (attendeesIter.hasNext()) {
      ZAttendee at = new ZAttendee(attendeesIter.next());
      if (this.mAttendees == null) this.mAttendees = new ArrayList<ZAttendee>();
      this.mAttendees.add(at);
    }
    setAction(action);
    setDescription(description);
    setSummary(summary);
    setTriggerRelative(triggerRelative);
  }