本文整理汇总了Java中org.apache.http.auth.AuthState.getAuthScheme方法的典型用法代码示例。如果您正苦于以下问题:Java AuthState.getAuthScheme方法的具体用法?Java AuthState.getAuthScheme怎么用?Java AuthState.getAuthScheme使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.auth.AuthState
的用法示例。
在下文中一共展示了AuthState.getAuthScheme方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(HttpRequest request, HttpContext context) throws HttpException,
IOException {
AuthState authState = (AuthState) context.getAttribute("http.auth.target-scope");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute("http.auth" +
".credentials-provider");
HttpHost targetHost = (HttpHost) context.getAttribute("http.target_host");
if (authState.getAuthScheme() == null) {
Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName
(), targetHost.getPort()));
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
示例2: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
// If no auth scheme avaialble yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {
Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.setAuthScheme(authScheme);
authState.setCredentials(creds);
}
}
}
示例3: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
//
// get the authentication state for the request
//
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
//
// if no auth scheme avaialble yet, try to initialize it preemptively
//
if (authState.getAuthScheme() == null) {
// check if credentials are set
if (this.credentials == null) {
throw new HttpException("No credentials for preemptive authentication");
}
// add the credentials to the auth state
authState.setAuthScheme(this.basicAuthScheme);
authState.setCredentials(this.credentials);
// HttpHost targetHost = (HttpHost)context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
//CredentialsProvider credsProvider = (CredentialsProvider)context.getAttribute(ClientContext.CREDS_PROVIDER);
}
}
示例4: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
// If no auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
Credentials credentials = credentialsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (credentials != null) {
authState.setAuthScheme(new DiadocAuthScheme());
authState.setCredentials(credentials);
}
}
}
示例5: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
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 not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
// Obtain credentials matching the target host
org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
// If found, generate BasicScheme preemptively
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
示例6: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
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 not auth scheme has been initialized yet
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
org.apache.http.auth.Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
示例7: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
public void process(HttpRequest httpRequest, HttpContext httpContext) throws HttpException, IOException {
AuthState authState = (AuthState) httpContext.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) httpContext.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) httpContext
.getAttribute(HttpClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) httpContext.getAttribute(HttpClientContext.HTTP_TARGET_HOST);
if (authScheme != null) {
Credentials creds = credsProvider
.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
示例8: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme avaialble yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
if (authScheme != null) {
Credentials creds = credsProvider.getCredentials(AuthScope.ANY);
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
示例9: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
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 not auth scheme has been initialized yet
if( authState.getAuthScheme() == null )
{
AuthScope authScope = new AuthScope( targetHost.getHostName(),
targetHost.getPort() );
// Obtain credentials matching the target host
Credentials creds = credsProvider.getCredentials( authScope );
// If found, generate BasicScheme preemptively
if( creds != null )
{
authState.setAuthScheme( new BasicScheme() );
authState.setCredentials( creds );
}
}
}
示例10: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
Credentials creds;
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider =
(CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost =
(HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {
creds =
credsProvider.getCredentials(new AuthScope(
targetHost.getHostName(),
targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
示例11: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
final AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme available yet, try to initialize it
// preemptively
if (authState.getAuthScheme() == null) {
final CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(HttpClientContext.CREDS_PROVIDER);
final HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
final AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
final Credentials creds = credsProvider.getCredentials(authScope);
if (creds == null) {
LOGGER.debug("Cannot initiate preemtive authentication, Credentials not found!");
}
authState.update(new BasicScheme(), creds);
}
}
示例12: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
// If no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {
Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds != null) {
authState.setAuthScheme(authScheme);
authState.setCredentials(creds);
}
}
}
}
示例13: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
HttpClientContext clientContext = HttpClientContext.adapt(context);
AuthState authState = clientContext.getTargetAuthState();
// If there's no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
CredentialsProvider credsProvider = clientContext.getCredentialsProvider();
HttpHost targetHost = clientContext.getTargetHost();
Credentials creds = credsProvider.getCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
log.debug("No credentials found for host " + targetHost);
} else {
log.debug("Updating credentials for host " + targetHost);
authState.update(new BasicScheme(), creds);
}
}
}
示例14: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
if (authState.getAuthScheme() == null) {
CredentialsProvider credsProvider = (CredentialsProvider) context
.getAttribute(HttpClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST);
Credentials creds = credsProvider
.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials given for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
示例15: process
import org.apache.http.auth.AuthState; //导入方法依赖的package包/类
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
// If no auth scheme available yet, try to initialize it preemptively
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
if (authScheme != null) {
Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}