protected String getVal(Single term) {
      String rhs = term.getRhs();

      AttributeManager attrMgr = null;
      try {
        attrMgr = AttributeManager.getInstance();
      } catch (ServiceException e) {
        ZimbraLog.account.warn("failed to get AttributeManager instance", e);
      }

      IDNType idnType = AttributeManager.idnType(attrMgr, term.getLhs());
      rhs = IDNUtil.toAscii(rhs, idnType);

      return rhs;
    }
Example #2
0
  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;
  }
  @Override // ZMutableEntry
  public void mapToAttrs(Map<String, Object> mapAttrs) {
    AttributeManager attrMgr = AttributeManager.getInst();

    for (Map.Entry<String, Object> me : mapAttrs.entrySet()) {

      String attrName = me.getKey();
      Object v = me.getValue();

      boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
      boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);

      if (v instanceof String) {
        ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String) v);
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
        entry.addAttribute(a);
      } else if (v instanceof String[]) {
        String[] sa = (String[]) v;
        ASN1OctetString[] values = new ASN1OctetString[sa.length];
        for (int i = 0; i < sa.length; i++) {
          values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
        }
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
        entry.addAttribute(a);
      } else if (v instanceof Collection) {
        Collection c = (Collection) v;
        ASN1OctetString[] values = new ASN1OctetString[c.size()];
        int i = 0;
        for (Object o : c) {
          values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
          i++;
        }
        Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
        entry.addAttribute(a);
      }
    }
  }
Example #4
0
 static Set<String> getAttrsInClass(Entry target) throws ServiceException {
   AttributeClass klass = TargetType.getAttributeClass(target);
   return AttributeManager.getInstance().getAllAttrsInClass(klass);
 }