2017-07-13 81 views
0

我使用Apache的駱駝2.19,我能夠調用使用駱駝HTTP模塊我的終點,它支持NTLMv1身份開箱時要使用NTLMv1身份:呼叫的NTLMv2通過Apache的駱駝安全端點

from("activemq:{{queue.feedback}}") 
    .to("http://localhost:8888/ntlm/secured?authMethodPriority=NTLM 
       &authMethod=NTLM&authUsername=Zaphod 
       &authPassword=Beeblebrox&authDomain=Minor 
       &authHost=LightCity") 

的問題是我無法弄清楚如何使用NTLMv2進行請求。 的official documentation指出:

注:HTTP的駱駝是基於HttpClient的3.x版,因此只有 什麼被稱爲NTLMv1身份,在 NTLM協議的早期版本的支持有限。它根本不支持NTLMv2。 camel-http4有 支持NTLMv2。

當我嘗試使用駱駝http4它根本不值一提:

from("activemq:{{queue.feedback}}") 
    .to("http4://localhost:8888/ntlm/secured?authMethodPriority=NTLM 
       &authMethod=NTLM&authUsername=Zaphod 
       &authPassword=Beeblebrox&authDomain=Minor 
       &authHost=LightCity") 

看來,駱駝http4不知道NTLM都沒有。我試圖調查camel-http4 repo on GitHub,除了文檔之外,我找不到與NTLM相關的任何內容。

任何有關如何在Camel 2.19中使用NTLMv2的想法(駱駝的其他版本可能也很適合)?

回答

0

問題出在camel-http4組件上。默認情況下,它使用InputStreamEntity,它不是HttpEntity實體的可重複實現,這意味着一旦讀取了流 - 它已關閉,並且無法再讀取它。這導致MainClientExec失敗:

if (execCount > 1 && !RequestEntityProxy.isRepeatable(request)) { 
    throw new NonRepeatableRequestException("Cannot retry request with a non-repeatable request entity."); 
} 

這似乎是一個錯誤,因此解決辦法是InputStreamEntity轉換爲ByteArrayEntity(這是重複的)是在發送請求之前:

@Component 
public class NtlmProcessor implements Processor { 

    @Override 
    public void process(Exchange exchange) throws Exception { 
     HttpEntity httpEntity = exchange.getIn().getBody(HttpEntity.class); 

     byte[] bytes = EntityUtils.toByteArray(httpEntity); 

     ByteArrayEntity byteArrayEntity = new ByteArrayEntity(bytes, ContentType.get(httpEntity)); 

     exchange.getOut().setBody(byteArrayEntity); 
    } 
}