コード例 #1
0
ファイル: Period.java プロジェクト: nullin/zimbra-sources
  public static Period decodeMetadata(Metadata meta, ICalTimeZone tz, TimeZoneMap tzmap)
      throws ServiceException {
    String start = meta.get(FN_START);
    ParsedDateTime startTime;
    try {
      startTime = ParsedDateTime.parse(start, tzmap, tz, tzmap.getLocalTimeZone());
    } catch (ParseException e) {
      throw ServiceException.INVALID_REQUEST(
          "Invalid PERIOD start time in metadata: " + meta.toString(), e);
    }

    String end = meta.get(FN_END, null);
    if (end != null) {
      ParsedDateTime endTime;
      try {
        endTime = ParsedDateTime.parse(end, tzmap, tz, tzmap.getLocalTimeZone());
      } catch (ParseException e) {
        throw ServiceException.INVALID_REQUEST(
            "Invalid PERIOD end time in metadata: " + meta.toString(), e);
      }
      return new Period(startTime, endTime);
    } else {
      String durStr = meta.get(FN_DURATION, null);
      if (durStr == null)
        throw ServiceException.INVALID_REQUEST(
            "PERIOD in metadata missing both end time and duration: " + meta.toString(), null);
      ParsedDuration duration = ParsedDuration.parse(durStr);
      return new Period(startTime, duration);
    }
  }
コード例 #2
0
ファイル: TargetType.java プロジェクト: koem/Zimbra
  /**
   * central place where a target should be loaded
   *
   * @param prov
   * @param targetType
   * @param targetBy
   * @param target
   * @return
   * @throws ServiceException
   */
  static Entry lookupTarget(
      Provisioning prov, TargetType targetType, TargetBy targetBy, String target, boolean mustFind)
      throws ServiceException {
    Entry targetEntry = null;

    switch (targetType) {
      case account:
        targetEntry = prov.get(AccountBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ACCOUNT(target);
        break;
      case calresource:
        targetEntry = prov.get(CalendarResourceBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_CALENDAR_RESOURCE(target);
        break;
      case dl:
        targetEntry = prov.getAclGroup(DistributionListBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(target);
        break;
      case domain:
        targetEntry = prov.get(DomainBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_DOMAIN(target);
        break;
      case cos:
        targetEntry = prov.get(CosBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_COS(target);
        break;
      case server:
        targetEntry = prov.get(ServerBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_SERVER(target);
        break;
      case xmppcomponent:
        targetEntry = prov.get(XMPPComponentBy.fromString(targetBy.name()), target);
        if (targetEntry == null && mustFind)
          throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(target);
        break;
      case zimlet:
        ZimletBy zimletBy = ZimletBy.fromString(targetBy.name());
        if (zimletBy != ZimletBy.name)
          throw ServiceException.INVALID_REQUEST("zimlet must be by name", null);
        targetEntry = prov.getZimlet(target);
        if (targetEntry == null && mustFind) throw AccountServiceException.NO_SUCH_ZIMLET(target);
        break;
      case config:
        targetEntry = prov.getConfig();
        break;
      case global:
        targetEntry = prov.getGlobalGrant();
        break;
      default:
        ServiceException.INVALID_REQUEST(
            "invallid target type for lookupTarget:" + targetType.toString(), null);
    }

    return targetEntry;
  }
コード例 #3
0
    // public only for unit test. TODO: cleanup unit test
    public Grantee(NamedEntry grantee, boolean adminOnly) throws ServiceException {
      super(grantee);

      Provisioning prov = grantee.getProvisioning();
      GroupMembership granteeGroups = null;

      if (grantee instanceof Account) {
        mGranteeType = GranteeType.GT_USER;
        mGranteeDomain = prov.getDomain((Account) grantee);
        granteeGroups = prov.getGroupMembership((Account) grantee, adminOnly);

      } else if (grantee instanceof DistributionList) {
        mGranteeType = GranteeType.GT_GROUP;
        mGranteeDomain = prov.getDomain((DistributionList) grantee);
        granteeGroups = prov.getGroupMembership((DistributionList) grantee, adminOnly);

      } else if (grantee instanceof DynamicGroup) {
        mGranteeType = GranteeType.GT_GROUP;
        mGranteeDomain = prov.getDomain((DynamicGroup) grantee);
        // no need to get membership for dynamic groups
        // dynamic groups cannot be nested, either as a members in another
        // dynamic group or a distribution list

      } else {
        if (adminOnly) {
          throw ServiceException.INVALID_REQUEST("invalid grantee type", null);
        } else {
          if (grantee instanceof Domain) {
            mGranteeType = GranteeType.GT_DOMAIN;
            mGranteeDomain = (Domain) grantee;
          }
        }
      }

      if (adminOnly) {
        if (!RightBearer.isValidGranteeForAdminRights(mGranteeType, grantee)) {
          throw ServiceException.INVALID_REQUEST("invalid grantee", null);
        }
      }

      if (mGranteeDomain == null) {
        throw ServiceException.FAILURE("internal error, cannot get domain for grantee", null);
      }

      // setup grantees ids
      mIdAndGroupIds = new HashSet<String>();
      mIdAndGroupIds.add(grantee.getId());
      if (granteeGroups != null) {
        mIdAndGroupIds.addAll(granteeGroups.groupIds());
      }
    }
コード例 #4
0
ファイル: ModifyPrefs.java プロジェクト: huu0510/z-pec
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);

    if (!canModifyOptions(zsc, account))
      throw ServiceException.PERM_DENIED("can not modify options");

    HashMap<String, Object> prefs = new HashMap<String, Object>();
    Map<String, Set<String>> name2uniqueAttrValues = new HashMap<String, Set<String>>();
    for (KeyValuePair kvp :
        request.listKeyValuePairs(AccountConstants.E_PREF, AccountConstants.A_NAME)) {
      String name = kvp.getKey(), value = kvp.getValue();
      char ch = name.length() > 0 ? name.charAt(0) : 0;
      int offset = ch == '+' || ch == '-' ? 1 : 0;
      if (!name.startsWith(PREF_PREFIX, offset))
        throw ServiceException.INVALID_REQUEST("pref name must start with " + PREF_PREFIX, null);

      AttributeInfo attrInfo =
          AttributeManager.getInstance().getAttributeInfo(name.substring(offset));
      if (attrInfo == null) {
        throw ServiceException.INVALID_REQUEST("no such attribute: " + name, null);
      }
      if (attrInfo.isCaseInsensitive()) {
        String valueLowerCase = Strings.nullToEmpty(value).toLowerCase();
        if (name2uniqueAttrValues.get(name) == null) {
          Set<String> set = new HashSet<String>();
          set.add(valueLowerCase);
          name2uniqueAttrValues.put(name, set);
          StringUtil.addToMultiMap(prefs, name, value);
        } else {
          Set<String> set = name2uniqueAttrValues.get(name);
          if (set.add(valueLowerCase)) {
            StringUtil.addToMultiMap(prefs, name, value);
          }
        }
      } else {
        StringUtil.addToMultiMap(prefs, name, value);
      }
    }

    if (prefs.containsKey(Provisioning.A_zimbraPrefMailForwardingAddress)) {
      if (!account.getBooleanAttr(Provisioning.A_zimbraFeatureMailForwardingEnabled, false))
        throw ServiceException.PERM_DENIED("forwarding not enabled");
    }

    // call modifyAttrs and pass true to checkImmutable
    Provisioning.getInstance().modifyAttrs(account, prefs, true, zsc.getAuthToken());

    Element response = zsc.createElement(AccountConstants.MODIFY_PREFS_RESPONSE);
    return response;
  }
コード例 #5
0
  static boolean validateCrossDomainAdminGrant(Right right, GranteeType granteeType)
      throws ServiceException {
    if (right == Admin.R_crossDomainAdmin && granteeType != GranteeType.GT_DOMAIN) {
      throw ServiceException.INVALID_REQUEST(
          "grantee for right " + Admin.R_crossDomainAdmin.getName() + " must be a domain.", null);
    }

    if (right != Admin.R_crossDomainAdmin && granteeType == GranteeType.GT_DOMAIN) {
      throw ServiceException.INVALID_REQUEST(
          "grantee for right " + right.getName() + " cannot be a domain.", null);
    }

    return right == Admin.R_crossDomainAdmin;
  }
コード例 #6
0
ファイル: GetServer.java プロジェクト: koem/Zimbra
  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;
  }
コード例 #7
0
ファイル: SetCustomMetadata.java プロジェクト: huu0510/z-pec
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);

    Element meta = request.getElement(MailConstants.E_METADATA);
    String section = meta.getAttribute(MailConstants.A_SECTION);
    section = section.trim();
    if (section.length() == 0 || section.length() > 36)
      throw ServiceException.INVALID_REQUEST(
          "invalid length for custom metadata section name", null);

    CustomMetadata custom = new CustomMetadata(section);
    for (Element.KeyValuePair kvp : meta.listKeyValuePairs())
      custom.put(kvp.getKey(), kvp.getValue());

    ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
    mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);

    Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
    response.addAttribute(MailConstants.A_ID, ifmt.formatItemId(iid));
    return response;
  }
コード例 #8
0
 private static IRecurrence getRecurrenceForDay(
     int dayOfWeek, StartSpec startSpec, TimeRange timeRange, ICalTimeZone tz, TimeZoneMap tzmap)
     throws ServiceException {
   // DTSTART
   String dateStr = startSpec.getDateString(dayOfWeek);
   String dtStartStr;
   if (tz.sameAsUTC())
     dtStartStr =
         String.format("%sT%02d%02d00Z", dateStr, timeRange.start.hour, timeRange.start.minute);
   else
     dtStartStr =
         String.format(
             "TZID=\"%s\":%sT%02d%02d00",
             tz.getID(), dateStr, timeRange.start.hour, timeRange.start.minute);
   ParsedDateTime dtStart;
   try {
     dtStart = ParsedDateTime.parse(dtStartStr, tzmap);
   } catch (ParseException e) {
     throw ServiceException.INVALID_REQUEST("Bad date/time value \"" + dtStartStr + "\"", e);
   }
   // DURATION
   ParsedDuration dur = timeRange.getDuration();
   // RRULE
   String dayName = DayOfWeekName.lookup(dayOfWeek);
   String ruleStr = String.format("FREQ=WEEKLY;INTERVAL=1;BYDAY=%s", dayName);
   return new Recurrence.SimpleRepeatingRule(dtStart, dur, new ZRecur(ruleStr, tzmap), null);
 }
コード例 #9
0
 public static UCServiceBy fromString(String s) throws ServiceException {
   try {
     return UCServiceBy.valueOf(s);
   } catch (IllegalArgumentException e) {
     throw ServiceException.INVALID_REQUEST("unknown key: " + s, e);
   }
 }
コード例 #10
0
 public static Operation fromString(String s) throws ServiceException {
   try {
     return Operation.valueOf(s);
   } catch (IllegalArgumentException e) {
     throw ServiceException.INVALID_REQUEST("unknown operation: " + s, e);
   }
 }
コード例 #11
0
ファイル: TargetType.java プロジェクト: koem/Zimbra
 public static TargetType fromCode(String s) throws ServiceException {
   try {
     return TargetType.valueOf(s);
   } catch (IllegalArgumentException e) {
     throw ServiceException.INVALID_REQUEST("unknown target type: " + s, e);
   }
 }
コード例 #12
0
ファイル: CollectConfigFiles.java プロジェクト: huu0510/z-pec
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    try {
      // check the auth token
      AuthToken authToken = getAdminAuthTokenFromCookie(req, resp);
      if (authToken == null) return;
      // take the host name
      Provisioning prov = Provisioning.getInstance();
      String hostName = req.getParameter(P_HOST);
      Server server = prov.get(Key.ServerBy.name, hostName);
      if (server == null) {
        throw ServiceException.INVALID_REQUEST(
            "server with name " + hostName + " could not be found", null);
      }
      // call RemoteManager
      RemoteManager rmgr = RemoteManager.getRemoteManager(server);
      RemoteResult rr = rmgr.execute(RemoteCommands.COLLECT_CONFIG_FILES);
      // stream the data
      resp.setContentType(DOWNLOAD_CONTENT_TYPE);
      ContentDisposition cd =
          new ContentDisposition(Part.INLINE).setParameter("filename", hostName + ".conf.tgz");
      resp.addHeader("Content-Disposition", cd.toString());
      ByteUtil.copy(new ByteArrayInputStream(rr.getMStdout()), true, resp.getOutputStream(), false);
    } catch (ServiceException e) {
      returnError(resp, e);
      return;
    }
  }
コード例 #13
0
 // timeStr must have the format HHMM.  Hour range is 0-24, and minute range is 0-59.
 // Special value "2400" is allowed for denoting end time of the working hours that coincides
 // with the end of the day.
 public HourMinute(String hhmmStr, boolean isEndTime, String dayStr) throws ServiceException {
   boolean good = false;
   if (hhmmStr.length() == 4) {
     try {
       int hh = Integer.parseInt(hhmmStr.substring(0, 2));
       int mm = Integer.parseInt(hhmmStr.substring(2));
       if ((hh >= 0 && hh <= 23 && mm >= 0 && mm <= 59) || (isEndTime && hh == 24 && mm == 0)) {
         hour = hh;
         minute = mm;
         good = true;
       }
     } catch (NumberFormatException e) {
     }
   }
   if (!good)
     throw ServiceException.INVALID_REQUEST(
         "Working hours spec day section \""
             + dayStr
             + "\" has invalid "
             + (isEndTime ? "end" : "start")
             + " time \""
             + hhmmStr
             + "\"",
         null);
 }
コード例 #14
0
 public static AdsConnectionType fromString(String s) throws ServiceException {
   try {
     return AdsConnectionType.valueOf(s);
   } catch (IllegalArgumentException e) {
     throw ServiceException.INVALID_REQUEST(
         "invalid type: " + s + ", valid values: " + Arrays.asList(AdsConnectionType.values()), e);
   }
 }
コード例 #15
0
  @Override
  public String accountDNCreate(String baseDn, IAttributes attrs, String localPart, String domain)
      throws ServiceException {
    if (baseDn == null)
      throw ServiceException.INVALID_REQUEST(
          "base dn is required in DIT impl " + getClass().getCanonicalName(), null);

    return acctAndDLDNCreate(baseDn, attrs);
  }
コード例 #16
0
ファイル: RightDocumentHandler.java プロジェクト: koem/Zimbra
  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);
  }
コード例 #17
0
ファイル: Backup.java プロジェクト: Grynn/SnapCreator
    private long getCutoffTime(String val, BackupTarget target)
        throws ServiceException, IOException
    {
        if(val.indexOf('/') != -1)
            try
            {
                return Utils.parseDate(val);
            }
            catch(ParseException e)
            {
                throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("invalid date: ").append(val).toString(), e);
            }
        String d = val.toLowerCase().trim();
        if(d.endsWith("d") || d.endsWith("m") || d.endsWith("y"))
        {
            int len = d.length();
            char unit = d.charAt(len - 1);
            int num = Integer.parseInt(d.substring(0, len - 1));
            if(num < 0)
                throw ServiceException.INVALID_REQUEST("invalid cutoff period: negative value means cutoff date in the future", null);
            Calendar today = Calendar.getInstance();
            switch(unit)
            {
            case 100: // 'd'
                today.add(5, -num);
                break;

            case 109: // 'm'
                today.add(2, -num);
                break;

            case 121: // 'y'
                today.add(1, -num);
                break;
            }
            return today.getTimeInMillis();
        } else
        {
            return BackupManager.getLabelDate(val);
        }
    }
コード例 #18
0
 public void setExpandAllAttrs(String types) throws ServiceException {
   expandGetAttrs = null;
   expandSetAttrs = null;
   for (String typeString : COMMA_SPLITTER.split(types)) {
     String exp = typeString.trim();
     if (exp.equals(EXPAND_SET_ATTRS)) expandSetAttrs = true;
     else if (exp.equals(EXPAND_GET_ATTRS)) expandGetAttrs = true;
     else
       throw ServiceException.INVALID_REQUEST(
           "invalid " + AdminConstants.A_EXPAND_ALL_ATTRS + " value: " + exp, null);
   }
 }
コード例 #19
0
  @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);
  }
コード例 #20
0
ファイル: Backup.java プロジェクト: Grynn/SnapCreator
    protected List parseAccountNames(List acctElems)
        throws ServiceException
    {
        List a = new ArrayList(acctElems.size());
        String name;
        for(Iterator i$ = acctElems.iterator(); i$.hasNext(); a.add(name.toLowerCase()))
        {
            Element elem = (Element)i$.next();
            name = elem.getAttribute("name");
            if("all".equals(name))
            {
                if(acctElems.size() != 1)
                    throw ServiceException.INVALID_REQUEST("\"all\" cannot be mixed with specific account names", null);
                continue;
            }
            String parts[] = name.split("@");
            if(parts.length != 2)
                throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("invalid account email address: ").append(name).toString(), null);
        }

        return a;
    }
コード例 #21
0
  /*
   * ========================================================================================
   */
  @Override
  public SpecialAttrs handleSpecialAttrs(Map<String, Object> attrs) throws ServiceException {

    // check for required attrs
    if (SpecialAttrs.getSingleValuedAttr(attrs, SpecialAttrs.PA_ldapBase) == null)
      throw ServiceException.INVALID_REQUEST(
          "missing required attribute " + SpecialAttrs.PA_ldapBase, null);

    if (!NAMING_RDN_ATTR_USER.equals(DEFAULT_NAMING_RDN_ATTR_USER)) {
      if (SpecialAttrs.getSingleValuedAttr(attrs, NAMING_RDN_ATTR_USER) == null)
        throw ServiceException.INVALID_REQUEST(
            "missing required attribute " + NAMING_RDN_ATTR_USER, null);
    }

    SpecialAttrs specialAttrs = new SpecialAttrs();
    if (attrs != null) {
      specialAttrs.handleZimbraId(attrs);
      specialAttrs.handleLdapBaseDn(attrs);
    }

    return specialAttrs;
  }
コード例 #22
0
  private void doit(ZAuthToken zat, String[] accts, boolean sync)
      throws SoapFaultException, IOException, ServiceException {
    Element req = new Element.XMLElement(AdminConstants.FIX_CALENDAR_PRIORITY_REQUEST);
    if (accts == null || accts.length == 0)
      throw ServiceException.INVALID_REQUEST("Missing -" + O_ACCOUNT + " option", null);
    for (String acct : accts) {
      Element acctElem = req.addElement(AdminConstants.E_ACCOUNT);
      acctElem.addAttribute(AdminConstants.A_NAME, acct);
    }
    if (sync) req.addAttribute(AdminConstants.A_TZFIXUP_SYNC, true);

    auth(zat);
    getTransport().invokeWithoutSession(req);
  }
コード例 #23
0
ファイル: DelegateAuth.java プロジェクト: huu0510/z-pec
  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;
  }
コード例 #24
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);

    ExportContactsRequest req = JaxbUtil.elementToJaxb(request);
    String folder = req.getFolderId();
    ItemId iidFolder = folder == null ? null : new ItemId(folder, zsc);

    String ct = req.getContentType();
    if (ct == null) throw ServiceException.INVALID_REQUEST("content type missing", null);
    if (!ct.equals("csv"))
      throw ServiceException.INVALID_REQUEST("unsupported content type: " + ct, null);

    String format = req.getCsvFormat();
    String locale = req.getCsvLocale();
    String separator = req.getCsvDelimiter();
    Character sepChar = null;
    if ((separator != null) && (separator.length() > 0)) sepChar = separator.charAt(0);

    List<Contact> contacts = mbox.getContactList(octxt, iidFolder != null ? iidFolder.getId() : -1);

    StringBuilder sb = new StringBuilder();
    if (contacts == null) contacts = new ArrayList<Contact>();

    try {
      ContactCSV contactCSV = new ContactCSV(mbox, octxt);
      contactCSV.toCSV(format, locale, sepChar, contacts.iterator(), sb);
    } catch (ContactCSV.ParseException e) {
      throw MailServiceException.UNABLE_TO_EXPORT_CONTACTS(e.getMessage(), e);
    }

    ExportContactsResponse resp = new ExportContactsResponse(sb.toString());
    return zsc.jaxbToElement(resp);
  }
コード例 #25
0
  @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;
  }
コード例 #26
0
ファイル: Backup.java プロジェクト: Grynn/SnapCreator
 private static boolean parseIncludeExcludeAttr(String attrVal, boolean defaultVal)
     throws ServiceException
 {
     boolean skip;
     if(attrVal == null || attrVal.equalsIgnoreCase("config"))
         skip = defaultVal;
     else
     if(attrVal.equalsIgnoreCase("exclude"))
         skip = true;
     else
     if(attrVal.equalsIgnoreCase("include"))
         skip = false;
     else
         throw ServiceException.INVALID_REQUEST((new StringBuilder()).append("Invalid include/exclude value \"").append(attrVal).append("\"").toString(), null);
     return skip;
 }
コード例 #27
0
ファイル: GalUtil.java プロジェクト: TaNhoSy/zimbra-mirror
  private static String expandKey(String tokenize, String filterTemplate, String key)
      throws ServiceException {

    if (!filterTemplate.startsWith("(")) {
      if (filterTemplate.endsWith(")"))
        throw ServiceException.INVALID_REQUEST(
            "Unbalanced parenthesis in filter:" + filterTemplate, null);

      filterTemplate = "(" + filterTemplate + ")";
    }

    String query = null;
    Map<String, String> vars = new HashMap<String, String>();

    ZLdapFilterFactory filterFactory = ZLdapFilterFactory.getInstance();

    if (tokenize != null) {
      String tokens[] = key.split("\\s+");
      if (tokens.length > 1) {
        String q;
        if (GalConstants.TOKENIZE_KEY_AND.equals(tokenize)) {
          q = "(&";
        } else if (GalConstants.TOKENIZE_KEY_OR.equals(tokenize)) {
          q = "(|";
        } else {
          throw ServiceException.FAILURE(
              "invalid attribute value for tokenize key: " + tokenize, null);
        }

        for (String t : tokens) {
          vars.clear();
          vars.put("s", filterFactory.encodeValue(t));
          q = q + LdapUtil.expandStr(filterTemplate, vars);
        }
        q = q + ")";
        query = q;
      }
    }

    if (query == null) {
      vars.put("s", key == null ? null : filterFactory.encodeValue(key));
      query = LdapUtil.expandStr(filterTemplate, vars);
    }

    return query;
  }
コード例 #28
0
ファイル: Period.java プロジェクト: nullin/zimbra-sources
  public static Period parse(String value, ICalTimeZone tz, TimeZoneMap tzmap)
      throws ServiceException, ParseException {
    String parsed[] = value.split("\\/", 2);
    if (parsed.length != 2 || parsed[0].length() == 0 || parsed[1].length() == 1)
      throw ServiceException.INVALID_REQUEST("Invalid PERIOD value \"" + value + "\"", null);

    ParsedDateTime startTime;
    startTime = ParsedDateTime.parse(parsed[0], tzmap, tz, tzmap.getLocalTimeZone());

    char ch = parsed[1].charAt(0);
    if (ch == 'P' || ch == '+' || ch == '-') {
      ParsedDuration duration = ParsedDuration.parse(parsed[1]);
      return new Period(startTime, duration);
    } else {
      ParsedDateTime endTime = ParsedDateTime.parse(parsed[1], tzmap, tz, tzmap.getLocalTimeZone());
      return new Period(startTime, endTime);
    }
  }
コード例 #29
0
ファイル: RightDocumentHandler.java プロジェクト: koem/Zimbra
  protected Pair<Boolean, Boolean> parseExpandAttrs(Element request) throws ServiceException {
    String expandAttrs = request.getAttribute(AdminConstants.A_EXPAND_ALL_ATTRS, null);
    boolean expandSetAttrs = false;
    boolean expandGetAttrs = false;
    if (expandAttrs != null) {
      String[] eas = expandAttrs.split(",");
      for (String e : eas) {
        String exp = e.trim();
        if (exp.equals("setAttrs")) expandSetAttrs = true;
        else if (exp.equals("getAttrs")) expandGetAttrs = true;
        else
          throw ServiceException.INVALID_REQUEST(
              "invalid " + AdminConstants.A_EXPAND_ALL_ATTRS + " value: " + exp, null);
      }
    }

    return new Pair<Boolean, Boolean>(expandSetAttrs, expandGetAttrs);
  }
コード例 #30
0
ファイル: Search.java プロジェクト: judasprees/zimbra-sources
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    Account account = getRequestedAccount(zsc);
    OperationContext octxt = getOperationContext(zsc, context);

    SearchRequest req = JaxbUtil.elementToJaxb(request);
    if (Objects.firstNonNull(req.getWarmup(), false)) {
      mbox.index.getIndexStore().warmup();
      return zsc.createElement(MailConstants.SEARCH_RESPONSE);
    }

    SearchParams params = SearchParams.parse(req, zsc, account.getPrefMailInitialSearch());
    if (params.getLocale() == null) {
      params.setLocale(mbox.getAccount().getLocale());
    }
    if (params.inDumpster() && params.getTypes().contains(MailItem.Type.CONVERSATION)) {
      throw ServiceException.INVALID_REQUEST("cannot search for conversations in dumpster", null);
    }

    if (LC.calendar_cache_enabled.booleanValue()) {
      List<String> apptFolderIds = getFolderIdListIfSimpleAppointmentsQuery(params, zsc);
      if (apptFolderIds != null) {
        Account authAcct = getAuthenticatedAccount(zsc);
        Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
        runSimpleAppointmentQuery(response, params, octxt, zsc, authAcct, mbox, apptFolderIds);
        return response;
      }
    }

    ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
    try {
      // create the XML response Element
      Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
      // must use results.getSortBy() because the results might have ignored our sortBy
      // request and used something else...
      response.addAttribute(MailConstants.A_SORTBY, results.getSortBy().toString());
      putHits(zsc, octxt, response, results, params);
      return response;
    } finally {
      Closeables.closeQuietly(results);
    }
  }