Exemple #1
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);
    }
  }