我们在IIS服务器上部署了一个web服务,它基于NTLM身份验证进行身份验证。
当我尝试通过在httpCleint UserNamePasswordCredentials中传递用户名和密码来访问web服务时,收到如下警告
NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials请说明如何使用spring rest模板使用http客户端,以用户名和密码通过NTLM认证。
注意:虽然我收到了警告消息,但我也得到了响应。
发布于 2015-08-17 17:44:15
只需定义以下类即可。
public class NtlmAuthenticator extends Authenticator {
private final String username;
private final char[] password;
public NtlmAuthenticator(final String username, final String password) {
super();
this.username = username;
this.password = password.toCharArray();
}
@Override
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(username, password));
}
}然后添加以下it.It开始工作的code.Thats。
NtlmAuthenticator authenticator = new NtlmAuthenticator(userName,
password);
Authenticator.setDefault(authenticator);https://stackoverflow.com/questions/29840639
复制相似问题