类com.squareup.okhttp.OkAuthenticator.Challenge源码实例Demo

下面列出了怎么用com.squareup.okhttp.OkAuthenticator.Challenge的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: L.TileLayer.Cordova   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码2 项目: L.TileLayer.Cordova   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码3 项目: IoTgo_Android_App   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码4 项目: IoTgo_Android_App   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码5 项目: android-discourse   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 * and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode, RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url) throws IOException {
    String responseField;
    String requestField;
    if (responseCode == HTTP_UNAUTHORIZED) {
        responseField = "WWW-Authenticate";
        requestField = "Authorization";
    } else if (responseCode == HTTP_PROXY_AUTH) {
        responseField = "Proxy-Authenticate";
        requestField = "Proxy-Authorization";
    } else {
        throw new IllegalArgumentException(); // TODO: ProtocolException?
    }
    List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
    if (challenges.isEmpty()) {
        return false; // Could not find a challenge so end the request cycle.
    }
    Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH ? authenticator.authenticateProxy(proxy, url, challenges) : authenticator.authenticate(proxy, url, challenges);
    if (credential == null) {
        return false; // Could not satisfy the challenge so end the request cycle.
    }
    // Add authorization credentials, bypassing the already-connected check.
    successorRequestHeaders.set(requestField, credential.getHeaderValue());
    return true;
}
 
源代码6 项目: bluemix-parking-meter   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码7 项目: bluemix-parking-meter   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码8 项目: reader   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码9 项目: reader   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码10 项目: reader   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码11 项目: reader   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码12 项目: cordova-amazon-fireos   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码13 项目: cordova-amazon-fireos   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码14 项目: phonegapbootcampsite   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码15 项目: phonegapbootcampsite   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码18 项目: wildfly-samples   文件: HttpAuthenticator.java
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码19 项目: wildfly-samples   文件: HttpAuthenticator.java
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
@Override public Credential authenticate(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(),
        getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
源代码22 项目: L.TileLayer.Cordova   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码23 项目: IoTgo_Android_App   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码24 项目: android-discourse   文件: HttpAuthenticator.java
@Override
public Credential authenticate(Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
    for (Challenge challenge : challenges) {
        if (!"Basic".equals(challenge.getScheme())) {
            continue;
        }

        PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(url.getHost(), getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.SERVER);
        if (auth != null) {
            return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
        }
    }
    return null;
}
 
源代码25 项目: android-discourse   文件: HttpAuthenticator.java
@Override
public Credential authenticateProxy(Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
    for (Challenge challenge : challenges) {
        if (!"Basic".equals(challenge.getScheme())) {
            continue;
        }

        InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
        PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url, Authenticator.RequestorType.PROXY);
        if (auth != null) {
            return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
        }
    }
    return null;
}
 
源代码26 项目: bluemix-parking-meter   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码27 项目: reader   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码28 项目: reader   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码29 项目: cordova-amazon-fireos   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
源代码30 项目: phonegapbootcampsite   文件: HttpAuthenticator.java
/**
 * React to a failed authorization response by looking up new credentials.
 *
 * @return true if credentials have been added to successorRequestHeaders
 *         and another request should be attempted.
 */
public static boolean processAuthHeader(OkAuthenticator authenticator, int responseCode,
    RawHeaders responseHeaders, RawHeaders successorRequestHeaders, Proxy proxy, URL url)
    throws IOException {
  String responseField;
  String requestField;
  if (responseCode == HTTP_UNAUTHORIZED) {
    responseField = "WWW-Authenticate";
    requestField = "Authorization";
  } else if (responseCode == HTTP_PROXY_AUTH) {
    responseField = "Proxy-Authenticate";
    requestField = "Proxy-Authorization";
  } else {
    throw new IllegalArgumentException(); // TODO: ProtocolException?
  }
  List<Challenge> challenges = parseChallenges(responseHeaders, responseField);
  if (challenges.isEmpty()) {
    return false; // Could not find a challenge so end the request cycle.
  }
  Credential credential = responseHeaders.getResponseCode() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, url, challenges)
      : authenticator.authenticate(proxy, url, challenges);
  if (credential == null) {
    return false; // Could not satisfy the challenge so end the request cycle.
  }
  // Add authorization credentials, bypassing the already-connected check.
  successorRequestHeaders.set(requestField, credential.getHeaderValue());
  return true;
}
 
 类所在包
 同包方法