Monday, March 24, 2008

Authentication with Oracle HTTPClient

Oracle's HTTPClient supports Basic, Digest and NTML (since 10.1.3.1) schemes. I could not find good documentation on these. Here is my attempt to fill this gap. These code examples are taken from unit tests I wrote some years back.

Basic Authentication

I won't go in details on HTTP Basic auth. But here is an example of code that shows how the reader can configure HTTPClient to send HTTP Basic authentication info.



URL url = new URL("http://localhost:1234");
HTTPConnection client = new HTTPConnection(url);

try {
client.addBasicAuthorization("realm name", "user", "password");
HTTPResponse response = client.Get(url.getFile());
//assertEquals(200, response.getStatusCode());

} finally {
client.stop();
}


Digest Authentication

HTTPConnection client = new HTTPConnection(url);
try {
client.addDigestAuthorization("ProxyAuthDigestSchemeTestServlet",validUserName,validPassword);
HTTPResponse response = client.Get(url.getFile());
// assertEquals(200, response.getStatusCode());

} finally {
client.stop();
}



Starting 10.1.3.1 HTTPClient supported NTML as well. I'll cover NTLM support in HTTPClient in my next post.

Setting authentication method on the HTTPConnection object is just one way to set the credential. The two other ways are providing authentication info via an AuthorizationPrompter implementation or Providing it in the AuthorizationInfo object. See OracleHTTPClient javadoc for details.

No comments: