title: HttpClient set credentials for Kerberos authentication
body: <p>I am trying to authenticate with a kerberos/HTTP host. Using Apache HttpClient as my client - and a slightly modified version of <a href="http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientKerberosAuthentication.java?p=820841" rel="noreferrer">this source.</a>
  My Kerberos authentication goes perfectly fine, and I wish to know how to set the login credentials programatically. At the moment, the credentials are entered manually through the console, but I want to have it chosen by me at run time. [ As I wish to automate and load test the server with a large number of users, actually. ].</p>
  
  <p>EDIT : Here is a code snippet of the relevant parts : </p>
  
  <pre><code>..
          NegotiateSchemeFactory nsf = new NegotiateSchemeFactory();        
          httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, nsf);
  
          Credentials use_jaas_creds = new Credentials() {
  
              public String getPassword() {
                  return null;
              }
  
              public Principal getUserPrincipal() {
                  return null;
              }    
          };
  
          httpclient.getCredentialsProvider().setCredentials(
                  new AuthScope(null, -1, null),
                  use_jaas_creds);
  
          HttpUriRequest request = new HttpGet("http://kerberoshost/");
          HttpResponse response = httpclient.execute(request);
   .. 
  </code></pre>
  
  <p>The interface <code>Credentials</code> has two methods - <code>getPassword()</code> and <code>getUserPrincipal()</code>, but from some debugging I did, they don't seem to be invoked at all.</p>
  
  <p>What am I missing here ? What is a cleaner way to statically set the credentials ? </p>
  
  <p>A very <a href="https://stackoverflow.com/questions/10923283/setting-username-programatically-instead-of-prompt-with-httpclient-kerberos">similar question had been asked before</a>, but keytabs/login.conf hack is too cumbersome and not a practical option for an automated load test with a large number of user credentials. 
  Appreciate any help on this.</p>