gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:02 25 4
gpt4 key购买 nike

我正在尝试访问 SharePoint来自 Java 应用程序的网站。 SharePoint 服务器首选 Kerberos 身份验证。您能否提供一个仅实现 Kerberos 身份验证的示例?

最佳答案

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

Sooo,如果您使用现代 JDK 运行 Java,您可能会很轻松。查看docs on HTTP authentication mechanisms .那里有一些不错的代码片段。我将在此处复制其中一个以供引用。不过,请查看链接。

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

关于java - 使用 Kerberos 身份验证从 Java 应用程序访问 SharePoint 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/592403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com