使用Kerberos身份验证从Java应用程序访问SharePoint网站

5 java authentication sharepoint kerberos

我试图从Java应用程序访问SharePoint网站.SharePoint服务器更喜欢Kerberos身份验证.能否请您提供仅实施Kerberos身份验证的示例?

小智 7

因此,为了帮助您扩大搜索范围,有一点关于此处使用的Kerberos身份验证的SharePoint特定内容.事实上,SharePoint并没有真正拥有自己的身份验证机制(至少假设我们在这里谈论WSS 3/MOSS).它只依赖于底层的ASP.NET/IIS身份验证功能.

Sooo,如果您使用现代JDK运行Java,您可能会有一个轻松的时间.请参阅有关HTTP身份验证机制文档.那里有一些不错的代码片段.其中一个我将在这里复制以供参考.真的,请查看链接.

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;

public class RunHttpSpnego {

    static final String kuser = "username"; // your account name
    static final String kpass = "password"; // your password for the account

    static class MyAuthenticator extends Authenticator {
        public PasswordAuthentication getPasswordAuthentication() {
            // I haven't checked getRequestingScheme() here, since for NTLM
            // and Negotiate, the usrname and password are all the same.
            System.err.println("Feeding username and password for " + getRequestingScheme());
            return (new PasswordAuthentication(kuser, kpass.toCharArray()));
        }
    }

    public static void main(String[] args) throws Exception {
        Authenticator.setDefault(new MyAuthenticator());
        URL url = new URL(args[0]);
        InputStream ins = url.openConnection().getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
        String str;
        while((str = reader.readLine()) != null)
            System.out.println(str);
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 5

以下是开源SPNEGO HTTP Servlet过滤器库的Java文档中的示例.

该库有一个客户端,可以连接到已启用集成Windows身份验证的Web服务器.

该项目还提供了有关如何为Kerberos/SPNEGO身份验证设置环境的示例.

 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", "dfelix", "myp@s5");
         spnego.connect(new URL("http://medusa:8080/index.jsp"));

         System.out.println(spnego.getResponseCode());

     } finally {
         if (null != spnego) {
             spnego.disconnect();
         }
     }
 }
Run Code Online (Sandbox Code Playgroud)


And*_*ask 0

对于 Kerberos 设置,我知道有 3 个人知道有关 Kerb 的所有信息:Spence Harbar、Bob Fox 和 Tom Wisnowski。

Spence 还正在使用 Kerberos 向导来设置 Curb 并导出设置脚本。

在这里查看他的博客: http: //www.harbar.net/

汤姆·维兹诺夫斯基 (Tom Wiznowski) 发布了一份白皮书。 http://my/sites/tomwis/Shared%20Documents/Configuring%20Kerberos%20for%20SharePoint.docx

乔尔·奥尔森在这里得到了一篇好文章: http://www.sharepointjoel.com/Lists/Posts/Post.aspx ?ID=2

但如上所述,SharePoint 仅在公司已经使用 Curb 时才推荐使用 Curb。您不应仅仅因为 SharePoint 而在公司网络上安装 Kerberos。Kerberos 的设置很复杂,尽管通常认为它比 NTLM 更快,但只有当站点上的同时用户数达到一定限制时,情况才会如此。对于低流量站点,Kerberos 通过网络发送的大量令牌实际上使其比 NTLM 慢。

当然,有一些功能只能与 Kerberos 一起使用(rss feed、excel 服务中的多维数据集、由于双跳而在自定义代码中对 Web 服务调用进行身份验证),但是相信我,当我说 NTLM 会很好地运行您的应用程序时,请相信我。莫斯也。

如上所述,您能否具体说明您想要从 Java 应用程序中实现哪种集成?

您是否只是想调用 SharePoint 的 Web 服务层?

安德斯·拉斯克