开发者

Authentication failure calling SharePoint Web Service (JAX-WS client)

开发者 https://www.devze.com 2023-04-04 14:42 出处:网络
I have to call SharePoint 2010 Lists service from a Java client. I used NetBeans to generate the JAX-WS classes from the WSDL.

I have to call SharePoint 2010 Lists service from a Java client.

I used NetBeans to generate the JAX-WS classes from the WSDL.

And extended java.net.Authenticator to manage the authentication to SharePoint :

static final String user = "XXXXXXXX\\Administrateur"; // your account name
static final String pass = "mypassw"; // your password for the account

static class MyAuthenticator extends Authenticator {
        public PasswordAuthentication getPasswordAuthentication() {
            System.out.println("Feeding username and password for " + getRequestingScheme());
            return (new PasswordAuthentication(user, pass.toCharArray()));
        }
    }

Calling the web service with JAX-WS :

Authenticator.setDefault(new MyAuthenticator());

com.nm.Lists service = new com.nm.Lists();

com.nm.ListsSoap port = service.getListsSoap12();

String pageUrl = "http://xxxxxxx/testPushFile.txt";
String comment = "no comment";
String checkinType = "1";

boolean result = port.checkInFile(pageUrl, comment, checkinType);

I am still getting the error :

Exception in thread "main" javax.xml.ws.WebServiceException: java.io.IOException: Authentication failure
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.readResponseCodeAndMessage(HttpClientTransport.java:201)

Because it isn't working I tried :

  • to set the user without the d开发者_StackOverflow中文版omain

  • to set the domain as a system property : System.setProperty("http.auth.ntlm.domain", "XXXXXXXX");

  • to authenticate "old-fashioned way" :

      
    ((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, user);

    ((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, pass);

Any ideas what's the problem with authentication ?

Thanks


I am coming back to give the solution. Here is what I have done to make the Web Service authentication work :

  • I enabled Basic Authentication in IIS Manager for my SharePoint Site,
  • I used a user credentials that was registred in Windows Domain
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号