本文整理汇总了Java中ch.boye.httpclientandroidlib.auth.AuthState.getAuthScheme方法的典型用法代码示例。如果您正苦于以下问题:Java AuthState.getAuthScheme方法的具体用法?Java AuthState.getAuthScheme怎么用?Java AuthState.getAuthScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.boye.httpclientandroidlib.auth.AuthState
的用法示例。
在下文中一共展示了AuthState.getAuthScheme方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isCachable
import ch.boye.httpclientandroidlib.auth.AuthState; //导入方法依赖的package包/类
private boolean isCachable(final AuthState authState) {
final AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
final String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例2: getAuthPrincipal
import ch.boye.httpclientandroidlib.auth.AuthState; //导入方法依赖的package包/类
private static Principal getAuthPrincipal(final AuthState authState) {
final AuthScheme scheme = authState.getAuthScheme();
if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) {
final Credentials creds = authState.getCredentials();
if (creds != null) {
return creds.getUserPrincipal();
}
}
return null;
}
示例3: process
import ch.boye.httpclientandroidlib.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
示例4: handleAuthChallenge
import ch.boye.httpclientandroidlib.auth.AuthState; //导入方法依赖的package包/类
public boolean handleAuthChallenge(
final HttpHost host,
final HttpResponse response,
final AuthenticationStrategy authStrategy,
final AuthState authState,
final HttpContext context) {
try {
if (this.log.isDebugEnabled()) {
this.log.debug(host.toHostString() + " requested authentication");
}
final Map<String, Header> challenges = authStrategy.getChallenges(host, response, context);
if (challenges.isEmpty()) {
this.log.debug("Response contains no authentication challenges");
return false;
}
final AuthScheme authScheme = authState.getAuthScheme();
switch (authState.getState()) {
case FAILURE:
return false;
case SUCCESS:
authState.reset();
break;
case CHALLENGED:
case HANDSHAKE:
if (authScheme == null) {
this.log.debug("Auth scheme is null");
authStrategy.authFailed(host, null, context);
authState.reset();
authState.setState(AuthProtocolState.FAILURE);
return false;
}
case UNCHALLENGED:
if (authScheme != null) {
final String id = authScheme.getSchemeName();
final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) {
this.log.debug("Authorization challenge processed");
authScheme.processChallenge(challenge);
if (authScheme.isComplete()) {
this.log.debug("Authentication failed");
authStrategy.authFailed(host, authState.getAuthScheme(), context);
authState.reset();
authState.setState(AuthProtocolState.FAILURE);
return false;
} else {
authState.setState(AuthProtocolState.HANDSHAKE);
return true;
}
} else {
authState.reset();
// Retry authentication with a different scheme
}
}
}
final Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context);
if (authOptions != null && !authOptions.isEmpty()) {
if (this.log.isDebugEnabled()) {
this.log.debug("Selected authentication options: " + authOptions);
}
authState.setState(AuthProtocolState.CHALLENGED);
authState.update(authOptions);
return true;
} else {
return false;
}
} catch (final MalformedChallengeException ex) {
if (this.log.isWarnEnabled()) {
this.log.warn("Malformed challenge: " + ex.getMessage());
}
authState.reset();
return false;
}
}