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);
 }
Exemple #2
0
  public static ZAuthToken getZAuthToken(CommandLine cl)
      throws ServiceException, ParseException, IOException {
    if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
      String msg =
          String.format(
              "cannot specify both %s and %s options",
              SoapCLI.O_AUTHTOKEN, SoapCLI.O_AUTHTOKENFILE);
      throw new ParseException(msg);
    }

    if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
      return ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN));
    }

    if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
      String authToken =
          StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
      return ZAuthToken.fromJSONString(authToken);
    }

    return null;
  }
Exemple #3
0
  /**
   * Authenticates using the provided ZAuthToken
   *
   * @throws IOException
   * @throws com.zimbra.common.soap.SoapFaultException
   * @throws ServiceException
   */
  protected LmcSession auth(ZAuthToken zAuthToken)
      throws SoapFaultException, IOException, ServiceException {
    if (zAuthToken == null) return auth();

    URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
    mServerUrl = url.toExternalForm();
    SoapTransport trans = getTransport();
    mAuth = false;

    Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
    zAuthToken.encodeAuthReq(authReq, true);
    try {
      Element authResp = trans.invokeWithoutSession(authReq);
      ZAuthToken zat = new ZAuthToken(authResp.getElement(AdminConstants.E_AUTH_TOKEN), true);
      trans.setAuthToken(zat);
      mAuth = true;
      return new LmcSession(zat, null);
    } catch (UnknownHostException e) {
      // UnknownHostException's error message is not clear; rethrow with a more descriptive message
      throw new IOException("Unknown host: " + mHost);
    }
  }