本文整理汇总了Java中org.apache.http.auth.NTCredentials类的典型用法代码示例。如果您正苦于以下问题:Java NTCredentials类的具体用法?Java NTCredentials怎么用?Java NTCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NTCredentials类属于org.apache.http.auth包,在下文中一共展示了NTCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.http.auth.NTCredentials; //导入依赖的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: createHTTPClient
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
private static AbstractHttpClient createHTTPClient() {
AbstractHttpClient client = new DefaultHttpClient();
String proxyHost = System.getProperty("https.proxyHost", "");
if (!proxyHost.isEmpty()) {
int proxyPort = Integer.parseInt(System.getProperty("https.proxyPort", "-1"));
log.info("Using proxy " + proxyHost + ":" + proxyPort);
HttpParams params = client.getParams();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
String proxyUser = System.getProperty(JMeter.HTTP_PROXY_USER, JMeterUtils.getProperty(JMeter.HTTP_PROXY_USER));
if (proxyUser != null) {
log.info("Using authenticated proxy with username: " + proxyUser);
String proxyPass = System.getProperty(JMeter.HTTP_PROXY_PASS, JMeterUtils.getProperty(JMeter.HTTP_PROXY_PASS));
String localHost;
try {
localHost = InetAddress.getLocalHost().getCanonicalHostName();
} catch (Throwable e) {
log.error("Failed to get local host name, defaulting to 'localhost'", e);
localHost = "localhost";
}
AuthScope authscope = new AuthScope(proxyHost, proxyPort);
String proxyDomain = JMeterUtils.getPropDefault("http.proxyDomain", "");
NTCredentials credentials = new NTCredentials(proxyUser, proxyPass, localHost, proxyDomain);
client.getCredentialsProvider().setCredentials(authscope, credentials);
}
}
return client;
}
示例3: getProxyExecutor
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
public static HttpCommandExecutor getProxyExecutor(URL url, Properties prop) {
prop = decrypt(prop);
String proxyHost = prop.getProperty("proxyHost");
int proxyPort = Integer.valueOf(prop.getProperty("proxyPort"));
String proxyUserDomain = prop.getProperty("proxyUserDomain");
String proxyUser = prop.getProperty("proxyUser");
String proxyPassword = prop.getProperty("proxyPassword");
HttpClientBuilder builder = HttpClientBuilder.create();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
new NTCredentials(proxyUser, proxyPassword, getWorkstation(), proxyUserDomain));
if (url.getUserInfo() != null && !url.getUserInfo().isEmpty()) {
credsProvider.setCredentials(new AuthScope(url.getHost(), (url.getPort() > 0 ? url.getPort() : url.getDefaultPort())),
new UsernamePasswordCredentials(proxyUser, proxyPassword));
}
builder.setProxy(proxy);
builder.setDefaultCredentialsProvider(credsProvider);
HttpClient.Factory factory = new SimpleHttpClientFactory(builder);
return new HttpCommandExecutor(new HashMap<String, CommandInfo>(), url, factory);
}
示例4: createNtlmProxyClient
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
public static HttpClient createNtlmProxyClient() {
final String proxyHost = Configuration.getProperty("http.proxyHost");
final String proxyPort = Configuration.getProperty("http.proxyPort");
final String proxyUser = Configuration.getProperty("http.proxyUser");
final String proxyPassword = Configuration.getProperty("http.proxyPassword");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(proxyHost, Integer.parseInt(proxyPort)),
new NTCredentials(proxyUser + ":" + proxyPassword));
HttpHost proxy = new HttpHost(proxyHost, Integer.parseInt(proxyPort));
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
return client;
}
示例5: setupCredentials
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
/**
* Configure credentials and auth scheme on client if an authorization is
* available for url
* @param client {@link HttpClient}
* @param url URL to test
* @param credentialsProvider {@link CredentialsProvider}
* @param localHost host running JMeter
*/
public void setupCredentials(HttpClient client, URL url,
CredentialsProvider credentialsProvider, String localHost) {
Authorization auth = getAuthForURL(url);
if (auth != null) {
String username = auth.getUser();
String realm = auth.getRealm();
String domain = auth.getDomain();
if (log.isDebugEnabled()){
log.debug(username + " > D="+domain+" R="+realm + " M="+auth.getMechanism());
}
if (Mechanism.KERBEROS.equals(auth.getMechanism())) {
((AbstractHttpClient) client).getAuthSchemes().register(
AuthSchemes.SPNEGO,
new FixedSPNegoSchemeFactory(isStripPort(url)));
credentialsProvider.setCredentials(new AuthScope(null, -1, null), USE_JAAS_CREDENTIALS);
} else {
credentialsProvider.setCredentials(
new AuthScope(url.getHost(), url.getPort(), realm.length()==0 ? null : realm),
new NTCredentials(username, auth.getPass(), localHost, domain));
}
}
}
示例6: testNTLMAuthenticationFailure
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testNTLMAuthenticationFailure() throws Exception {
this.serverBootstrap.registerHandler("*", new NtlmResponseHandler());
final HttpHost target = start();
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("test", "test", null, null));
this.httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
final HttpContext context = HttpClientContext.create();
final HttpGet httpget = new HttpGet("/");
final HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
response.getStatusLine().getStatusCode());
}
示例7: testNTLMv1Type2Message
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testNTLMv1Type2Message() throws Exception {
this.serverBootstrap.registerHandler("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
"AADAAMADgAAAAzggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
"AGUAcgB2AGUAcgA="));
final HttpHost target = start();
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("test", "test", null, null));
this.httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
final HttpContext context = HttpClientContext.create();
final HttpGet httpget = new HttpGet("/");
final HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
response.getStatusLine().getStatusCode());
}
示例8: testNTLMv2Type2Message
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testNTLMv2Type2Message() throws Exception {
this.serverBootstrap.registerHandler("*", new NtlmType2MessageResponseHandler("TlRMTVNTUAACAA" +
"AADAAMADgAAAAzgoriASNFZ4mrze8AAAAAAAAAACQAJABEAAAABgBwFwAAAA9T" +
"AGUAcgB2AGUAcgACAAwARABvAG0AYQBpAG4AAQAMAFMAZQByAHYAZQByAAAAAAA="));
final HttpHost target = start();
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("test", "test", null, null));
this.httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
final HttpContext context = HttpClientContext.create();
final HttpGet httpget = new HttpGet("/");
final HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
response.getStatusLine().getStatusCode());
}
示例9: testNTLMType2MessageOnlyAuthenticationFailure
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testNTLMType2MessageOnlyAuthenticationFailure() throws Exception {
this.serverBootstrap.registerHandler("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
"AADAAMADgAAAAzggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
"AGUAcgB2AGUAcgA="));
final HttpHost target = start();
final HttpClientContext context = HttpClientContext.create();
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("test", "test", null, null));
context.setCredentialsProvider(credsProvider);
final HttpGet httpget = new HttpGet("/");
final HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
response.getStatusLine().getStatusCode());
}
示例10: testNTLMType2NonUnicodeMessageOnlyAuthenticationFailure
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testNTLMType2NonUnicodeMessageOnlyAuthenticationFailure() throws Exception {
this.serverBootstrap.registerHandler("*", new NtlmType2MessageOnlyResponseHandler("TlRMTVNTUAACAA" +
"AABgAGADgAAAAyggLiASNFZ4mrze8AAAAAAAAAAAAAAAAAAAAABgBwFwAAAA9T" +
"ZXJ2ZXI="));
final HttpHost target = start();
final HttpClientContext context = HttpClientContext.create();
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("test", "test", null, null));
context.setCredentialsProvider(credsProvider);
final HttpGet httpget = new HttpGet("/");
final HttpResponse response = this.httpclient.execute(target, httpget, context);
EntityUtils.consume(response.getEntity());
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED,
response.getStatusLine().getStatusCode());
}
示例11: testProxyCredentials
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void testProxyCredentials() throws Exception {
HttpClient wdmClient = new HttpClient.Builder().proxy("myproxy:8081")
.proxyUser("domain\\me").proxyPass("pass").build();
Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
field.setAccessible(true);
CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
field = client.getClass().getDeclaredField("credentialsProvider");
field.setAccessible(true);
BasicCredentialsProvider provider = (BasicCredentialsProvider) field
.get(client);
NTCredentials ntcreds = (NTCredentials) provider.getCredentials(
new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM));
assertThat(ntcreds.getDomain(), equalTo("DOMAIN"));
assertThat(ntcreds.getUserName(), equalTo("me"));
assertThat(ntcreds.getPassword(), equalTo("pass"));
UsernamePasswordCredentials creds = (UsernamePasswordCredentials) provider
.getCredentials(new AuthScope(ANY_HOST, ANY_PORT));
assertThat(creds.getUserName(), equalTo("domain\\me"));
assertThat(creds.getPassword(), equalTo("pass"));
}
示例12: getCredentials
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
@Test
public void getCredentials() {
// Basic TFS
final AuthenticationInfo info = new AuthenticationInfo("name1", "pass1", "server1", "display1");
final Credentials credentials = AuthHelper.getCredentials(ServerContext.Type.TFS, info);
Assert.assertTrue(credentials instanceof NTCredentials);
Assert.assertEquals("name1", credentials.getUserPrincipal().getName());
Assert.assertEquals("pass1", credentials.getPassword());
// Basic VSO
final AuthenticationInfo info2 = new AuthenticationInfo("name2", "pass2", "server2", "display2");
final Credentials credentials2 = AuthHelper.getCredentials(ServerContext.Type.VSO, info2);
Assert.assertTrue(credentials2 instanceof UsernamePasswordCredentials);
Assert.assertEquals("name2", credentials2.getUserPrincipal().getName());
Assert.assertEquals("pass2", credentials2.getPassword());
// domain parsing
createAndVerifyNTCredentials("domain", "name", "domain/name", "pass");
createAndVerifyNTCredentials("domain", "name", "domain\\name", "pass");
createAndVerifyNTCredentials("domain", "name", "[email protected]", "pass");
}
示例13: getHttpClient
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
protected final CloseableHttpClient getHttpClient(final boolean useSpnego) throws Exception {
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
final HttpClientBuilder hcb = HttpClients.custom();
if (useSpnego) {
//SPNEGO/Kerberos setup
log.debug("SPNEGO activated");
final AuthSchemeProvider nsf = new SPNegoSchemeFactory(true);// new NegotiateSchemeProvider();
final Credentials jaasCreds = new JaasCredentials();
credsProvider.setCredentials(new AuthScope(null, -1, null, AuthSchemes.SPNEGO), jaasCreds);
credsProvider.setCredentials(new AuthScope(null, -1, null, AuthSchemes.NTLM), new NTCredentials("Guest", "Guest", "Guest",
"Guest"));
final Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider> create()
.register(AuthSchemes.SPNEGO, nsf).register(AuthSchemes.NTLM, new NTLMSchemeFactory()).build();
hcb.setDefaultAuthSchemeRegistry(authSchemeRegistry);
}
hcb.setDefaultCredentialsProvider(credsProvider);
hcb.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(10 * 1000).build());
final CloseableHttpClient httpClient = hcb.build();
return httpClient;
}
示例14: getClient
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
/**
* Sharepoint requires NTLM. This client requires a non-null user/passwd/domain.
*
*/
@Override
public HttpClient getClient() {
if (currentConn!=null){
return currentConn;
}
HttpClientBuilder clientHelper = HttpClientBuilder.create();
if (proxyHost != null) {
clientHelper.setProxy(proxyHost);
}
RequestConfig globalConfig = RequestConfig.custom()
.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, server, domain));
clientHelper.setDefaultCredentialsProvider(creds);
HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build();
return httpClient;
}
示例15: configure
import org.apache.http.auth.NTCredentials; //导入依赖的package包/类
public void configure() throws ConfigurationException {
super.configure();
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, getTimeout());
HttpConnectionParams.setSoTimeout(httpParameters, getTimeout());
httpClient = new DefaultHttpClient(connectionManager, httpParameters);
httpClient.getAuthSchemes().register("NTLM", new NTLMSchemeFactory());
CredentialFactory cf = new CredentialFactory(getAuthAlias(),
getUserName(), getPassword());
httpClient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new NTCredentials(cf.getUsername(), cf.getPassword(), Misc
.getHostname(), getAuthDomain()));
if (StringUtils.isNotEmpty(getProxyHost())) {
HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
}
}