2016-09-21 158 views
0

我想編寫一個需要摘要式身份驗證以在服務器上進行身份驗證的Java Websocket客戶端。使用Jetty Websocket客戶端的摘要式身份驗證

我玩過Jetty Websocket client example,但我不知道如何輕鬆添加摘要認證。此外,我沒有找到線上資源,提供了有關如何完成的提示。

我也很難找到網上的信息,因爲大多數人使用Jetty作爲服務器(顯然)。例如,這不是重複的:How to authenticate websocket client in jetty?

因此,我想知道是否有可能對Jetty Websocket客戶端使用摘要式身份驗證?

回答

0

你可以嘗試這兩種方法:

  1. 把你的用戶名和密碼在WebSocket的URL。
    例如。 ws://用戶名:[email protected]/resturl

  2. 生成授權並將其放入請求標頭。

    String userpass = accessKey + ":" + secretKey; 
    
    String authorization = "Basic " + new String(new Base64().encode(userpass.getBytes())).trim(); 
    
    ClientUpgradeRequest request = new ClientUpgradeRequest(); 
    
    request.setHeader("Authorization", authorization);