本文整理汇总了Java中org.apache.http.auth.AuthSchemeRegistry.getAuthScheme方法的典型用法代码示例。如果您正苦于以下问题:Java AuthSchemeRegistry.getAuthScheme方法的具体用法?Java AuthSchemeRegistry.getAuthScheme怎么用?Java AuthSchemeRegistry.getAuthScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.auth.AuthSchemeRegistry
的用法示例。
在下文中一共展示了AuthSchemeRegistry.getAuthScheme方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
/**
* If no auth scheme has been selected for the given context, consider each
* of the preferred auth schemes and select the first one for which an
* AuthScheme and matching Credentials are available.
*/
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
if (authState != null && authState.getAuthScheme() != null) {
return;
}
HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
CredentialsProvider creds = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
AuthSchemeRegistry schemes = (AuthSchemeRegistry) context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
for (Object schemeName : (Iterable) context.getAttribute(ClientContext.AUTH_SCHEME_PREF)) {
AuthScheme scheme = schemes.getAuthScheme(schemeName.toString(), request.getParams());
if (scheme != null) {
AuthScope targetScope = new AuthScope(target.getHostName(), target.getPort(), scheme.getRealm(), scheme
.getSchemeName());
Credentials cred = creds.getCredentials(targetScope);
if (cred != null) {
authState.setAuthScheme(scheme);
authState.setCredentials(cred);
return;
}
}
}
}
示例2: process
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
/**
* If no auth scheme has been selected for the given context, consider each
* of the preferred auth schemes and select the first one for which an
* AuthScheme and matching Credentials are available.
*/
@SuppressWarnings("rawtypes")
public void process(HttpRequest request, HttpContext context)
throws HttpException, IOException {
AuthState authState = (AuthState) context
.getAttribute(ClientContext.TARGET_AUTH_STATE);
if (authState != null && authState.getAuthScheme() != null) {
return;
}
HttpHost target = (HttpHost) context
.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
CredentialsProvider creds = (CredentialsProvider) context
.getAttribute(ClientContext.CREDS_PROVIDER);
AuthSchemeRegistry schemes = (AuthSchemeRegistry) context
.getAttribute(ClientContext.AUTHSCHEME_REGISTRY);
for (Object schemeName : (Iterable) context
.getAttribute(ClientContext.AUTH_SCHEME_PREF)) {
AuthScheme scheme = schemes.getAuthScheme(schemeName.toString(),
request.getParams());
if (scheme != null) {
AuthScope targetScope = new AuthScope(target.getHostName(),
target.getPort(), scheme.getRealm(),
scheme.getSchemeName());
Credentials cred = creds.getCredentials(targetScope);
if (cred != null) {
authState.setAuthScheme(scheme);
authState.setCredentials(cred);
return;
}
}
}
}
示例3: select
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
public Queue<AuthOption> select(
final Map<String, Header> challenges,
final HttpHost authhost,
final HttpResponse response,
final HttpContext context) throws MalformedChallengeException {
if (challenges == null) {
throw new IllegalArgumentException("Map of auth challenges may not be null");
}
if (authhost == null) {
throw new IllegalArgumentException("Host may not be null");
}
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
Queue<AuthOption> options = new LinkedList<AuthOption>();
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
ClientContext.AUTHSCHEME_REGISTRY);
if (registry == null) {
this.log.debug("Auth scheme registry not set in the context");
return options;
}
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
ClientContext.CREDS_PROVIDER);
if (credsProvider == null) {
this.log.debug("Credentials provider not set in the context");
return options;
}
@SuppressWarnings("unchecked")
List<String> authPrefs = (List<String>) response.getParams().getParameter(this.prefParamName);
if (authPrefs == null) {
authPrefs = DEFAULT_SCHEME_PRIORITY;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Authentication schemes in the order of preference: " + authPrefs);
}
for (String id: authPrefs) {
Header challenge = challenges.get(id.toLowerCase(Locale.US));
if (challenge != null) {
try {
AuthScheme authScheme = registry.getAuthScheme(id, response.getParams());
authScheme.processChallenge(challenge);
AuthScope authScope = new AuthScope(
authhost.getHostName(),
authhost.getPort(),
authScheme.getRealm(),
authScheme.getSchemeName());
Credentials credentials = credsProvider.getCredentials(authScope);
if (credentials != null) {
options.add(new AuthOption(authScheme, credentials));
}
} catch (IllegalStateException e) {
if (this.log.isWarnEnabled()) {
this.log.warn("Authentication scheme " + id + " not supported");
// Try again
}
}
} else {
if (this.log.isDebugEnabled()) {
this.log.debug("Challenge for " + id + " authentication scheme not available");
// Try again
}
}
}
return options;
}
示例4: selectScheme
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
public AuthScheme selectScheme(
final Map<String, Header> challenges,
final HttpResponse response,
final HttpContext context) throws AuthenticationException {
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
ClientContext.AUTHSCHEME_REGISTRY);
if (registry == null) {
throw new IllegalStateException("AuthScheme registry not set in HTTP context");
}
Collection<String> authPrefs = getAuthPreferences(response, context);
if (authPrefs == null) {
authPrefs = DEFAULT_SCHEME_PRIORITY;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Authentication schemes in the order of preference: "
+ authPrefs);
}
AuthScheme authScheme = null;
for (String id: authPrefs) {
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) {
if (this.log.isDebugEnabled()) {
this.log.debug(id + " authentication scheme selected");
}
try {
authScheme = registry.getAuthScheme(id, response.getParams());
break;
} catch (IllegalStateException e) {
if (this.log.isWarnEnabled()) {
this.log.warn("Authentication scheme " + id + " not supported");
// Try again
}
}
} else {
if (this.log.isDebugEnabled()) {
this.log.debug("Challenge for " + id + " authentication scheme not available");
// Try again
}
}
}
if (authScheme == null) {
// If none selected, something is wrong
throw new AuthenticationException(
"Unable to respond to any of these challenges: "
+ challenges);
}
return authScheme;
}
示例5: selectScheme
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
@Override
public AuthScheme selectScheme(
final Map<String, Header> challenges,
final HttpResponse response,
final HttpContext context) throws AuthenticationException {
final AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
ClientContext.AUTHSCHEME_REGISTRY);
Asserts.notNull(registry, "AuthScheme registry");
Collection<String> authPrefs = getAuthPreferences(response, context);
if (authPrefs == null) {
authPrefs = DEFAULT_SCHEME_PRIORITY;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Authentication schemes in the order of preference: "
+ authPrefs);
}
AuthScheme authScheme = null;
for (final String id: authPrefs) {
final Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) {
if (this.log.isDebugEnabled()) {
this.log.debug(id + " authentication scheme selected");
}
try {
authScheme = registry.getAuthScheme(id, response.getParams());
break;
} catch (final IllegalStateException e) {
if (this.log.isWarnEnabled()) {
this.log.warn("Authentication scheme " + id + " not supported");
// Try again
}
}
} else {
if (this.log.isDebugEnabled()) {
this.log.debug("Challenge for " + id + " authentication scheme not available");
// Try again
}
}
}
if (authScheme == null) {
// If none selected, something is wrong
throw new AuthenticationException(
"Unable to respond to any of these challenges: "
+ challenges);
}
return authScheme;
}
示例6: selectScheme
import org.apache.http.auth.AuthSchemeRegistry; //导入方法依赖的package包/类
public AuthScheme selectScheme(
final Map<String, Header> challenges,
final HttpResponse response,
final HttpContext context) throws AuthenticationException {
AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
ClientContext.AUTHSCHEME_REGISTRY);
if (registry == null) {
throw new IllegalStateException("AuthScheme registry not set in HTTP context");
}
@SuppressWarnings("unchecked")
Collection<String> authPrefs = (Collection<String>) context.getAttribute(
ClientContext.AUTH_SCHEME_PREF);
if (authPrefs == null) {
authPrefs = getAuthPreferences();
}
if (this.log.isDebugEnabled()) {
this.log.debug("Authentication schemes in the order of preference: "
+ authPrefs);
}
AuthScheme authScheme = null;
for (String id: authPrefs) {
Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
if (challenge != null) {
if (this.log.isDebugEnabled()) {
this.log.debug(id + " authentication scheme selected");
}
try {
authScheme = registry.getAuthScheme(id, response.getParams());
break;
} catch (IllegalStateException e) {
if (this.log.isWarnEnabled()) {
this.log.warn("Authentication scheme " + id + " not supported");
// Try again
}
}
} else {
if (this.log.isDebugEnabled()) {
this.log.debug("Challenge for " + id + " authentication scheme not available");
// Try again
}
}
}
if (authScheme == null) {
// If none selected, something is wrong
throw new AuthenticationException(
"Unable to respond to any of these challenges: "
+ challenges);
}
return authScheme;
}