Chr*_*oph 13 java sharepoint exchange-server ntlm jax-ws
我试着通过JAX-WS访问SharePoint列表中所描述的在这里
但是,当运行下面的代码时,我得到:
java.lang.Exception: Exception. See stacktrace.com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
Run Code Online (Sandbox Code Playgroud)
Sharepoint需要NTLM身份验证.可能是什么问题?非常感谢!
public static ListsSoap sharePointListsAuth(String userName, String password) throws Exception {
ListsSoap port = null;
if (userName != null && password != null) {
try {
Lists service = new Lists();
port = service.getListsSoap();
System.out.println("Web Service Auth Username: " + userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, userName);
((BindingProvider) port).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
} catch (Exception e) {
throw new Exception("Error: " + e.toString());
}
} else {
throw new Exception("Couldn't authenticate: Invalid connection details given.");
}
return port;
}
Run Code Online (Sandbox Code Playgroud)
Mar*_*evy 17
在使用JAX-WS连接到Exchange Web服务时,我遇到了同样的问题,这对我有用:
首先,创建一个身份验证器:
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class NtlmAuthenticator extends Authenticator {
private final String username;
private final char[] password;
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));
}
}
Run Code Online (Sandbox Code Playgroud)
在您的应用程序中,将身份验证器设置为默认值:
String username = "DOMAIN\\USERNAME";
String password = "PASSWORD"
NtlmAuthenticator authenticator = new NtlmAuthenticator(username, password);
Authenticator.setDefault(authenticator);
Run Code Online (Sandbox Code Playgroud)
请注意,我正在使用方法#2来指定域,如Java文档中所述.
| 归档时间: |
|
| 查看次数: |
20865 次 |
| 最近记录: |