public void setCredentialsProvider(CredentialsProvider provider) { setCredentialsProvider(HTTPAuthScope.ANY, provider); }
/** * @param provider * @throws HTTPException */ public HTTPSession setCredentialsProvider(CredentialsProvider provider) throws HTTPException { setCredentialsProvider(provider, null); return this; }
@Deprecated public HTTPSession setCredentialsProvider(AuthScope scope, CredentialsProvider provider) throws HTTPException { return setCredentialsProvider(provider, scope); }
public void setCredentialsProvider(String scheme, CredentialsProvider provider) { AuthScope scope = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, scheme); setCredentialsProvider(scope, provider); }
/** * It is convenient to be able to directly set the Credentials * (not the provider) when those credentials are fixed. * * @param creds * @param scope where to use it (i.e. on what host) * @throws HTTPException */ public HTTPSession setCredentials(Credentials creds, AuthScope scope) throws HTTPException { assert (creds != null); if(scope == null) scope = AuthScope.ANY; CredentialsProvider provider = new BasicCredentialsProvider(); provider.setCredentials(scope, creds); setCredentialsProvider(provider, scope); return this; }
@Deprecated public HTTPSession setCredentialsProvider(String url, CredentialsProvider provider) throws HTTPException { assert (url != null && provider != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); setCredentialsProvider(provider, scope); return this; }
public void setCredentials(String scheme, Credentials creds) { CredentialsProvider provider = new HTTPConstantProvider(creds); setCredentialsProvider(scheme, provider); }
public void setCredentialsProvider(String surl) throws HTTPException { // Try to extract user info URI uri = HTTPAuthScope.decompose(surl); String userinfo = uri.getUserInfo(); if(userinfo != null) { int index = userinfo.indexOf(':'); String user = userinfo.substring(index); String pwd = userinfo.substring(index + 1, userinfo.length()); if(user != null && pwd != null) { // Create a non-interactive user+pwd handler CredentialsProvider bp = new HTTPBasicProvider(user, pwd); setCredentialsProvider(HTTPAuthPolicy.BASIC, bp); } } }
@Test public void testCache2() throws Exception { logger.info("*** Testing: Cache Invalidation visually"); if(!this.prop_display) { logger.error("Test aborted: requires display"); return; } for(AuthDataBasic data : basictests) { Result result = null; logger.info("*** URL: " + data.url); try (HTTPSession session = HTTPFactory.newSession(data.url)) { Login cp = new Login(data.user, BADPASSWORD); session.setCredentialsProvider(cp); result = invoke(session, data.url); report(result); } Assert.assertTrue("Incorrect return code: " + result.status, result.status == HttpStatus.SC_UNAUTHORIZED || result.status == HttpStatus.SC_FORBIDDEN); // retry with correct password; // AuthCache should automatically clear bad one from cache. try (HTTPSession session = HTTPFactory.newSession(data.url)) { Login cp = new Login(data.user, data.password); session.setCredentialsProvider(cp); result = invoke(session, data.url); report(result); } Assert.assertTrue("Incorrect return code: " + result.status, check(result.status)); } }
@Test public void testCache() throws Exception { logger.info("*** Testing: Cache Invalidation"); for(AuthDataBasic data : basictests) { Result result = null; TestProvider provider = null; logger.info("*** URL: " + data.url); // Do each test with a bad password to cause cache invalidation provider = new TestProvider(data.user, BADPASSWORD); HTTPSession session = HTTPFactory.newSession(data.url); session.setCredentialsProvider(provider); result = invoke(session, data.url); report(result,provider.counter); Assert.assertTrue("Incorrect return code: " + result.status, result.status == HttpStatus.SC_UNAUTHORIZED || result.status == HttpStatus.SC_FORBIDDEN); Assert.assertTrue("Credentials provider called: " + provider.counter, provider.counter == 1); // retry with correct password; // AuthCache should automatically clear bad one from cache. provider.setUserPwd(data.user, data.password); session.setCredentialsProvider(provider); result = invoke(session, data.url); report(result,provider.counter); Assert.assertTrue("Incorrect return code: " + result.status, check(result.status)); session.close(); } }
session.setCredentialsProvider(provider); result = invoke(session, data.url); report(result,provider.counter);