title: java http client for file upload to sharepoint using kerberos authentication
body: <p>Need standalone Java program that facilitate uploading files to Sharepoint using KERBEROS authentication. </p>
  
  <p>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. </p>
  
  <p>I had Kerberos configuration setup using SPNEGO API to connect sharepoint. </p>
  
  <p>Conf files: 
  krb5.conf 
  login.conf </p>
  
  <p>API used to Kerberos Auth: 
  spnego-r7.jar </p>
  
  <p>Connectivity: 
  Following code I am using for connectivity and File download which is perfectly working. </p>
  
  <pre><code>spnego = new SpnegoHttpURLConnection("spnego-client", &lt;&lt;sharepoint_user&gt;&gt;, &lt;&lt;sharepoint_password&gt;&gt;); 
  
  //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() &gt;= 200) { 
  log.debug("Authentication Successful"); 
  } 
  </code></pre>
  
  <p>File Read/Download: </p>
  
  <pre><code>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))&gt;=0) { 
  bout.write(data,0,x); 
  } 
  bout.close(); 
  in.close(); 
  </code></pre>
  
  <p>could you 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. </p>
  
  <p>Thanks in advance.</p>