本文整理汇总了Java中com.squareup.okhttp.Authenticator类的典型用法代码示例。如果您正苦于以下问题:Java Authenticator类的具体用法?Java Authenticator怎么用?Java Authenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Authenticator类属于com.squareup.okhttp包,在下文中一共展示了Authenticator类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
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;
}
示例2: authenticate
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
@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;
}
示例3: authenticateProxy
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
@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;
}
示例4: processAuthHeader
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
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);
}
示例5: authenticateProxy
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
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;
}
示例6: processAuthHeader
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
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);
}
示例7: setAuthenticator
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
/**
* 设置Http AUTH认证
*
* @param authenticator
* @return
*/
public static OkHttpManager setAuthenticator(Authenticator authenticator) {
if (null != authenticator) {
OkHttpClientManager.getInstance().setAuthenticator(authenticator);
}
return mInstance;
}
示例8: processAuthHeader
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
/**
* 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);
}
示例9: configureAuthenticator
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
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);
}
示例10: setAuthenticator
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
public void setAuthenticator(Authenticator authenticator) {
if (null != authenticator) {
mClient.setAuthenticator(authenticator);
}
}
示例11: SingleTimeAuthenticator
import com.squareup.okhttp.Authenticator; //导入依赖的package包/类
public SingleTimeAuthenticator(Authenticator authenticator) {
this.authenticator = authenticator;
}