Liberty服务器上的LDAP java单点登录

Yax*_*hah 6 java ldap single-sign-on websphere-liberty open-liberty

我想使用Java在Websphere-Liberty服务器上实现单点登录.我想使用LDAP对用户进行身份验证.

我搜索了很多但找不到确切的例子.我已经检查了堆栈溢出的每个可用示例.但没有运气.

如果可以为它提供演示或示例代码,那将是很好的.

提前致谢.

更新:我能够在华夫饼干的帮助下实现相同的功能..但华夫饼不适用于Linux/Unix... 谁能帮帮我吗?

ayr*_*sme 1

如果您使用 LDAP,则可以像 Basic 一样传递身份验证。如果您知道用户名和密码,请在标头“Authorization”后附加值“Basic base64_token”。

Base64 令牌是使用您的用户名和密码进行 Base64 编码的字符串,格式为用户名:密码。理想情况下,这应该有效。如果不起作用请告诉我。在这种情况下,我们可以使用 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
  }
}
Run Code Online (Sandbox Code Playgroud)