Username and password {@link Credentials}.
76777879808182838485
HttpClient c = new HttpClient(connectionManager); // use basic authentication if available if (user != null && user.length() > 0) { AuthScope authScope = new AuthScope(null, -1, null); Credentials credentials = new UsernamePasswordCredentials(user, password); c.getState().setCredentials(authScope, credentials); } return c; }
6667686970717273747576
// gives an unauthorized response in certain situations, thus reducing the overhead of making the // connection. client.getState().setAuthenticationPreemptive(true); // Set up the WMS credentials: Credentials credentials = new UsernamePasswordCredentials(authentication.getUser(), authentication.getPassword()); client.getState().setCredentials(authentication.getRealm(), parseDomain(url), credentials); } // Create the GET method with the correct URL:
120121122123124125126127128129130
{ log.debug("Connecting to: "+url); String userInfo = url.getUserInfo(); if( userInfo != null ) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials(realm, url.getHost(), auth); } log.debug("RequestURI: "+request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText();
115116117118119120121122123124125
log.info("Connecting to: "+ url); String userInfo = url.getUserInfo(); if( userInfo != null ) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials("JBossTest Servlets", url.getHost(), auth); } log.info("RequestURI: "+request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText();
151152153154155156157158159160161
log.info("Connecting to: "+ url); String userInfo = url.getUserInfo(); if( userInfo != null ) { UsernamePasswordCredentials auth = new UsernamePasswordCredentials(userInfo); httpConn.getState().setCredentials(realm, url.getHost(), auth); } log.info("RequestURI: "+request.getURI()); int responseCode = httpConn.executeMethod(request); String response = request.getStatusText();
919293949596979899
} @Test public void testSecureLinksAdmin() throws Exception { httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "asd")); Book book = client.getBookXML("foo"); checkBookLinks1(url, book, "add", "update", "list", "self", "remove"); }
99100101102103104105106107
} @Test public void testSecureLinksPowerUser() throws Exception { httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("power-user", "asd")); Book book = client.getBookXML("foo"); checkBookLinks1(url, book, "add", "update", "list", "self"); }
107108109110111112113114115
} @Test public void testSecureLinksUser() throws Exception { httpClient.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user", "asd")); Book book = client.getBookXML("foo"); checkBookLinks1(url, book, "list", "self"); }
2425262728293031323334
HttpClient client = new HttpClient(); client.getState().setCredentials( //new AuthScope(null, 8080, "Test"), new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials("bill", "password") ); { GetMethod method = new GetMethod("http://localhost:8080/basic-integration-test/security"); method.setDoAuthentication(true); int status = client.executeMethod(method);
8990919293949596979899
HttpClient client = new HttpClient(); client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials( //new AuthScope(null, 8080, "Test"), new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials("bill", "password")); { GetMethod method = createGetMethod("/secured"); method.setDoAuthentication(true); int status = client.executeMethod(method); Assert.assertEquals(HttpResponseCodes.SC_OK, status);