Please make sure your environment is configured correctly for Kerberos, this can be achieved by running kinit. If this fails, you need to make sure that your krb5.ini (windows) or krb5.conf (linux) is configured correctly on your domain controller.
Once you confirm that Kerberos is functional, you can use the sample code from HttpClient, as shown below.
Please note that there are many problems that can lead to Kerberos failure, for example, time synchronization, supported encryption types, trust relationships between domain forests, and it is also worth making sure that your client is on a separate box on the server.
Here is a sample code that is available in the HttpClient download, you need to make sure that your JAAS and krb5.conf or ini configurations are correct!
public class ClientKerberosAuthentication { public static void main(String[] args) throws Exception { System.setProperty("java.security.auth.login.config", "login.conf"); System.setProperty("java.security.krb5.conf", "krb5.conf"); System.setProperty("sun.security.krb5.debug", "true"); System.setProperty("javax.security.auth.useSubjectCredsOnly","false"); DefaultHttpClient httpclient = new DefaultHttpClient(); try { httpclient.getAuthSchemes().register(AuthPolicy.SPNEGO, new SPNegoSchemeFactory()); 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); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); System.out.println("----------------------------------------"); if (entity != null) { System.out.println(EntityUtils.toString(entity)); } System.out.println("----------------------------------------");
source share