本文整理汇总了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;
}