List of usage examples for org.apache.http.auth AuthScope ANY_PORT
int ANY_PORT
To view the source code for org.apache.http.auth AuthScope ANY_PORT.
Click Source Link
From source file:org.datacleaner.user.UserPreferencesImplTest.java
public void testCreateHttpClientWithNtCredentials() throws Exception { UserPreferencesImpl up = new UserPreferencesImpl(null); up.setProxyHostname("host"); up.setProxyPort(1234);//from www.jav a 2 s. c om up.setProxyUsername("FOO\\bar"); up.setProxyPassword("baz"); up.setProxyEnabled(true); up.setProxyAuthenticationEnabled(true); CloseableHttpClient httpClient = up.createHttpClient(); String computername = InetAddress.getLocalHost().getHostName(); assertNotNull(computername); assertTrue(computername.length() > 1); AuthScope authScope; Credentials credentials; authScope = new AuthScope("host", 1234, AuthScope.ANY_REALM, "ntlm"); credentials = getCredentialsProvider(httpClient).getCredentials(authScope); assertEquals("[principal: FOO/bar][workstation: " + computername.toUpperCase() + "]", credentials.toString().replaceAll("\\\\", "/")); authScope = new AuthScope("host", 1234); credentials = getCredentialsProvider(httpClient).getCredentials(authScope); assertEquals("[principal: FOO\\bar]", credentials.toString()); authScope = new AuthScope("anotherhost", AuthScope.ANY_PORT); credentials = getCredentialsProvider(httpClient).getCredentials(authScope); assertNull(credentials); }
From source file:org.eobjects.datacleaner.user.UserPreferencesImplTest.java
public void testCreateHttpClientWithoutNtCredentials() throws Exception { UserPreferencesImpl up = new UserPreferencesImpl(null); up.setProxyHostname("host"); up.setProxyPort(1234);/*from ww w. j a va2s . c o m*/ up.setProxyUsername("bar"); up.setProxyPassword("baz"); up.setProxyEnabled(true); up.setProxyAuthenticationEnabled(true); DefaultHttpClient httpClient = (DefaultHttpClient) up.createHttpClient(); String computername = InetAddress.getLocalHost().getHostName(); assertNotNull(computername); assertTrue(computername.length() > 1); AuthScope authScope; Credentials credentials; authScope = new AuthScope("host", 1234, AuthScope.ANY_REALM, "ntlm"); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertEquals("[principal: bar][workstation: " + computername.toUpperCase() + "]", credentials.toString()); authScope = new AuthScope("host", 1234); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertEquals("[principal: bar]", credentials.toString()); authScope = new AuthScope("anotherhost", AuthScope.ANY_PORT); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertNull(credentials); }
From source file:org.eobjects.datacleaner.user.UserPreferencesImplTest.java
public void testCreateHttpClientWithNtCredentials() throws Exception { UserPreferencesImpl up = new UserPreferencesImpl(null); up.setProxyHostname("host"); up.setProxyPort(1234);//from ww w .ja v a 2 s. co m up.setProxyUsername("FOO\\bar"); up.setProxyPassword("baz"); up.setProxyEnabled(true); up.setProxyAuthenticationEnabled(true); DefaultHttpClient httpClient = (DefaultHttpClient) up.createHttpClient(); String computername = InetAddress.getLocalHost().getHostName(); assertNotNull(computername); assertTrue(computername.length() > 1); AuthScope authScope; Credentials credentials; authScope = new AuthScope("host", 1234, AuthScope.ANY_REALM, "ntlm"); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertEquals("[principal: FOO/bar][workstation: " + computername.toUpperCase() + "]", credentials.toString()); authScope = new AuthScope("host", 1234); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertEquals("[principal: FOO\\bar]", credentials.toString()); authScope = new AuthScope("anotherhost", AuthScope.ANY_PORT); credentials = httpClient.getCredentialsProvider().getCredentials(authScope); assertNull(credentials); }