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

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

问题描述

我想从Java应用程序访问的SharePoint网站。 SharePoint服务器prefers 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?

推荐答案

所以只是为了帮助你扩大搜索答案有点,没有什么特定于SharePoint这里使用Kerberos身份验证。事实上的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.

的sooo,如果你正在运行Java ausing现代化的JDK,你可能有一个简单的时间。查看HTTP认证机制文档。这里也有一些不错的code片段在那里。其中之一,我会重现供参考。真的不过,检查出的链接。

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天全站免登陆