本文整理匯總了Java中org.apache.http.impl.auth.BasicScheme.processChallenge方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicScheme.processChallenge方法的具體用法?Java BasicScheme.processChallenge怎麽用?Java BasicScheme.processChallenge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.auth.BasicScheme
的用法示例。
在下文中一共展示了BasicScheme.processChallenge方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAuthSucceeded
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
@Test
public void testAuthSucceeded() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpHost authhost = new HttpHost("somehost", 80);
final BasicScheme authScheme = new BasicScheme();
authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
final AuthCache authCache = Mockito.mock(AuthCache.class);
final HttpClientContext context = HttpClientContext.create();
context.setAuthCache(authCache);
authStrategy.authSucceeded(authhost, authScheme, context);
Mockito.verify(authCache).put(authhost, authScheme);
}
示例2: testAuthSucceededNoCache
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
@Test
public void testAuthSucceededNoCache() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpHost authhost = new HttpHost("somehost", 80);
final BasicScheme authScheme = new BasicScheme();
authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
final HttpClientContext context = HttpClientContext.create();
context.setAuthCache(null);
authStrategy.authSucceeded(authhost, authScheme, context);
final AuthCache authCache = context.getAuthCache();
Assert.assertNotNull(authCache);
}
示例3: testAuthFailed
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
@Test
public void testAuthFailed() throws Exception {
final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy();
final HttpHost authhost = new HttpHost("somehost", 80);
final BasicScheme authScheme = new BasicScheme();
authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test"));
final AuthCache authCache = Mockito.mock(AuthCache.class);
final HttpClientContext context = HttpClientContext.create();
context.setAuthCache(authCache);
authStrategy.authFailed(authhost, authScheme, context);
Mockito.verify(authCache).remove(authhost);
}
示例4: authPreemptive
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
public Executor authPreemptive(final HttpHost host) {
final BasicScheme basicScheme = new BasicScheme();
try {
basicScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC "));
} catch (final MalformedChallengeException ignore) {
}
this.authCache.put(host, basicScheme);
return this;
}
示例5: authPreemptiveProxy
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
public Executor authPreemptiveProxy(final HttpHost proxy) {
final BasicScheme basicScheme = new BasicScheme();
try {
basicScheme.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC "));
} catch (final MalformedChallengeException ignore) {
}
this.authCache.put(proxy, basicScheme);
return this;
}
示例6: getHttpClientContext
import org.apache.http.impl.auth.BasicScheme; //導入方法依賴的package包/類
private HttpClientContext getHttpClientContext() throws Exception {
HttpProxyConfig httpProxyConfig = configRepository.getHttpProxyConfig();
if (httpProxyConfig.host().isEmpty() || httpProxyConfig.username().isEmpty()) {
return HttpClientContext.create();
}
// perform preemptive proxy authentication
int proxyPort = MoreObjects.firstNonNull(httpProxyConfig.port(), 80);
HttpHost proxyHost = new HttpHost(httpProxyConfig.host(), proxyPort);
BasicScheme basicScheme = new BasicScheme();
basicScheme.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC realm="));
BasicAuthCache authCache = new BasicAuthCache();
authCache.put(proxyHost, basicScheme);
String password = httpProxyConfig.password();
if (!password.isEmpty()) {
password = Encryption.decrypt(password, configRepository.getLazySecretKey());
}
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxyHost),
new UsernamePasswordCredentials(httpProxyConfig.username(), password));
HttpClientContext context = HttpClientContext.create();
context.setAuthCache(authCache);
context.setCredentialsProvider(credentialsProvider);
return context;
}