本文整理匯總了Java中org.apache.http.client.CredentialsProvider.getCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java CredentialsProvider.getCredentials方法的具體用法?Java CredentialsProvider.getCredentials怎麽用?Java CredentialsProvider.getCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.CredentialsProvider
的用法示例。
在下文中一共展示了CredentialsProvider.getCredentials方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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 || authState.hasAuthOptions()) {
return;
}
// If no authState has been established and this is a PUT or POST request, add preemptive authorisation
String requestMethod = request.getRequestLine().getMethod();
if (alwaysSendAuth || requestMethod.equals(HttpPut.METHOD_NAME) || requestMethod.equals(HttpPost.METHOD_NAME)) {
CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
Credentials credentials = credentialsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (credentials == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, credentials);
}
}
示例2: doPreemptiveAuth
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthState authState,
final CredentialsProvider credsProvider) {
String schemeName = authScheme.getSchemeName();
if (this.log.isDebugEnabled()) {
this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
}
AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setState(AuthProtocolState.SUCCESS);
authState.update(authScheme, creds);
} else {
this.log.debug("No credentials for preemptive authentication");
}
}
示例3: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例4: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例5: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例6: doPreemptiveAuth
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthStateHC4 authState,
final CredentialsProvider credsProvider) {
final String schemeName = authScheme.getSchemeName();
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Re-using cached '" + schemeName + "' auth scheme for " + host);
}
final AuthScope authScope = new AuthScope(host.getHostName(), host.getPort(), AuthScope.ANY_REALM, schemeName);
final Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
authState.setState(AuthProtocolState.CHALLENGED);
} else {
authState.setState(AuthProtocolState.SUCCESS);
}
authState.update(authScheme, creds);
} else {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "No credentials for preemptive authentication");
}
}
}
示例7: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例8: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例9: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例10: setConnectionAuthorization
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
/**
* Setup credentials for url AuthScope but keeps Proxy AuthScope credentials
* @param client HttpClient
* @param url URL
* @param authManager {@link AuthManager}
* @param key key
*/
private void setConnectionAuthorization(HttpClient client, URL url, AuthManager authManager, HttpClientKey key) {
CredentialsProvider credentialsProvider =
((AbstractHttpClient) client).getCredentialsProvider();
if (authManager != null) {
if(authManager.hasAuthForURL(url)) {
authManager.setupCredentials(client, url, credentialsProvider, localHost);
} else {
credentialsProvider.clear();
}
} else {
Credentials credentials = null;
AuthScope authScope = null;
if(key.hasProxy && !StringUtils.isEmpty(key.proxyUser)) {
authScope = new AuthScope(key.proxyHost, key.proxyPort);
credentials = credentialsProvider.getCredentials(authScope);
}
credentialsProvider.clear();
if(credentials != null) {
credentialsProvider.setCredentials(authScope, credentials);
}
}
}
示例11: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的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);
}
}
}
示例12: doPreemptiveAuth
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
private void doPreemptiveAuth(
final HttpHost host,
final AuthScheme authScheme,
final AuthState authState,
final CredentialsProvider credsProvider) {
final String schemeName = authScheme.getSchemeName();
if (this.log.isDebugEnabled()) {
this.log.debug("Re-using cached '" + schemeName + "' auth scheme for " + host);
}
final AuthScope authScope = new AuthScope(host, AuthScope.ANY_REALM, schemeName);
final Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
if ("BASIC".equalsIgnoreCase(authScheme.getSchemeName())) {
authState.setState(AuthProtocolState.CHALLENGED);
} else {
authState.setState(AuthProtocolState.SUCCESS);
}
authState.update(authScheme, creds);
} else {
this.log.debug("No credentials for preemptive authentication");
}
}
示例13: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
public void process(final HttpRequest request, final HttpContext context) throws HttpException {
final AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
if (authState.getAuthScheme() == null) {
final CredentialsProvider credsProvider = (CredentialsProvider) context
.getAttribute(HttpClientContext.CREDS_PROVIDER);
final HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
final Credentials creds = credsProvider.getCredentials(new AuthScope(targetHost.getHostName(),
targetHost.getPort()));
if (creds == null) {
throw new HttpException("No creds provided for preemptive auth.");
}
authState.update(new BasicScheme(), creds);
}
}
示例14: setCredentials
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
private void setCredentials() {
AuthState authState = httpClientContext.getTargetAuthState();
if (authState != null) {
CredentialsProvider credentialsProvider = httpClientContext.getCredentialsProvider();
AuthScope authScope = new AuthScope(HttpHost.create(getBaseUrl()));
org.apache.http.auth.Credentials credentials = credentialsProvider.getCredentials(authScope);
if (credentials != null) {
authState.update(new BasicScheme(), credentials);
authState.setState(AuthProtocolState.CHALLENGED);
}
}
}
示例15: process
import org.apache.http.client.CredentialsProvider; //導入方法依賴的package包/類
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:benniaobuguai,項目名稱:android-project-gallery,代碼行數:16,代碼來源:PreemtiveAuthorizationHttpRequestInterceptor.java