需要独立的 Java 程序,以便使用 KERBEROS 身份验证将文件上传到 Sharepoint。
我们有升级到 2010 版本并配置了 Kerberos 身份验证的共享点服务器。早期的共享点版本使用 NTLM 身份验证,我有 javaq 客户端程序从本地系统上传文件。由于 sharepoint 已使用 Kerberos 身份验证进行了升级,因此我需要修改当前 NTLM 版本的 Java 程序以使用 Kerberos。我得到了用于身份验证和连接的代码片段,它工作正常。我能够读取 Sharepoint URL 并通过 java 程序下载特定文件。现在我正在尝试将文件上传到 Sharepoint,但没有获得用于此所需的 Java 类和 jar 文件。
我有使用 SPNEGO API 连接共享点的 Kerberos 配置设置。
配置文件:krb5.conf login.conf
用于 Kerberos 身份验证的 API:spnego-r7.jar
连接性:我使用以下代码进行连接和文件下载,这是完美的工作。
spnego = new SpnegoHttpURLConnection("spnego-client", <<sharepoint_user>>, <<sharepoint_password>>);
//New Lines added to omit SSL Handshake exception
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers(){
return null;
}
public void checkClientTrusted(java.security.cert.X509Certific ate[] certs, String authType){
//No need to implement.
}
public void checkServerTrusted(java.security.cert.X509Certific ate[] certs, String authType){
//No need to implement.
}
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.g etSocketFactory());
spnego.connect(new URL(spLocation));
System.out.println("spnego.getResponseCode():: "+spnego.getResponseCode());
if(spnego.getResponseCode() >= 200) {
log.debug("Authentication Successful");
}
文件读取/下载:
java.io.BufferedInputStream in = new java.io.BufferedInputStream( spnego.getInputStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream(outputFile);
java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte[] data = new byte[1024];
int x=0;
System.out.println("4" + outputFile.length());
while((x=in.read(data,0,1024))>=0) {
bout.write(data,0,x);
}
bout.close();
in.close();
您能否建议如何使用 java 代码将文件上传到 Sharepoint 文件夹。我搜索了许多论坛几个小时,但没有得到文件上传的确切代码。您对此的建议非常感谢。
提前致谢。