Exemplo n.º 1
0
 private void initTagDataSource(OfflineAccount account) throws ServiceException {
   OfflineProvisioning prov = OfflineProvisioning.getOfflineInstance();
   tagDs = account.getDataSourceByName(dsName);
   if (tagDs == null) {
     OfflineLog.offline.debug("initializing tag datasource");
     tagDs =
         prov.createDataSource(
             account, DataSourceType.tagmap, dsName, new HashMap<String, Object>());
     // initially any previously existing local tags also have same ID as remote.
     List<Tag> tags = mbox.getTagList(null);
     for (Tag tag : tags) {
       mapTag(tag.getId(), tag.getId());
     }
   }
 }
Exemplo n.º 2
0
 private Account getLockAccount(String accountId) throws ServiceException {
   Account acct = null;
   if (accountId == null || OfflineProvisioning.LOCAL_ACCOUNT_ID.equalsIgnoreCase(accountId)) {
     acct = getAccount();
   } else {
     acct = OfflineProvisioning.getOfflineInstance().getAccount(accountId);
   }
   return acct;
 }
Exemplo n.º 3
0
 public Element sendRequestWithNotification(Element request) throws ServiceException {
   Server server =
       Provisioning.getInstance()
           .get(Key.ServerBy.name, OfflineConstants.SYNC_SERVER_PREFIX + getAccountId());
   if (server != null) {
     // when we first add an account, server is still null
     List<Session> soapSessions = getListeners(Session.Type.SOAP);
     Session session = null;
     if (soapSessions.size() == 1) {
       session = soapSessions.get(0);
     } else if (soapSessions.size() > 1) {
       // this occurs if user refreshes web browser (or opens ZD in two different browsers); older
       // session does not time out so there are now two listening
       // only the most recent is 'active'
       for (Session ses : soapSessions) {
         if (session == null || ses.accessedAfter(session.getLastAccessTime())) {
           session = ses;
         }
       }
     }
     if (session != null) {
       ZAuthToken zat = getAuthToken();
       if (zat != null) {
         AuthToken at =
             AuthProvider.getAuthToken(OfflineProvisioning.getOfflineInstance().getLocalAccount());
         at.setProxyAuthToken(zat.getValue());
         ProxyTarget proxy = new ProxyTarget(server, at, getSoapUri());
         // zscProxy needs to be for the 'ffffff-' account, but with target of *this* mailbox's
         // acct
         // currently UI receives SoapJS in its responses, we ask for that protocol so
         // notifications are handled correctly
         ZimbraSoapContext zscIn =
             new ZimbraSoapContext(
                 at, at.getAccountId(), SoapProtocol.Soap12, SoapProtocol.SoapJS);
         ZimbraSoapContext zscProxy = new ZimbraSoapContext(zscIn, getAccountId(), session);
         proxy.setTimeouts(OfflineLC.zdesktop_request_timeout.intValue());
         return DocumentHandler.proxyWithNotification(request, proxy, zscProxy, session);
       }
     }
   }
   return sendRequest(request);
 }
Exemplo n.º 4
0
  @Override
  void ensureSystemFolderExists() throws ServiceException {
    lock.lock();
    try {
      super.ensureSystemFolderExists();
      try {
        getFolderById(ID_FOLDER_NOTIFICATIONS);
      } catch (NoSuchItemException e) {
        Folder.FolderOptions fopt =
            new Folder.FolderOptions().setAttributes(Folder.FOLDER_IS_IMMUTABLE);

        CreateFolder redo =
            new CreateFolder(getId(), NOTIFICATIONS_PATH, ID_FOLDER_USER_ROOT, fopt);

        redo.setFolderIdAndUuid(ID_FOLDER_NOTIFICATIONS, UUIDUtil.generateUUID());
        redo.start(System.currentTimeMillis());
        createFolder(new TracelessContext(redo), NOTIFICATIONS_PATH, ID_FOLDER_USER_ROOT, fopt);
      }
      OfflineProvisioning prov = OfflineProvisioning.getOfflineInstance();
      for (String accountId : prov.getAllAccountIds()) {
        Account acct = prov.get(AccountBy.id, accountId);
        if (acct == null || prov.isGalAccount(acct) || prov.isMountpointAccount(acct)) continue;
        try {
          getFolderByName(null, ID_FOLDER_NOTIFICATIONS, accountId);
        } catch (NoSuchItemException e) {
          createMountpoint(
              null,
              ID_FOLDER_NOTIFICATIONS,
              accountId,
              accountId,
              ID_FOLDER_USER_ROOT,
              null,
              MailItem.Type.UNKNOWN,
              0,
              MailItem.DEFAULT_COLOR_RGB,
              false);
        }
      }
    } finally {
      lock.release();
    }
  }
 @Override
 public List<Proxy> select(URI uri) {
   OfflineProvisioning prov = OfflineProvisioning.getOfflineInstance();
   List<Proxy> proxies = new ArrayList<Proxy>();
   try {
     String mode =
         prov.getLocalAccount().getAttr(OfflineProvisioning.A_zimbraPrefOfflineAttrProxyMode);
     if (Mode.MANUAL.toString().equals(mode)) {
       if (uri.getHost().indexOf("localhost") < 0 && uri.getHost().indexOf("127.0.0.1") < 0) {
         Account localAcct = prov.getLocalAccount();
         ProxyAuthenticator proxyAuth = new ProxyAuthenticator();
         // HTTP
         if (uri.getScheme().indexOf("http") == 0) {
           String proxyHost =
               localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineHttpProxyHost);
           int proxyPort =
               localAcct.getIntAttr(OfflineProvisioning.A_zimbraPrefOfflineHttpProxyPort, -1);
           String proxyUsername =
               localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineHttpProxyUsername);
           String proxyPassword =
               localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineHttpProxyPassword);
           addProxy(
               Proxy.Type.HTTP,
               proxyHost,
               proxyPort,
               proxyUsername,
               proxyPassword,
               proxies,
               proxyAuth);
         }
         // SOCKS
         String proxyHost =
             localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineSocksProxyHost);
         int proxyPort =
             localAcct.getIntAttr(OfflineProvisioning.A_zimbraPrefOfflineSocksProxyPort, -1);
         String proxyUsername =
             localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineSocksProxyUsername);
         String proxyPassword =
             localAcct.getAttr(OfflineProvisioning.A_zimbraPrefOfflineSocksProxyPassword);
         addProxy(
             Proxy.Type.SOCKS,
             proxyHost,
             proxyPort,
             proxyUsername,
             proxyPassword,
             proxies,
             proxyAuth);
         // configure authentication for 3rd party libraries (like gdata) that use
         // HttpUrlConnection
         Authenticator.setDefault(proxyAuth);
       }
     } else if (mode == null || Mode.SYSTEM.toString().equals(mode)) {
       // if not set yet use old default behavior; system proxy settings
       return ps.select(uri);
     }
   } catch (ServiceException e) {
     OfflineLog.offline.error("ServiceException configuring manual proxy; assuming disabled", e);
   }
   if (proxies.isEmpty()) {
     proxies.add(Proxy.NO_PROXY);
   }
   return proxies;
 }