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

Posted on 2006-05-09
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 (

<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

    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 59

    Assisted Solution

    by:Kevin Cross
    See if this helps:
    Can find the remote user name using the request object:

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now