public HTTPMethod setCredentials(Credentials creds) throws HTTPException { this.session.setCredentials(creds); return this; }
public HTTPMethod setCredentials(Credentials creds, AuthScope scope) throws HTTPException { this.session.setCredentials(creds, scope); return this; }
/** * It is convenient to be able to directly set the Credentials * (not the provider) when those credentials are fixed. * Scope defaults to ANY * * @param creds * @throws HTTPException */ public HTTPSession setCredentials(Credentials creds) throws HTTPException { setCredentials(creds, null); return this; }
@Deprecated public HTTPSession setCredentials(String url, Credentials creds) throws HTTPException { assert (creds != null); AuthScope scope = HTTPAuthUtil.uriToAuthScope(url); setCredentials(creds, scope); return this; }
this.methodurl = HTTPUtil.uriExclude(this.methodurl, HTTPUtil.URIPart.USERINFO); this.session.setCredentials( new UsernamePasswordCredentials(this.userinfo));
@Test public void testFailBadUser() { String endpoint = TestOnLocalServer.withHttpPath(path); logger.info(String.format("testRestriction req = '%s'", endpoint)); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { session.setCredentials(new UsernamePasswordCredentials("baadss", "changeme")); HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); Assert.assertTrue(statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN); } catch (ucar.httpservices.HTTPException e) { Assert.fail(e.getMessage()); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testSuccess() { String endpoint = TestOnLocalServer.withHttpPath(path); logger.info(String.format("testRestriction req = '%s'", endpoint)); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { session.setCredentials(new UsernamePasswordCredentials("tds", "secret666")); HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); Assert.assertEquals(200, statusCode); } catch (ucar.httpservices.HTTPException e) { Assert.fail(e.getMessage()); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Test public void testFailBadPassword() { String endpoint = TestOnLocalServer.withHttpPath(path); logger.info(String.format("testRestriction req = '%s'", endpoint)); try (HTTPSession session = HTTPFactory.newSession(endpoint)) { session.setCredentials(new UsernamePasswordCredentials("tiggeUser", "changeme")); HTTPMethod method = HTTPFactory.Get(session); int statusCode = method.execute(); //if (statusCode != HttpStatus.SC_UNAUTHORIZED && statusCode != HttpStatus.SC_FORBIDDEN) // assert false; Assert.assertTrue(statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN); } catch (ucar.httpservices.HTTPException e) { Assert.fail(e.getMessage()); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
session.setCredentials(cred);
session.setMaxRedirects(111); Credentials bp = new UsernamePasswordCredentials("anyuser", "password"); session.setCredentials(bp);
session.setCredentials(creds); result = invoke(session, data.url); report(result);