首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sprint RestTemplate Kerberos认证

Sprint RestTemplate Kerberos认证
EN

Stack Overflow用户
提问于 2013-12-10 20:49:16
回答 1查看 2.7K关注 0票数 0

我必须使用NTLM身份验证(我认为与Kerberos相同)调用一个带有Spring RestTemplate服务的服务。有人知道我怎么做到的吗?

对不起,我的英语。

谢谢..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-10 21:06:53

虽然RestTemplate可以配置为使用Apache HttpClient,但默认情况下它使用java.net类(例如URLConnection)。

以下代码未经测试,但“应该工作”

代码语言:javascript
复制
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
// maybe use "domain\username" instead
Authenticator.setDefault(new MyAuthenticator("username", "password"));
...
<your-RestTemplate-call-here>
...
class MyAuthenticator extends Authenticator {
    private String httpUsername;
    private String httpPassword;

    public MyAuthenticator(String httpUsername, String httpPassword) {
        this.httpUsername = httpUsername;
        this.httpPassword = httpPassword;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        System.out.println("Scheme:" + getRequestingScheme());
        return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20504908

复制
相关文章

相似问题

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