简体   繁体   English

Java LDAP-无法验证用户

[英]Java LDAP - unable to authenticate users

I facing a issue need to resolve this as soon as possible need your help. 我面临一个问题,需要尽快解决此问题,需要您的帮助。

I have a very simple java program just for sample authentication of ldap user 我有一个非常简单的Java程序,仅用于ldap用户的示例身份验证

Issue -1 -: 问题-1-:

public static void main(String[] args) throws NamingException {

        final String ldapAdServer = "ldap://0.0.0.0:389";


        final String ldapUsername = "uid=test,ou=People,dc=example,dc=com";
        final String ldapPassword = "gdyb21LQTcIANtvYMT7QVQ==";


        Hashtable<String, Object> env = new Hashtable<String, Object>();
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        if (ldapUsername != null) {
            env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
        }
        if (ldapPassword != null) {
            env.put(Context.SECURITY_CREDENTIALS, ldapPassword);
        }
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, ldapAdServer);

        env.put("java.naming.ldap.attributes.binary", "objectSID");
        DirContext ctx = new InitialDirContext(env);

    }

running the above program gives "[LDAP: error code 49 - Invalid Credentials]" error also I have taken the export of ldap users and userPassword is same as entered in the program 运行上面的程序也会显示“ [LDAP:错误代码49-无效凭据]”错误,我也导出了ldap用户,并且userPassword与在程序中输入的相同

dn: uid=test,ou=People,dc=example,dc=com objectClass: person objectClass: inetOrgPerson objectClass: organizationalPerson objectClass: top uid: test mail: test@yopmail.com userPassword: {MD5}gdyb21LQTcIANtvYMT7QVQ==

The same password I have entered above and the java code is throwing error additionally I have used dsconfig and configured "default-password-storage-scheme" to use MD5 and same works well when I just gives the plain password but I need to pass MD5 hex password to ldap to get authenticated . 我在上面输入的密码相同,并且Java代码抛出错误,另外,我使用了dsconfig并配置了“ default-password-storage-scheme”以使用MD5,当我只提供普通密码但我需要通过MD5时,同样效果很好ldap的十六进制密码以进行身份​​验证。

Issue- 2-: we are using liferay as backend system and all users details must be stored in ldap if user is changing password liferay is generating password using MD5 and hex encoding something like this "098f6bcd4621d373cade4e832627b4f6 " but when the same when exported using export ldiff option we are something like this in ldap "{MD5}gdyb21LQTcIANtvYMT7QVQ==" there is a mismatch between the password genearted by liferay and ldap I want the liferay md5 password to go in ldap. 问题2:我们使用liferay作为后端系统,如果用户更改密码,则所有用户详细信息都必须存储在ldap中。liferay使用MD5和十六进制编码(如“ 098f6bcd4621d373cade4e832627b4f6”)生成密码,但使用导出ldiff导出时相同选项,我们在ldap“ {MD5} gdyb21LQTcIANtvYMT7QVQ ==” =“中是这样的,liferay和ldap生成的密码之间不匹配,我希望liferay md5密码进入ldap。 Again entering the same password obtained form ldiff file and putting the same in the java program doesnt seem to work and plain clear text password works. 再次输入从ldiff文件获得的相同密码并将其放入Java程序中似乎无效,并且纯明文密码也有效。

Need serious help on this . 在这方面需要认真的帮助。

Please feel free if any additional information is required on the same. 如果需要任何其他信息,请随时联系。

There is nothing wrong with your code. 您的代码没有错。 The problem is that OpenDJ is expecting the clear text password instead of the hashed value (which is what you're using). 问题在于OpenDJ期望使用明文密码而不是哈希值(这是您使用的密码)。

When OpenDJ receives a bind request (a bind request is how users authenticate against an LDAP server) it will grab the password from the request, compute the hash value, and compare it against the value stored in the userPassword attribute ( gdyb21LQTcIANtvYMT7QVQ== in your case). 当OpenDJ收到绑定请求(绑定请求是用户针对LDAP服务器进行身份验证的方式)时,它将从请求中获取密码,计算哈希值,然后将其与存储在userPassword属性中的值进行比较( gdyb21LQTcIANtvYMT7QVQ ==案件)。 Notice that OpenDJ prepends the hash algorithm that was used originally (MD5, SHA1, etc...). 请注意,OpenDJ预先添加了最初使用的哈希算法(MD5,SHA1等)。

So using clear text passwords should fix Issue 1 . 因此,使用明文密码应该可以解决问题1

The above explanation should also bring some light as to what's causing Issue 2 . 上面的解释还应该阐明引起问题2的原因 Liferay is passing the password hash when modifying the userPassword attribute in OpenDJ. 当在OpenDJ中修改userPassword属性时,Liferay将传递密码哈希。 However OpenDJ believes it's receiving the clear text value so it hashes the password again. 但是,OpenDJ认为它正在接收明文值,因此会再次哈希密码。 Thus you end up with a "double hashed" password in your LDAP server. 因此,您最终在LDAP服务器中使用“双哈希”密码。

You have two options to fix Issue 2: 您有两种方法可以解决问题2:

  • Disable hashing in Liferay and let OpenDJ do the hashing. 在Liferay中禁用哈希,然后让OpenDJ进行哈希。
  • Allow pre-encoded passwords in LDAP and configure Liferay to pass the password value in binary format. 允许使用LDAP中的预编码密码,并将Liferay配置为以二进制格式传递密码值。 To allow pre-encoded passwords you just need to set the allow-pre-encoded-passwords advanced password policy property to true . 要允许预编码密码,您只需要将allow-pre-encoded-passwords高级密码策略属性设置为true即可 I am afraid I cannot help you with the Liferay configuration. 恐怕Liferay配置无法为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM