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

项目: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;
}
项目:FMTech    文件:AuthenticatorAdapter.java   
public final Request authenticate(Proxy paramProxy, Response paramResponse)
  throws IOException
{
  List localList = paramResponse.challenges();
  Request localRequest = paramResponse.request;
  URL localURL = localRequest.url();
  int i = 0;
  int j = localList.size();
  while (i < j)
  {
    Challenge localChallenge = (Challenge)localList.get(i);
    if ("Basic".equalsIgnoreCase(localChallenge.scheme))
    {
      PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localURL.getHost(), getConnectToInetAddress(paramProxy, localURL), localURL.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.SERVER);
      if (localPasswordAuthentication != null)
      {
        String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword()));
        return localRequest.newBuilder().header("Authorization", str).build();
      }
    }
    i++;
  }
  return null;
}
项目:FMTech    文件:AuthenticatorAdapter.java   
public final Request authenticateProxy(Proxy paramProxy, Response paramResponse)
  throws IOException
{
  List localList = paramResponse.challenges();
  Request localRequest = paramResponse.request;
  URL localURL = localRequest.url();
  int i = 0;
  int j = localList.size();
  while (i < j)
  {
    Challenge localChallenge = (Challenge)localList.get(i);
    if ("Basic".equalsIgnoreCase(localChallenge.scheme))
    {
      InetSocketAddress localInetSocketAddress = (InetSocketAddress)paramProxy.address();
      PasswordAuthentication localPasswordAuthentication = java.net.Authenticator.requestPasswordAuthentication(localInetSocketAddress.getHostName(), getConnectToInetAddress(paramProxy, localURL), localInetSocketAddress.getPort(), localURL.getProtocol(), localChallenge.realm, localChallenge.scheme, localURL, Authenticator.RequestorType.PROXY);
      if (localPasswordAuthentication != null)
      {
        String str = Credentials.basic(localPasswordAuthentication.getUserName(), new String(localPasswordAuthentication.getPassword()));
        return localRequest.newBuilder().header("Proxy-Authorization", str).build();
      }
    }
    i++;
  }
  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 List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
    List<Challenge> result = new ArrayList();
    int size = responseHeaders.size();
    for (int i = 0; i < size; i++) {
        if (challengeHeader.equalsIgnoreCase(responseHeaders.name(i))) {
            String value = responseHeaders.value(i);
            int pos = 0;
            while (pos < value.length()) {
                int tokenStart = pos;
                pos = HeaderParser.skipUntil(value, pos, " ");
                String scheme = value.substring(tokenStart, pos).trim();
                pos = HeaderParser.skipWhitespace(value, pos);
                if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
                    break;
                }
                pos += "realm=\"".length();
                int realmStart = pos;
                pos = HeaderParser.skipUntil(value, pos, a.e);
                String realm = value.substring(realmStart, pos);
                pos = HeaderParser.skipWhitespace(value, HeaderParser.skipUntil(value, pos +
                        1, ",") + 1);
                result.add(new Challenge(scheme, realm));
            }
        }
    }
    return result;
}
项目:FMTech    文件:OkHeaders.java   
public static List<Challenge> parseChallenges(Headers paramHeaders, String paramString)
{
  ArrayList localArrayList = new ArrayList();
  int i = 0;
  int j = paramHeaders.namesAndValues.length / 2;
  while (i < j)
  {
    if (paramString.equalsIgnoreCase(paramHeaders.name(i)))
    {
      String str1 = paramHeaders.value(i);
      int k = 0;
      while (k < str1.length())
      {
        int m = k;
        int n = HeaderParser.skipUntil(str1, k, " ");
        String str2 = str1.substring(m, n).trim();
        int i1 = HeaderParser.skipWhitespace(str1, n);
        if (!str1.regionMatches(true, i1, "realm=\"", 0, 7)) {
          break;
        }
        int i2 = i1 + 7;
        int i3 = HeaderParser.skipUntil(str1, i2, "\"");
        String str3 = str1.substring(i2, i3);
        k = HeaderParser.skipWhitespace(str1, 1 + HeaderParser.skipUntil(str1, i3 + 1, ","));
        localArrayList.add(new Challenge(str2, str3));
      }
    }
    i++;
  }
  return localArrayList;
}
项目:zsync4j    文件:HttpClient.java   
static boolean containsBasic(Iterable<? extends Challenge> challenges) {
  for (Challenge challenge : challenges) {
    if ("Basic".equalsIgnoreCase(challenge.getScheme())) {
      return true;
    }
  }
  return false;
}
项目:spdymcsclient    文件:OkHeaders.java   
/**
 * Parse RFC 2617 challenges. This API is only interested in the scheme
 * name and realm.
 */
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
  // auth-scheme = token
  // auth-param  = token "=" ( token | quoted-string )
  // challenge   = auth-scheme 1*SP 1#auth-param
  // realm       = "realm" "=" realm-value
  // realm-value = quoted-string
  List<Challenge> result = new ArrayList<>();
  for (int h = 0; h < responseHeaders.size(); h++) {
    if (!challengeHeader.equalsIgnoreCase(responseHeaders.name(h))) {
      continue;
    }
    String value = responseHeaders.value(h);
    int pos = 0;
    while (pos < value.length()) {
      int tokenStart = pos;
      pos = HeaderParser.skipUntil(value, pos, " ");

      String scheme = value.substring(tokenStart, pos).trim();
      pos = HeaderParser.skipWhitespace(value, pos);

      // TODO: This currently only handles schemes with a 'realm' parameter;
      //       It needs to be fixed to handle any scheme and any parameters
      //       http://code.google.com/p/android/issues/detail?id=11140

      if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
        break; // Unexpected challenge parameter; give up!
      }

      pos += "realm=\"".length();
      int realmStart = pos;
      pos = HeaderParser.skipUntil(value, pos, "\"");
      String realm = value.substring(realmStart, pos);
      pos++; // Consume '"' close quote.
      pos = HeaderParser.skipUntil(value, pos, ",");
      pos++; // Consume ',' comma.
      pos = HeaderParser.skipWhitespace(value, pos);
      result.add(new Challenge(scheme, realm));
    }
  }
  return result;
}