4. Using KerberosRestTemplate

If there is a need to access Kerberos protected web resources programmatically we have KerberosRestTemplate which extends RestTemplate and does necessary login actions prior to delegating to actual RestTemplate methods. You basically have few options to configure this template.

With ticket cache.

public void doWithTicketCache() {
    KerberosRestTemplate restTemplate =
            new KerberosRestTemplate();
    restTemplate.getForObject("http://neo.example.org:8080/hello", String.class);
}

With keytab file.

public void doWithKeytabFile() {
    KerberosRestTemplate restTemplate =
            new KerberosRestTemplate("/tmp/user2.keytab", "[email protected]");
    restTemplate.getForObject("http://neo.example.org:8080/hello", String.class);
}