當前位置: 首頁>>代碼示例>>Java>>正文


Java AuthState.setCredentials方法代碼示例

本文整理匯總了Java中org.apache.http.auth.AuthState.setCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java AuthState.setCredentials方法的具體用法?Java AuthState.setCredentials怎麽用?Java AuthState.setCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.auth.AuthState的用法示例。


在下文中一共展示了AuthState.setCredentials方法的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);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:AsyncHttpClient$3.java

示例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);
        }
    }
    
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:21,代碼來源:HttpSender.java

示例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);
    }
}
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:24,代碼來源:PreemptiveBasicAuthHttpRequestInterceptor.java

示例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);
        }
    }
}
 
開發者ID:diadoc,項目名稱:diadocsdk-java,代碼行數:17,代碼來源:DiadocPreemptiveAuthRequestInterceptor.java

示例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);
        }
    }
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:22,代碼來源:HttpApiWithBasicAuth.java

示例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);
        }
    }
}
 
開發者ID:Kamshak,項目名稱:foursquared,代碼行數:20,代碼來源:SpecialWebViewActivity.java

示例7: 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 );
        }
    }
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:25,代碼來源:WebRealmServiceTest.java

示例8: 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 (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);
		}
	}
}
 
開發者ID:tommy4711,項目名稱:gaeproxy,代碼行數:20,代碼來源:WeaveTransport.java

示例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);

    // 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);
            }
        }
    }
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:20,代碼來源:BrowserMobHttpClient.java

示例10: 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);
        }
    }
}
 
開發者ID:elphinkuo,項目名稱:lightDroid,代碼行數:26,代碼來源:HttpApiWithBasicAuth.java

示例11: makeAuthenticationPreemptive

import org.apache.http.auth.AuthState; //導入方法依賴的package包/類
/**
 * 
 * This function adds support for pre-emptive HTTP Authentication for an HttpClient.
 * 
 * @param httpClient
 */
public static void makeAuthenticationPreemptive(HttpClient httpClient) {
	HttpRequestInterceptor preemptiveAuth = new HttpRequestInterceptor() {
		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);
				}
			}
		}
	};

	((AbstractHttpClient) httpClient).addRequestInterceptor(preemptiveAuth,0);
}
 
開發者ID:GSMADeveloper,項目名稱:MobileConnectSDKTestApp,代碼行數:30,代碼來源:HttpUtils.java

示例12: process

import org.apache.http.auth.AuthState; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
    // Get the AuthState
    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) {
                throw new HttpException("No credentials for preemptive authentication");
            }
            authState.setAuthScheme(authScheme);
            authState.setCredentials(creds);
        }
    }

}
 
開發者ID:umbrew,項目名稱:stash-pullrequest-jenkins,代碼行數:24,代碼來源:JenkinsJobTrigger.java

示例13: process

import org.apache.http.auth.AuthState; //導入方法依賴的package包/類
public void process(final HttpRequest request, final HttpContext context) {
    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);
        }
    }
}
 
開發者ID:guptavishal,項目名稱:jets3t-aws-roles,代碼行數:21,代碼來源:RestUtils.java

示例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(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) {
                        throw new HttpException("No credentials for preemptive authentication");
                    }
                    authState.setAuthScheme(authScheme);
                    authState.setCredentials(creds);
                }
            }
        }
 
開發者ID:jniesen,項目名稱:build-flow-http-extension,代碼行數:22,代碼來源:PreemptiveHttpClient.java

示例15: 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);
	if (authState.getAuthScheme() == null) {
		AuthScheme preemptiveAuthScheme = (AuthScheme) context.getAttribute(PREEMPTIVE_AUTH);
		if (preemptiveAuthScheme != null) {
			CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
			Credentials creds = credsProvider.getCredentials(authScope);
			if (creds == null) {
				throw new HttpException("No credentials for preemptive authentication");
			}
			authState.setAuthScheme(preemptiveAuthScheme);
			authState.setCredentials(creds);
			if(log.isTraceEnabled()) {
				log.trace("successfully set credentials " + creds + " and authScheme " + preemptiveAuthScheme + " for request " + request);
			}
		} else {
			log.warn(PREEMPTIVE_AUTH + " authScheme not found in context; make sure you are using the CustomHttpComponentsMessageSender and the preemptiveAuthEnabled property is set to true");
		}
	} else {
		log.warn("context's authState attribute (" + authState + ") has non-null AuthScheme for request " + request);
	}
}
 
開發者ID:Bedework,項目名稱:exchange-ws-client,代碼行數:25,代碼來源:PreemptiveAuthInterceptor.java


注:本文中的org.apache.http.auth.AuthState.setCredentials方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。