首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有用于NTLM身份验证的http客户端的Spring Rest模板

带有用于NTLM身份验证的http客户端的Spring Rest模板
EN

Stack Overflow用户
提问于 2015-04-24 14:53:47
回答 1查看 6.5K关注 0票数 5

我们在IIS服务器上部署了一个web服务,它基于NTLM身份验证进行身份验证。

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

代码语言:javascript
复制
NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.http.auth.UsernamePasswordCredentials

请说明如何使用spring rest模板使用http客户端,以用户名和密码通过NTLM认证。

注意:虽然我收到了警告消息,但我也得到了响应。

EN

回答 1

Stack Overflow用户

发布于 2015-08-17 17:44:15

只需定义以下类即可。

代码语言:javascript
复制
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。

代码语言:javascript
复制
NtlmAuthenticator authenticator = new NtlmAuthenticator(userName,
                    password);
            Authenticator.setDefault(authenticator);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29840639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档