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


Java AuthState.setAuthScheme方法代碼示例

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


在下文中一共展示了AuthState.setAuthScheme方法的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: processChallenges

import org.apache.http.auth.AuthState; //導入方法依賴的package包/類
private void processChallenges(
    final Map<String, Header> challenges,
    final AuthState authState,
    final AuthenticationHandler authHandler,
    final HttpResponse response,
    final HttpContext context)
      throws MalformedChallengeException, AuthenticationException {

  AuthScheme authScheme = authState.getAuthScheme();
  if (authScheme == null) {
    // Authentication not attempted before
    authScheme = authHandler.selectScheme(challenges, response, context);
    authState.setAuthScheme(authScheme);
  }
  String id = authScheme.getSchemeName();

  Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
  if (challenge == null) {
    throw new AuthenticationException(id +
      " authorization challenge expected, but not found");
  }
  authScheme.processChallenge(challenge);
  this.log.debug("Authorization challenge processed");
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:25,代碼來源:DefaultRequestDirector.java

示例11: 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

示例12: processChallenges

import org.apache.http.auth.AuthState; //導入方法依賴的package包/類
private void processChallenges(
        final Map<String, Header> challenges, 
        final AuthState authState,
        final AuthenticationHandler authHandler,
        final HttpResponse response, 
        final HttpContext context) 
            throws MalformedChallengeException, AuthenticationException {
    
    AuthScheme authScheme = authState.getAuthScheme();
    if (authScheme == null) {
        // Authentication not attempted before
        authScheme = authHandler.selectScheme(challenges, response, context);
        authState.setAuthScheme(authScheme);
    }
    String id = authScheme.getSchemeName();

    Header challenge = challenges.get(id.toLowerCase(Locale.ENGLISH));
    if (challenge == null) {
        throw new AuthenticationException(id + 
            " authorization challenge expected, but not found");
    }
    authScheme.processChallenge(challenge);
    this.log.debug("Authorization challenge processed");
}
 
開發者ID:tdopires,項目名稱:cJUnit-mc626,代碼行數:25,代碼來源:DefaultRequestDirector.java

示例13: 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

示例14: 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

示例15: 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


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