Reputation: 516
This might be vague or ambiguous, but I have to ask. I want to authenticate to a Kerberized service through Java. Is there any specific way to perform this if I have the krb5.conf and the server's keytab file?
Or, what method would you recommend to perform this?
Upvotes: 1
Views: 5466
Reputation: 516
I figured out a way to do this.
So, there's this SourceForge project which enables "Integrated Windows Authentication and Authorization in Java". If you have a service account in the server, you can pass that credentials in your Java code and get the server to authenticate you. It's available in Maven - Spnego Maven Dependency
Sample code for reference, taken from Spnego API Docs
public static void main(final String[] args) throws Exception {
System.setProperty("java.security.krb5.conf", "krb5.conf");
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("java.security.auth.login.config", "login.conf");
SpnegoHttpURLConnection spnego = null;
try {
spnego = new SpnegoHttpURLConnection("spnego-client", "username", "password");
spnego.connect(new URL("http://medusa:8080/index.jsp"));
System.out.println(spnego.getResponseCode());
} finally {
if (null != spnego) {
spnego.disconnect();
}
}
}
Thanks to Arunav Sanyal for the help :)
Upvotes: 1