2017-10-09 88 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 
    } 
}