本文整理汇总了Java中org.apache.http.auth.AuthState.getState方法的典型用法代码示例。如果您正苦于以下问题:Java AuthState.getState方法的具体用法?Java AuthState.getState怎么用?Java AuthState.getState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.auth.AuthState
的用法示例。
在下文中一共展示了AuthState.getState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAuthenticationRequested
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public boolean isAuthenticationRequested(
final HttpHost host,
final HttpResponse response,
final AuthenticationStrategy authStrategy,
final AuthState authState,
final HttpContext context) {
if (authStrategy.isAuthenticationRequested(host, response, context)) {
return true;
} else {
switch (authState.getState()) {
case CHALLENGED:
case HANDSHAKE:
authState.setState(AuthProtocolState.SUCCESS);
authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
break;
case SUCCESS:
break;
default:
authState.setState(AuthProtocolState.UNCHALLENGED);
}
return false;
}
}
示例2: isAuthenticationRequested
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public boolean isAuthenticationRequested(
final HttpHost host,
final HttpResponse response,
final AuthenticationStrategy authStrategy,
final AuthState authState,
final HttpContext context) {
if (authStrategy.isAuthenticationRequested(host, response, context)) {
this.log.debug("Authentication required");
if (authState.getState() == AuthProtocolState.SUCCESS) {
authStrategy.authFailed(host, authState.getAuthScheme(), context);
}
return true;
} else {
switch (authState.getState()) {
case CHALLENGED:
case HANDSHAKE:
this.log.debug("Authentication succeeded");
authState.setState(AuthProtocolState.SUCCESS);
authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
break;
case SUCCESS:
break;
default:
authState.setState(AuthProtocolState.UNCHALLENGED);
}
return false;
}
}
示例3: isAuthenticationRequested
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
/**
* Determines if the given HTTP response response represents
* an authentication challenge that was sent back as a result
* of authentication failure.
*
* @param authHost authentication host.
* @param response HTTP response.
* @param context HTTP context.
* @return {@code true} if user authentication is required,
* {@code false} otherwise.
*/
@Override
public boolean isAuthenticationRequested(final HttpHost authHost,
final HttpResponse response,
final HttpContext context) {
final StatusLine line = response.getStatusLine();
final int code = line.getStatusCode();
final HttpClientContext clientContext = HttpClientContext.adapt(context);
final AuthState authState = clientContext.getTargetAuthState();
final AuthProtocolState authProtocolState = authState.getState();
if (code == HttpStatus.SC_UNAUTHORIZED) {
if (authProtocolState.equals(AuthProtocolState.CHALLENGED)) {
clientContext.getTargetAuthState().setState(AuthProtocolState.FAILURE);
authFailed(authHost, authState.getAuthScheme(), context);
}
return true;
}
if (clientContext.getTargetAuthState() == null) {
return true;
}
return false;
}
示例4: authenticate
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public boolean authenticate(
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");
}
Map<String, Header> challenges = authStrategy.getChallenges(host, response, context);
if (challenges.isEmpty()) {
this.log.debug("Response contains no authentication challenges");
return false;
}
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) {
String id = authScheme.getSchemeName();
Header challenge = challenges.get(id.toLowerCase(Locale.US));
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
}
}
}
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 (MalformedChallengeException ex) {
if (this.log.isWarnEnabled()) {
this.log.warn("Malformed challenge: " + ex.getMessage());
}
authState.reset();
return false;
}
}
示例5: handleAuthChallenge
import org.apache.http.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.ROOT));
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;
}
}