• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need Java client to Upload files to Sharepoint 2010 using Kerberos authentication

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

Need help on Java client to upload file to Sharepoint which is using KERBEROS authentication.

We have sharepoint server which is upgraded to 2010 version and is configured with Kerberos authentication. Earlier sharepoint version was using NTLM authentication for which I have javaq client program to upload files from local system. Since sharepoint got upgraded with Kerberos authentication, I need to modify current NTLM versioned java program to use Kerberos. I got code snippet for authentication and connectivity which is working fine. I am able to read Sharepoint URL and download a specific file though java program. Now I am trying upload file to Sharepoint but not getting the required java classes and jar files to be used for this.

I had Kerberos configuration setup using SPNEGO API to connect sharepoint.

Conf files:
krb5.conf
login.conf

API used to Kerberos Auth:
spnego-r7.jar


Connectivity:
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
spnego.connect(new URL(spLocation));
System.out.println("spnego.getResponseCode():: "+spnego.getResponseCode());
if(spnego.getResponseCode() >= 200) {
log.debug("Authentication Successful");
}

File Read/Download:
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();


Kindly advise how to upload files to Sharepoint folder using java code. I searched many forums for hours but not getting exact code for File upload. Your advice on this much appreciated.

Thanks in advance.
 
poli reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following code I am using for connectivity and File download. Please advise how to Upload file.

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.X509Certificate[] certs, String authType){
//No need to implement.
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType){
//No need to implement.
}
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
spnego.connect(new URL(spLocation));
System.out.println("spnego.getResponseCode():: "+spnego.getResponseCode());
if(spnego.getResponseCode() >= 200) {
log.debug("Authentication Successful");
}
 
poli reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry for cross post. Henceforth I will ensure to post only in one forum.

Please advise your suggestion on this: Uploading file to Sharepoint through Java client using Kerberos Authentication.
 
poli reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any advice on this please?
 
poli reddy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally after 10 days of continuous research and search through many blogs, I got solution for my problem. I hope this helps someone needy:


 
This tiny ad will self destruct in five seconds.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic