@Test public void testAuthenticate() throws Exception { AbstractHttpClient client = mock(AbstractHttpClient.class); HttpContext context = mock(HttpContext.class); CredentialsProvider credentials = mock(CredentialsProvider.class); doReturn(credentials).when(client).getCredentialsProvider(); HttpBasicAuthentication auth = new HttpBasicAuthentication(client, context); auth.setUserName("username"); auth.setPassword("password"); URI uri = URI.create("http: auth.setTargetHost(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())); auth.execute(); verify(credentials).setCredentials(Matchers.<AuthScope>any(), Matchers.<Credentials>any()); verify(context).setAttribute(Matchers.<String>any(), any()); }
public void authenticate() { validate(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); }
HttpBasicAuthentication extends AbstractHttpAuthentication { public void authenticate() { validate(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); } }
HttpBasicAuthentication extends AbstractHttpAuthentication { public void authenticate() { validate(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); } HttpBasicAuthentication(HttpClient client, HttpContext context); }
HttpBasicAuthentication extends AbstractHttpAuthentication { public void authenticate() { validate(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); } HttpBasicAuthentication(HttpClient client, HttpContext context); void authenticate(); }
HttpBasicAuthentication extends AbstractHttpAuthentication { public void authenticate() { validate(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, password); httpClient.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), credentials); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); context.setAttribute(ClientContext.AUTH_CACHE, authCache); } HttpBasicAuthentication(HttpClient client, HttpContext context); void authenticate();  }