List of usage examples for org.apache.http.auth Credentials toString
public String toString()
From source file:org.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 v a 2 s. co m*/ up.setProxyUsername("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: bar][workstation: " + computername.toUpperCase() + "]", credentials.toString()); authScope = new AuthScope("host", 1234); credentials = getCredentialsProvider(httpClient).getCredentials(authScope); assertEquals("[principal: bar]", credentials.toString()); authScope = new AuthScope("anotherhost", AuthScope.ANY_PORT); credentials = getCredentialsProvider(httpClient).getCredentials(authScope); assertNull(credentials); }
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 w w w.j av a 2 s . co m*/ 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 av a 2 s . co 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 w w w . j a va 2 s . c o 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); }