java - 如何通过 LDAPS 使用 Java 代码重置 RedHat Directory 服务器中的用户密码?

标签 java ldap redhat hp-ux directory-server

如何从我的 Java 应用程序使用 LDAPS 访问 RedHat 目录服务器/HP UX 目录服务器?我正在尝试通过 LDAP 访问它,它工作正常,但在使用 LDAPS 时它没有与服务器建立连接。

这是我的代码,它不起作用:

public void setPassword(String userDn,String password) {
    InitialDirContext ctx=null;
    DirContext connection;
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    String systemname = "ldaps://myserver:636";
    env.put(Context.PROVIDER_URL, systemname);  
    env.put(Context.SECURITY_PRINCIPAL, "cn=directory manager");
    env.put(Context.SECURITY_CREDENTIALS, "MySecret");
    ctx = new InitialDirContext(env);
    connection = (DirContext)ctx;
    connection.lookup("dc=mydomain,dc=com");
    ModificationItem[] mods = new ModificationItem[1];
    Attribute mod0 = new BasicAttribute("userpassword",password);
    mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, mod0);
    connection.modifyAttributes(userDn, mods);
    connection.close();
}

如果我用 ldap 替换 ldaps,上面的代码工作正常。

但是我也需要代码来为 LDAPS 工作。有些网站提到需要 keystore 、证书等。但我对这些一无所知。

最佳答案

你可以尝试一些事情:

  • 使用已知的好工具 ldapsearch 验证 LDAP 客户端是否可以连接到服务器
  • 使用 openssl s_client -connect host:port 验证客户端是否可以建立安全连接。

关于java - 如何通过 LDAPS 使用 Java 代码重置 RedHat Directory 服务器中的用户密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12894033/

相关文章:

centos - mount - 在 fstab 错误中找不到/dev/sdc

session - 简单终端命令后 RHEL session 崩溃(例如 cd ~)

linux - 针对 Linux 服务器(Web 服务器)集成 Windows/OSX/Linux 身份验证

java - BZip2 - 对于不同类型的文件,要传递给 FileOutputstream 的内容

java - 使用 Google API 的 CLI 应用程序

java - 如何找出我的进程 ID 正在哪个物理 CPU 上运行?

java - 如何使用 ldap 服务器 url 了解 ldap 的版本

python - 如何防止 python3 的 ldap3 中的 LDAP 注入(inject)

linux - 在 Red Hat Enterprise Linux 上安装 R Studio

java - "Could not find class android.transition.Transition"按返回键时异常