Basic authentication scheme as defined in RFC 2617.
323324325326327328329330331332333334
@Test public void testAuthSucceeded() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("somehost", 80); BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); AuthCache authCache = Mockito.mock(AuthCache.class); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache);
339340341342343344345346347348349350
@Test public void testAuthSucceededNoCache() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("somehost", 80); BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, null); authStrategy.authSucceeded(authhost, authScheme, context);
354355356357358359360361362363364
@Test public void testAuthScemeNotCompleted() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("somehost", 80); BasicScheme authScheme = new BasicScheme(); AuthCache authCache = Mockito.mock(AuthCache.class); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache);
386387388389390391392393394395396
@Test public void testAuthFailedInvalidInput() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("locahost", 80); BasicScheme authScheme = new BasicScheme(); HttpContext context = new BasicHttpContext(); try { authStrategy.authFailed(null, authScheme, context); Assert.fail("IllegalArgumentException expected"); } catch (IllegalArgumentException ex) {
404405406407408409410411412413414415
@Test public void testAuthFailed() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("somehost", 80); BasicScheme authScheme = new BasicScheme(); authScheme.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "Basic realm=test")); AuthCache authCache = Mockito.mock(AuthCache.class); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, authCache);
420421422423424425426427428429430
@Test public void testAuthFailedNoCache() throws Exception { TargetAuthenticationStrategy authStrategy = new TargetAuthenticationStrategy(); HttpHost authhost = new HttpHost("somehost", 80); BasicScheme authScheme = new BasicScheme(); HttpContext context = new BasicHttpContext(); context.setAttribute(ClientContext.AUTH_CACHE, null); authStrategy.authFailed(authhost, authScheme, context);
461462463464465466467468469470471
final URI requestURI = currentRequest.getURI(); if (requestURI != null) { final String userinfo = requestURI.getUserInfo(); if (userinfo != null) { final AuthState targetAuthState = localContext.getTargetAuthState(); targetAuthState.update(new BasicScheme(), new UsernamePasswordCredentials(userinfo)); } } HttpHost target = null; final HttpRequest original = currentRequest.getOriginal();
220221222223224225226227228229230
final BasicSchemeFactory myBasicAuthSchemeFactory = new BasicSchemeFactory() { @Override public AuthScheme create(final HttpContext context) { return new BasicScheme() { @Override public String getSchemeName() { return "MyBasic"; }
296297298299300301302303304305306
this.currentRequest = this.mainRequest.getRequest(); final String userinfo = this.currentRequest.getURI().getUserInfo(); if (userinfo != null) { this.targetAuthState.update( new BasicScheme(), new UsernamePasswordCredentials(userinfo)); } // Re-write request URI if needed rewriteRequestURI(this.currentRequest, route); }
138139140141142143144145146147148
HttpHost targetHost = new HttpHost( uri.getHost(), uri.getPort(), uri.getScheme() ); // 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 );