2011-09-16 20 views
1

Javaクライアントからの共有ポイントリストにアクセスするためにJAX-WSを使用しています。私はntlm認証部分を解読することができません。それは私に403禁じられたerror.Butを与えている基本認証が有効になっているときに私は認証することができます。私のコードは以下の通りです。それ以前に誰かが働いたことはありますか?前もって感謝します。NTLM認証を使用してJavaのSharepointリストにアクセスする

public static void main(String[] args) { 
    try { 
     String userName = "INDIA\\arindam"; 
     String password = "[email protected]"; 
     String end = "http://www.sharepoint.com/_vti_bin/lists.asmx"; 
     com.microsoft.schemas.sharepoint.soap.ListsSoap port = null; 
     com.microsoft.schemas.sharepoint.soap.Lists service = new Lists(); 
     port = service.getListsSoap(); 
     NtlmAuthenticator authenticator = new NtlmAuthenticator(userName, password); 
     Authenticator.setDefault(authenticator); 
     String listName = "Shared Documents"; 
     String rowLimit = "150"; 
     String viewName = ""; 
     com.microsoft.schemas.sharepoint.soap.GetListItems.ViewFields viewFields = null; 
     com.microsoft.schemas.sharepoint.soap.GetListItems.Query query = null; 
     com.microsoft.schemas.sharepoint.soap.GetListItems.QueryOptions queryOptions = null; 
     String webID = ""; 
     com.microsoft.schemas.sharepoint.soap.GetListItemsResponse.GetListItemsResult result = port.getListItems(listName, viewName, query, viewFields, rowLimit, queryOptions, webID); 
     System.out.println(result.toString()); 
    } catch (Exception ex) { 
     System.err.println(ex); 
    } 
} 

*

public class NtlmAuthenticator extends Authenticator { 
    private final String username; 
    private final char[] password; 
    com.microsoft.schemas.sharepoint.soap.ListsSoap port = null; 
    com.microsoft.schemas.sharepoint.soap.Lists service = new Lists(); 

    public NtlmAuthenticator(final String username, final String password) { 
     super(); 
     this.username = new String(username); 
     this.password = password.toCharArray(); 
    } 
    @Override 
    public PasswordAuthentication getPasswordAuthentication() { 
     return (new PasswordAuthentication(username, password)); 
    } 
} 

答えて

0

私はまだ私はJAX-WSとNTLMで動作しますが、私は、少なくとも403のエラーを回避するために管理してきた長い多くの問題を見つけることです。ポートを作成した後、次の2行のコードを追加してみてください。

((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName); 
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
関連する問題