本文整理汇总了Java中org.apache.http.auth.params.AuthPNames类的典型用法代码示例。如果您正苦于以下问题:Java AuthPNames类的具体用法?Java AuthPNames怎么用?Java AuthPNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthPNames类属于org.apache.http.auth.params包,在下文中一共展示了AuthPNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
public static void main(String... args) throws IOException {
DefaultHttpClient httpclient = new DefaultHttpClient();
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.NTLM);
httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
NTCredentials creds = new NTCredentials("abhisheks", "abhiProJul17", "", "");
httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpHost target = new HttpHost("apps.prorigo.com", 80, "http");
// Make sure the same context is used to execute logically related requests
HttpContext localContext = new BasicHttpContext();
// Execute a cheap method first. This will trigger NTLM authentication
HttpGet httpget = new HttpGet("/conference/Booking");
HttpResponse response = httpclient.execute(target, httpget, localContext);
HttpEntity entity = response.getEntity();
System.out.println(EntityUtils.toString(entity));
}
示例2: _createTwilioRESTClient
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@SuppressWarnings({ "resource"})
private TwilioRestClient _createTwilioRESTClient() {
TwilioRestClient outClient = new TwilioRestClient(_apiData.getAccountSID().asString(),
_apiData.getAccountToken().asString());
if (_proxySettings != null && _proxySettings.isEnabled()) {
UrlComponents proxyUrlComps = _proxySettings.getProxyUrl().getComponents();
log.info("Connecting to twilio through {}:{}",proxyUrlComps.getHost(),
proxyUrlComps.getPort());
// Get the twilio api underlying http client
DefaultHttpClient httpClient = (DefaultHttpClient)outClient.getHttpClient();
// Set proxy details
HttpHost proxy = new HttpHost(proxyUrlComps.getHost().asString(),proxyUrlComps.getPort(),
"http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyUrlComps.getHost().asString(),
proxyUrlComps.getPort()),
new UsernamePasswordCredentials(_proxySettings.getUserCode().asString(),
_proxySettings.getPassword().asString()));
httpClient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF,
Lists.newArrayList(AuthPolicy.BASIC));
}
return outClient;
}
示例3: enableAuth
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
public static void enableAuth(final AbstractHttpClient client, final Keychain keychain, final KeyId keyId) {
if (client == null) {
throw new NullPointerException("client");
}
if (keychain == null) {
throw new NullPointerException("keychain");
}
client.getAuthSchemes().register(Constants.SCHEME, new AuthSchemeFactory() {
public AuthScheme newInstance(HttpParams params) {
return new Http4SignatureAuthScheme();
}
});
Signer signer = new Signer(keychain, keyId);
client.getCredentialsProvider().setCredentials(AuthScope.ANY, new SignerCredentials(signer));
client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF,
Arrays.asList(Constants.SCHEME));
HttpClientParams.setAuthenticating(client.getParams(), true);
}
示例4: getAuthPreferences
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@Override
protected List<String> getAuthPreferences(
final HttpResponse response,
final HttpContext context) {
@SuppressWarnings("unchecked")
List<String> authpref = (List<String>) response.getParams().getParameter(
AuthPNames.TARGET_AUTH_PREF);
if (authpref != null) {
return authpref;
} else {
return super.getAuthPreferences(response, context);
}
}
示例5: getAuthPreferences
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@Override
protected List<String> getAuthPreferences(
final HttpResponse response,
final HttpContext context) {
@SuppressWarnings("unchecked")
List<String> authpref = (List<String>) response.getParams().getParameter(
AuthPNames.PROXY_AUTH_PREF);
if (authpref != null) {
return authpref;
} else {
return super.getAuthPreferences(response, context);
}
}
示例6: getCredentialsCharset
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
String getCredentialsCharset(final HttpRequest request) {
String charset = (String) request.getParams().getParameter(AuthPNames.CREDENTIAL_CHARSET);
if (charset == null) {
charset = getCredentialsCharset().name();
}
return charset;
}
示例7: getAuthPreferences
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@Override
protected List<String> getAuthPreferences(
final HttpResponse response,
final HttpContext context) {
@SuppressWarnings("unchecked")
final
List<String> authpref = (List<String>) response.getParams().getParameter(
AuthPNames.TARGET_AUTH_PREF);
if (authpref != null) {
return authpref;
} else {
return super.getAuthPreferences(response, context);
}
}
示例8: getAuthPreferences
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@Override
protected List<String> getAuthPreferences(
final HttpResponse response,
final HttpContext context) {
@SuppressWarnings("unchecked")
final
List<String> authpref = (List<String>) response.getParams().getParameter(
AuthPNames.PROXY_AUTH_PREF);
if (authpref != null) {
return authpref;
} else {
return super.getAuthPreferences(response, context);
}
}
示例9: getRequestConfig
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static RequestConfig getRequestConfig(final HttpParams params) {
return RequestConfig.custom()
.setSocketTimeout(params.getIntParameter(
CoreConnectionPNames.SO_TIMEOUT, 0))
.setStaleConnectionCheckEnabled(params.getBooleanParameter(
CoreConnectionPNames.STALE_CONNECTION_CHECK, true))
.setConnectTimeout(params.getIntParameter(
CoreConnectionPNames.CONNECTION_TIMEOUT, 0))
.setExpectContinueEnabled(params.getBooleanParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE, false))
.setProxy((HttpHost) params.getParameter(
ConnRoutePNames.DEFAULT_PROXY))
.setLocalAddress((InetAddress) params.getParameter(
ConnRoutePNames.LOCAL_ADDRESS))
.setProxyPreferredAuthSchemes((Collection<String>) params.getParameter(
AuthPNames.PROXY_AUTH_PREF))
.setTargetPreferredAuthSchemes((Collection<String>) params.getParameter(
AuthPNames.TARGET_AUTH_PREF))
.setAuthenticationEnabled(params.getBooleanParameter(
ClientPNames.HANDLE_AUTHENTICATION, true))
.setCircularRedirectsAllowed(params.getBooleanParameter(
ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false))
.setConnectionRequestTimeout((int) params.getLongParameter(
ClientPNames.CONN_MANAGER_TIMEOUT, 0))
.setCookieSpec((String) params.getParameter(
ClientPNames.COOKIE_POLICY))
.setMaxRedirects(params.getIntParameter(
ClientPNames.MAX_REDIRECTS, 50))
.setRedirectsEnabled(params.getBooleanParameter(
ClientPNames.HANDLE_REDIRECTS, true))
.setRelativeRedirectsAllowed(!params.getBooleanParameter(
ClientPNames.REJECT_RELATIVE_REDIRECT, false))
.build();
}
示例10: HttpClientForProxy
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
/**
* 認証プロキシを通過するためのHttpClient。
*/
public HttpClientForProxy() {
super();
String proxyUser = System.getProperty("http.proxyUser");
if (proxyUser != null) {
String proxyHost = System.getProperty("http.proxyHost");
String proxyPortStr = System.getProperty("http.proxyPort");
int proxyPort = 0;
if (proxyPortStr != null) {
proxyPort = Integer.parseInt(proxyPortStr);
}
String proxyPassword = System.getProperty("http.proxyPassword");
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.BASIC);
this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
CredentialsProvider credsProvider = this.getCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(
proxyUser, proxyPassword));
this.setCredentialsProvider(credsProvider);
String protocol = "";
if (proxyHost.indexOf("https") != 0) {
protocol = "http";
} else {
protocol = "https";
}
HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol);
this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}
示例11: appendAuthentication
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
private void appendAuthentication(Credentials credentials, String authPolicy, SolrClient solrClient) {
if (isHttpSolrClient(solrClient)) {
HttpSolrClient httpSolrClient = (HttpSolrClient) solrClient;
if (credentials != null && StringUtils.isNotBlank(authPolicy)
&& assertHttpClientInstance(httpSolrClient.getHttpClient())) {
AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrClient.getHttpClient();
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials);
httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy));
}
}
}
示例12: HttpClientForProxy
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
/**
* 認証プロキシを通過するためのHttpClient。
*/
public HttpClientForProxy() {
super();
String proxyHost = System.getProperty("http.proxyHost");
if (proxyHost != null) {
String proxyPortStr = System.getProperty("http.proxyPort");
int proxyPort = 0;
if (proxyPortStr != null) {
proxyPort = Integer.parseInt(proxyPortStr);
}
String proxyUser = System.getProperty("http.proxyUser");
if (proxyUser != null) {
String proxyPassword = System.getProperty("http.proxyPassword");
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.BASIC);
this.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
CredentialsProvider credsProvider = this.getCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(
proxyUser, proxyPassword));
this.setCredentialsProvider(credsProvider);
}
String protocol = "";
if (proxyHost.indexOf("https") != 0) {
protocol = "http";
} else {
protocol = "https";
}
HttpHost proxy = new HttpHost(proxyHost, proxyPort, protocol);
this.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
}
}
示例13: appendAuthentication
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
private void appendAuthentication(Credentials credentials, String authPolicy, SolrServer solrServer) {
if (isHttpSolrServer(solrServer)) {
HttpSolrServer httpSolrServer = (HttpSolrServer) solrServer;
if (credentials != null && StringUtils.isNotBlank(authPolicy)
&& assertHttpClientInstance(httpSolrServer.getHttpClient())) {
AbstractHttpClient httpClient = (AbstractHttpClient) httpSolrServer.getHttpClient();
httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY), credentials);
httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(authPolicy));
}
}
}
示例14: testInitFactoryWithAuthentication
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
@Test
public void testInitFactoryWithAuthentication() {
HttpSolrServerFactory factory = new HttpSolrServerFactory(solrServer, "core", new UsernamePasswordCredentials(
"username", "password"), "BASIC");
AbstractHttpClient solrHttpClient = (AbstractHttpClient) ((HttpSolrServer) factory.getSolrServer()).getHttpClient();
Assert.assertNotNull(solrHttpClient.getCredentialsProvider().getCredentials(AuthScope.ANY));
Assert.assertNotNull(solrHttpClient.getParams().getParameter(AuthPNames.TARGET_AUTH_PREF));
Assert.assertEquals("username", ((UsernamePasswordCredentials) solrHttpClient.getCredentialsProvider()
.getCredentials(AuthScope.ANY)).getUserName());
Assert.assertEquals("password", ((UsernamePasswordCredentials) solrHttpClient.getCredentialsProvider()
.getCredentials(AuthScope.ANY)).getPassword());
}
示例15: ProxyAuthenticationStrategy
import org.apache.http.auth.params.AuthPNames; //导入依赖的package包/类
public ProxyAuthenticationStrategy() {
super(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, AUTH.PROXY_AUTH, AuthPNames.PROXY_AUTH_PREF);
}