6

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

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

如果可以提供相同的演示或示例代码,那就太好了。

提前致谢。

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

4

3 回答 3

4

waffle dosent 支持 *nix。您可以在支持Krb5LoginModule的情况下使用JASS (仅限 Java SE 8),这将使您能够缓存操作系统票证。

于 2017-11-03T14:04:30.077 回答
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
  }
}
于 2017-09-25T09:37:01.000 回答
1

专门用于 windows 。单点登录可以通过使用 waffle 来完成。

对于 Ldap 身份验证,您可以使用以下代码行通过 spring mvc 转到简单的 java 类:

    String username = login.getUsername();// "ancb";
    String password = login.getPassword();// "*****";
    String base = "OU=******,DC=InfoDir,DC=DEV,DC=****";
    String dn = "CN=" + username + "," + base;
    String ldapURL = "ldaps://****.systems.**.****:3269";

    // Setup environment for authenticating
    Hashtable<String, String> environment = new Hashtable<String, String>();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    environment.put(Context.PROVIDER_URL, ldapURL);
    environment.put(Context.SECURITY_AUTHENTICATION, "simple");
    environment.put(Context.SECURITY_PRINCIPAL, dn);
    environment.put(Context.SECURITY_CREDENTIALS, password);

    String dynamicLdapaccount = "(CN="+ username +")" ;

        DirContext authContext = new InitialDirContext(environment);

对于单点登录:

您需要在服务器级别设置 Kerberos 和 Spnego 配置。对于自由服务器,它的 server.xml 需要修改。

于 2017-10-26T04:57:03.703 回答