2017-10-09 87 views
-1

有用於認證使用LDAP用戶的模塊「模塊1」。該模塊有一個類,它必須使用相同的登錄ldap憑證向另一個遠程服務發出http請求。發送登錄憑證在HTTP報頭到安全服務器

我有一個實現遠程服務認證的LDAP類。

我不知道如何從模塊1發送的登錄憑據到遠程服務的HTTP標頭。如何以編程方式訪問我用於從Module1進行Ldap登錄的憑據?你的迴應會非常令人欣喜。

回答

1

你可以去基本身份驗證,其中用戶憑證將被編碼,並通過頁眉發送。請確保從模塊1呼叫固定到遠程服務,所以基本上是從模塊1到遠程服務的調用將通過HTTPS

0

如果您使用LDAP發生,認證可以像基本被冒充。如果您知道用戶名和密碼,請將標題「Authorization」附加值「Basic base64_token」。

基於64位令牌是一個字符串,它的base64與格式爲username的用戶名和口令進行編碼:密碼。理想情況下,這應該起作用。讓我知道如果它不起作用。在這種情況下,我們可以使用SPNEGO探索選項。

在JAVA對LDAP代碼:

public class Main 
{ 
    public static void main(String[] args) 
    { 
    //Replace username and password with your username and password 
    token = Base64.getEncoder().encodeToString((username + ":" + password).getBytes()) 
    conn = (HttpURLConnection) endpoint.openConnection(); 

    // Set the necessary header fields, which in this case is Basic 
    conn.addRequestProperty("Authorization", "Basic " + token); 

    //Continue to do what you want to do after this. This should authenticate 
    // you to the server 
    } 
}