Java 类com.squareup.okhttp.Authenticator 实例源码

项目:boohee_v5.6    文件:AuthenticatorAdapter.java   
public Request authenticate(Proxy proxy, Response response) throws IOException {
    List<Challenge> challenges = response.challenges();
    Request request = response.request();
    HttpUrl url = request.httpUrl();
    int size = challenges.size();
    for (int i = 0; i < size; i++) {
        Challenge challenge = (Challenge) challenges.get(i);
        if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
            PasswordAuthentication auth = java.net.Authenticator
                    .requestPasswordAuthentication(url.host(), getConnectToInetAddress(proxy,
                            url), url.port(), url.scheme(), challenge.getRealm(), challenge
                            .getScheme(), url.url(), RequestorType.SERVER);
            if (auth != null) {
                return request.newBuilder().header("Authorization", Credentials.basic(auth
                        .getUserName(), new String(auth.getPassword()))).build();
            }
        }
    }
    return null;
}
项目:boohee_v5.6    文件:AuthenticatorAdapter.java   
public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
    List<Challenge> challenges = response.challenges();
    Request request = response.request();
    HttpUrl url = request.httpUrl();
    int size = challenges.size();
    for (int i = 0; i < size; i++) {
        Challenge challenge = (Challenge) challenges.get(i);
        if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
            InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
            PasswordAuthentication auth = java.net.Authenticator
                    .requestPasswordAuthentication(proxyAddress.getHostName(),
                            getConnectToInetAddress(proxy, url), proxyAddress.getPort(), url
                                    .scheme(), challenge.getRealm(), challenge.getScheme(),
                            url.url(), RequestorType.PROXY);
            if (auth != null) {
                return request.newBuilder().header("Proxy-Authorization", Credentials.basic
                        (auth.getUserName(), new String(auth.getPassword()))).build();
            }
        }
    }
    return null;
}
项目:spdymcsclient    文件:AuthenticatorAdapter.java   
@Override public Request authenticate(Proxy proxy, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  URL url = request.url();
  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue;

    PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication(
        url.getHost(), getConnectToInetAddress(proxy, url), url.getPort(), url.getProtocol(),
        challenge.getRealm(), challenge.getScheme(), url, RequestorType.SERVER);
    if (auth == null) continue;

    String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
    return request.newBuilder()
        .header("Authorization", credential)
        .build();
  }
  return null;

}
项目:spdymcsclient    文件:AuthenticatorAdapter.java   
@Override public Request authenticateProxy(Proxy proxy, Response response) throws IOException {
  List<Challenge> challenges = response.challenges();
  Request request = response.request();
  URL url = request.url();
  for (int i = 0, size = challenges.size(); i < size; i++) {
    Challenge challenge = challenges.get(i);
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) continue;

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = java.net.Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        RequestorType.PROXY);
    if (auth == null) continue;

    String credential = Credentials.basic(auth.getUserName(), new String(auth.getPassword()));
    return request.newBuilder()
        .header("Proxy-Authorization", credential)
        .build();
  }
  return null;
}
项目:boohee_v5.6    文件:OkHeaders.java   
public static Request processAuthHeader(Authenticator authenticator, Response response, Proxy
        proxy) throws IOException {
    if (response.code() == 407) {
        return authenticator.authenticateProxy(proxy, response);
    }
    return authenticator.authenticate(proxy, response);
}
项目:FMTech    文件:OkHeaders.java   
public static Request processAuthHeader(Authenticator paramAuthenticator, Response paramResponse, Proxy paramProxy)
  throws IOException
{
  if (paramResponse.code == 407) {
    return paramAuthenticator.authenticateProxy(paramProxy, paramResponse);
  }
  return paramAuthenticator.authenticate(paramProxy, paramResponse);
}
项目:OkHttpManager    文件:OkHttpManager.java   
/**
 * 设置Http AUTH认证
 *
 * @param authenticator
 * @return
 */
public static OkHttpManager setAuthenticator(Authenticator authenticator) {
    if (null != authenticator) {
        OkHttpClientManager.getInstance().setAuthenticator(authenticator);
    }
    return mInstance;
}
项目:spdymcsclient    文件:OkHeaders.java   
/**
 * React to a failed authorization response by looking up new credentials.
 * Returns a request for a subsequent attempt, or null if no further attempts
 * should be made.
 */
public static Request processAuthHeader(Authenticator authenticator, Response response,
    Proxy proxy) throws IOException {
  return response.code() == HTTP_PROXY_AUTH
      ? authenticator.authenticateProxy(proxy, response)
      : authenticator.authenticate(proxy, response);
}
项目:js-android-sdk    文件:Server.java   
private void configureAuthenticator(OkHttpClient client, AuthStrategy authStrategy) {
    Authenticator recoverableAuthenticator =
            new RecoverableAuthenticator(authStrategy, mCredentials);

    Authenticator authenticator = recoverableAuthenticator;
    if (mAuthenticationPolicy == AuthPolicy.FAIL_FAST) {
        authenticator = new SingleTimeAuthenticator(recoverableAuthenticator);
    }
    client.setAuthenticator(authenticator);
}
项目:OkHttpManager    文件:OkHttpClientManager.java   
public void setAuthenticator(Authenticator authenticator) {
    if (null != authenticator) {
        mClient.setAuthenticator(authenticator);
    }
}
项目:js-android-sdk    文件:SingleTimeAuthenticator.java   
public SingleTimeAuthenticator(Authenticator authenticator) {
    this.authenticator = authenticator;
}