本文整理汇总了Java中org.apache.http.client.params.AuthPolicy类的典型用法代码示例。如果您正苦于以下问题:Java AuthPolicy类的具体用法?Java AuthPolicy怎么用?Java AuthPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthPolicy类属于org.apache.http.client.params包,在下文中一共展示了AuthPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.client.params.AuthPolicy; //导入依赖的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: ProxyClient
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
public ProxyClient(final HttpParams params) {
super();
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestClientConnControl(),
new RequestUserAgent(),
new RequestProxyAuthentication()
} );
this.requestExec = new HttpRequestExecutor();
this.proxyAuthStrategy = new ProxyAuthenticationStrategy();
this.authenticator = new HttpAuthenticator();
this.proxyAuthState = new AuthState();
this.authSchemeRegistry = new AuthSchemeRegistry();
this.authSchemeRegistry.register(AuthPolicy.BASIC, new BasicSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.DIGEST, new DigestSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.NTLM, new NTLMSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory());
this.authSchemeRegistry.register(AuthPolicy.KERBEROS, new KerberosSchemeFactory());
this.reuseStrategy = new DefaultConnectionReuseStrategy();
this.params = params;
}
示例3: createAuthSchemeRegistry
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
protected AuthSchemeRegistry createAuthSchemeRegistry() {
AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(
AuthPolicy.BASIC,
new BasicSchemeFactory());
registry.register(
AuthPolicy.DIGEST,
new DigestSchemeFactory());
registry.register(
AuthPolicy.NTLM,
new NTLMSchemeFactory());
registry.register(
AuthPolicy.SPNEGO,
new SPNegoSchemeFactory());
registry.register(
AuthPolicy.KERBEROS,
new KerberosSchemeFactory());
return registry;
}
示例4: getHttpClient
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private SystemDefaultHttpClient getHttpClient() {
final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
Credentials use_jaas_creds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
httpClient.getCredentialsProvider().setCredentials(
AuthScope.ANY, use_jaas_creds);
return httpClient;
}
示例5: getHttpClient
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private SystemDefaultHttpClient getHttpClient() {
final SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
httpClient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory(true));
Credentials use_jaas_creds = new Credentials() {
public String getPassword() {
return null;
}
public Principal getUserPrincipal() {
return null;
}
};
httpClient.getCredentialsProvider().setCredentials(
AuthScope.ANY, use_jaas_creds);
return httpClient;
}
示例6: createAuthSchemeRegistry
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
protected AuthSchemeRegistry createAuthSchemeRegistry() {
final AuthSchemeRegistry registry = new AuthSchemeRegistry();
registry.register(
AuthPolicy.BASIC,
new BasicSchemeFactory());
registry.register(
AuthPolicy.DIGEST,
new DigestSchemeFactory());
registry.register(
AuthPolicy.NTLM,
new NTLMSchemeFactory());
registry.register(
AuthPolicy.SPNEGO,
new SPNegoSchemeFactory());
registry.register(
AuthPolicy.KERBEROS,
new KerberosSchemeFactory());
return registry;
}
示例7: _createTwilioRESTClient
import org.apache.http.client.params.AuthPolicy; //导入依赖的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;
}
示例8: setUp
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
if (getDataService() == null || getDataServiceForFilteredEntity() == null) {
clearEntities();
prepareEntity();
prepareFilteredEntity();
SchemaHolder schemaHolder = entityService.getSchema();
jarGeneratorService.regenerateMdsDataBundle(schemaHolder);
}
getDataService().deleteAll();
getDataServiceForFilteredEntity().deleteAll();
if (!userService.hasActiveMotechAdmin()) {
userService.registerMotechAdmin("motech", "motech", "[email protected]", Locale.ENGLISH);
}
getHttpClient().getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthPolicy.BASIC),
new UsernamePasswordCredentials("motech", "motech")
);
}
示例9: isCachable
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private boolean isCachable(final AuthState authState) {
AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例10: isCachable
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private boolean isCachable(final AuthScheme authScheme) {
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例11: isCachable
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
protected boolean isCachable(final AuthScheme authScheme) {
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例12: isCachable
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private boolean isCachable(final AuthState authState) {
final AuthScheme authScheme = authState.getAuthScheme();
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
final String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例13: isCachable
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private boolean isCachable(final AuthScheme authScheme) {
if (authScheme == null || !authScheme.isComplete()) {
return false;
}
final String schemeName = authScheme.getSchemeName();
return schemeName.equalsIgnoreCase(AuthPolicy.BASIC) ||
schemeName.equalsIgnoreCase(AuthPolicy.DIGEST);
}
示例14: HttpClientForProxy
import org.apache.http.client.params.AuthPolicy; //导入依赖的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);
}
}
示例15: useCredentials
import org.apache.http.client.params.AuthPolicy; //导入依赖的package包/类
private void useCredentials(DefaultHttpClient httpClient, PasswordCredentials credentials, String host, int port) {
Credentials basicCredentials = new UsernamePasswordCredentials(credentials.getUsername(), credentials.getPassword());
httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port), basicCredentials);
NTLMCredentials ntlmCredentials = new NTLMCredentials(credentials);
Credentials ntCredentials = new NTCredentials(ntlmCredentials.getUsername(), ntlmCredentials.getPassword(), ntlmCredentials.getWorkstation(), ntlmCredentials.getDomain());
httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM), ntCredentials);
LOGGER.debug("Using {} and {} for authenticating against '{}:{}'", new Object[]{credentials, ntlmCredentials, host, port});
}