2013-12-10 66 views
0

我有NTLM身份驗證(我認爲是一樣的的Kerberos)同春RestTemplate服務調用的服務。有人知道我該怎麼做?衝刺RestTemplate Kerberos身份驗證

P.D:對不起,我的英語。

謝謝...

+0

看在上帝的份上,NTLM是不一樣的Kerberos的!你甚至無法使用Google。 –

回答

1

雖然RestTemplate可以被配置爲使用Apache的HttpClient它由缺省值(例如URLConnection)使用java.net類。

下面的代碼是未經測試,而是「應該工作」

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()); 
    } 
} 
+0

謝謝它的作品! – rjaraba