Java Kerberos 身份验证

Java Kerberos Authentication

这可能含糊不清或模棱两可,但我不得不问。我想通过 Java 向基于 Kerberos 的服务进行身份验证。如果我有 krb5.conf 和服务器的密钥表文件,是否有任何特定的方法来执行此操作?

或者,您会推荐什么方法来执行此操作?

我想出了一个方法来做到这一点。

所以,有这个 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

参考示例代码,取自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();
             }
         }
     }

感谢 Arunav Sanyal 的帮助:)