Basic authentication scheme as defined in RFC 2617.
305306307308309310311312313314315
@Test public void testAuthSucceededInvalidInput() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("locahost", 80); final BasicScheme authScheme = new BasicScheme(); final HttpClientContext context = HttpClientContext.create(); try { authStrategy.authSucceeded(null, authScheme, context); Assert.fail("IllegalArgumentException expected"); } catch (final IllegalArgumentException ex) {
328329330331332333334335336337338339
@Test public void testAuthSucceeded() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("somehost", 80); final BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); final AuthCache authCache = Mockito.mock(AuthCache.class); final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(authCache);
344345346347348349350351352353354355
@Test public void testAuthSucceededNoCache() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("somehost", 80); final BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(null); authStrategy.authSucceeded(authhost, authScheme, context);
359360361362363364365366367368369
@Test public void testAuthScemeNotCompleted() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("somehost", 80); final BasicScheme authScheme = new BasicScheme(); final AuthCache authCache = Mockito.mock(AuthCache.class); final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(authCache);
391392393394395396397398399400401
@Test public void testAuthFailedInvalidInput() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("locahost", 80); final BasicScheme authScheme = new BasicScheme(); final HttpClientContext context = HttpClientContext.create(); try { authStrategy.authFailed(null, authScheme, context); Assert.fail("IllegalArgumentException expected"); } catch (final IllegalArgumentException ex) {
409410411412413414415416417418419420
@Test public void testAuthFailed() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("somehost", 80); final BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); final AuthCache authCache = Mockito.mock(AuthCache.class); final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(authCache);
425426427428429430431432433434435
@Test public void testAuthFailedNoCache() throws Exception { final TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); final HttpHost authhost = new HttpHost("somehost", 80); final BasicScheme authScheme = new BasicScheme(); final HttpClientContext context = HttpClientContext.create(); context.setAuthCache(null); authStrategy.authFailed(authhost, authScheme, context);
205206207208209210211212213214215
// Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and add it to the local auth cache AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); HttpResponse response = null; maxit = 10;
5354555657585960616263
new UsernamePasswordCredentials("admin", "admin")); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
70717273747576777879
// Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and add it to the local auth cache AuthCache authCache = new BasicAuthCache(); authCache.put(targetHost, new BasicScheme()); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); return localcontext; }