使用 Kerberos 身份验证从 Java 应用程序访问 SharePoint 网站 [英] Access a SharePoint website from a Java application with Kerberos authentication

查看:15
本文介绍了使用 Kerberos 身份验证从 Java 应用程序访问 SharePoint 网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to access a SharePoint website from a Java application. The SharePoint server prefers Kerberos authentication. Can you please provide an example for just the implementation of Kerberos authentication?

推荐答案

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

So just to help you broaden your search for answers a bit, there's nothing SharePoint-specific about the Kerberos authentication used here. In fact SharePoint doesn't really have it's own authentication mechanisms (at least assuming we're talking about WSS 3/MOSS here). It just relies on the underlying ASP.NET/IIS authentication capabilities.

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

Sooo, if you're running your Java ausing a modern JDK, you'll probably have an easy time. See the docs on HTTP authentication mechanisms. There's some nice code snippets in there. One of which I'll reproduce for reference here. Really though, check out the link.

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);
    }
}

这篇关于使用 Kerberos 身份验证从 Java 应用程序访问 SharePoint 网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆