具有HTTP客户端的Spring Rest模板用于NTLM身份验证 [英] Spring Rest template with http client for NTLM authentication

查看:491
本文介绍了具有HTTP客户端的Spring Rest模板用于NTLM身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在IIS服务器中部署了一个Web服务,该服务基于NTLM身份验证进行验证.

We have a web service deployed in IIS server which authenticate based on NTLM authentication.

当我尝试通过在httpCleint UserNamePasswordCredentials中传递用户名和密码来访问Web服务时,收到的警告为

When i try to access the web service by passing username and password in httpCleint UserNamePasswordCredentials, am getting warnings as

NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials

请说明如何使用带有spring rest模板的http客户端来通过具有用户名和密码的NTLM身份验证.

Please clarify how to user http client with spring rest template to pass the NTLM authentication with user name and password.

注意:尽管收到警告消息,但也得到了答复.

Note:Though am getting the warning message, am also getting response.

推荐答案

只需定义以下类.

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));
        }
    }

然后添加以下代码.就这样,它开始工作.

then add the following code.Thats it.It started working.

NtlmAuthenticator authenticator = new NtlmAuthenticator(userName,
                    password);
            Authenticator.setDefault(authenticator);

这篇关于具有HTTP客户端的Spring Rest模板用于NTLM身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆