本文整理匯總了Java中ch.boye.httpclientandroidlib.auth.UsernamePasswordCredentials類的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordCredentials類的具體用法?Java UsernamePasswordCredentials怎麽用?Java UsernamePasswordCredentials使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UsernamePasswordCredentials類屬於ch.boye.httpclientandroidlib.auth包,在下文中一共展示了UsernamePasswordCredentials類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setCredentials
import ch.boye.httpclientandroidlib.auth.UsernamePasswordCredentials; //導入依賴的package包/類
/**
* @param username
* Use in authentication header credentials
* @param password
* Use in authentication header credentials
* @param domain
* NTLM authentication
* @param workstation
* NTLM authentication
*/
public void setCredentials(String username, String password, String domain,
String workstation) {
if (username != null) {
this.client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthPolicy.NTLM),
new NTCredentials(username, password, workstation, domain));
this.client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthPolicy.BASIC),
new UsernamePasswordCredentials(username, password));
this.client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
AuthScope.ANY_REALM, AuthPolicy.DIGEST),
new UsernamePasswordCredentials(username, password));
}
}
示例2: getCredentials
import ch.boye.httpclientandroidlib.auth.UsernamePasswordCredentials; //導入依賴的package包/類
public Credentials getCredentials(final AuthScope authscope) {
Args.notNull(authscope, "Auth scope");
final Credentials localcreds = internal.getCredentials(authscope);
if (localcreds != null) {
return localcreds;
}
if (authscope.getHost() != null) {
PasswordAuthentication systemcreds = getSystemCreds(
authscope, Authenticator.RequestorType.SERVER);
if (systemcreds == null) {
systemcreds = getSystemCreds(
authscope, Authenticator.RequestorType.PROXY);
}
if (systemcreds != null) {
final String domain = System.getProperty("http.auth.ntlm.domain");
if (domain != null) {
return new NTCredentials(
systemcreds.getUserName(),
new String(systemcreds.getPassword()),
null, domain);
} else {
if (AuthSchemes.NTLM.equalsIgnoreCase(authscope.getScheme())) {
// Domian may be specified in a fully qualified user name
return new NTCredentials(
systemcreds.getUserName(),
new String(systemcreds.getPassword()),
null, null);
} else {
return new UsernamePasswordCredentials(
systemcreds.getUserName(),
new String(systemcreds.getPassword()));
}
}
}
}
return null;
}
示例3: getAuthHeader
import ch.boye.httpclientandroidlib.auth.UsernamePasswordCredentials; //導入依賴的package包/類
/**
* Return a Header object representing an Authentication header for HTTP
* Basic.
*/
@Override
public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) {
Credentials creds = new UsernamePasswordCredentials(credentials);
// This must be UTF-8 to generate the same Basic Auth headers as desktop for non-ASCII passwords.
return BasicScheme.authenticate(creds, "UTF-8", false);
}