Java equivalent to .NET's "System.Net.CredentialCache.DefaultCredentials"

Posted on 2006-05-09
Medium Priority
Last Modified: 2012-05-05
Here is the code in C# which works

<Begin C# Code>
Webs.Webs x = new Webs.Webs();
x.PreAuthenticate = true;
x.Credentials = System.Net.CredentialCache.DefaultCredentials;
x.Url = url + @"/_vti_bin/webs.asmx";
System.Xml.XmlNode n = x.GetWebCollection();
<End C# Code>

However I would like to access this SharePoint webservice from a java application.  How do I replicate the "System.Net.CredentialCache.DefaultCredentials" in java?

Here is my Java code but I get a "(401)Unauthorized" error which I also get in the .NET code if I don't do the "x.Credentials = System.Net.CredentialCache.DefaultCredentials" call.

I used wsdl2java to bring the webservice into eclipse (http://wsdl2javawizard.sourceforge.net/)

<Begin Java Code>
     _GetWebCollection parameters = new _GetWebCollection();
     WebsLocator w = new WebsLocator();
     WebsSoap ws = w.getWebsSoap();
catch (ServiceException e)
catch (RemoteException e)
Question by:gillgates
LVL 30

Accepted Solution

Mayank S earned 1000 total points
ID: 16645297
Are _GetWebCollection, WebsLocator, etc generated as stubs/ proxy-classes to some web-service using WSDL 2 Java? If so, they will have some methods for providing the credentials.
LVL 61

Assisted Solution

by:Kevin Cross
Kevin Cross earned 1000 total points
ID: 16652665
See if this helps: http://jcifs.samba.org/src/docs/ntlmhttpauth.html
Can find the remote user name using the request object: http://jcifs.samba.org/src/examples/NtlmHttpAuthExample.java

Maybe not quite what you were looking for, but could validate you have an authenticated user then you can use a generic account and password in your web service calls using stub methods created to pass username and password to sharepoint web services as mayankeagle elluded to, but see if will let you set what the active user is to the authenticated user of your java app to get the user specific content on the sharepoint page.  :)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question