简体   繁体   English

无法验证Java - LDAP

[英]Unable to authenticate Java - LDAP

My ldiff file looks like this 我的ldiff文件看起来像这样

dn:uid=test,ou=users,dc=example,dc=com
objectclass:person
objectclass:inetOrgPerson
objectclass:organizationalPerson
objectclass:top
givenName: test
title:test
uid:test
cn:test
sn:sdf
userPassword: 81dc9bdb52d04dc20036dbd8313ed055
mail: test@yopmail.com
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
modifiersName: cn=Directory Manager,cn=Root DNs,cn=config

The userPassword is hashed in portal db using MD5 with hex encoding. 使用带有十六进制编码的MD5在门户网站数据库中对userPassword进行哈希处理。 Also enabled pre-encoded-password to true but doesnt help. 还启用了pre-encoded-password为true但没有帮助。

The plain text password for the above userPassword is "1234" and I have a sample java program to authenticate the same 上面的userPassword的纯文本密码是“1234”,我有一个示例java程序来验证相同的

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 = "81dc9bdb52d04dc20036dbd8313ed055;


        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);

    }

Replacing the userPassword in the java program always gives "Invalid Authentication Exception" 替换java程序中的userPassword总是会出现“无效的身份验证异常”

Attached is the setting of OpenDJ OPENDJ Passpword policy 随附的是OpenDJ OPENDJ密码策略的设置

My requirement is we have an portal whose passwords is stored in db in MD5 with hex encoding the portal is integrated to the ldap for every password change the ldap is updated with hashed value , but the above java program doesnt work at all . 我的要求是我们有一个门户网站,其密码存储在MD5中的db中,并使用十六进制编码将门户网站集成到ldap,每次更改密码,ldap使用散列值更新,但上述java程序根本不起作用。 Need serious help . 需要认真帮助。

Thanks. 谢谢。

You need to store the password hash in binary format. 您需要以二进制格式存储密码哈希。 You can do this in a LDIF file by using "::" instead of ":" to separate the attribute name from the value: 您可以使用“::”而不是“:”在LDIF文件中执行此操作,以将属性名称与值分隔:

dn:uid=test,ou=users,dc=example,dc=com
objectclass:person
objectclass:inetOrgPerson
objectclass:organizationalPerson
objectclass:top
givenName: test
title:test
uid:test
cn:test
sn:sdf
userPassword:: 81dc9bdb52d04dc20036dbd8313ed055
mail: test@yopmail.com
creatorsName: cn=Directory Manager,cn=Root DNs,cn=config
modifiersName: cn=Directory Manager,cn=Root DNs,cn=config

In OpenDJ, when you add or import a password, the server will only keep a hashed version of it, and for that, it uses the password storage scheme configured in the password policy for users (or the import policy). 在OpenDJ中,当您添加或导入密码时,服务器将仅保留其密码版本,为此,它使用密码策略中为用户配置的密码存储方案(或导入策略)。

However, it always computes the hash unless it detects that the password is already hashed with a known scheme. 但是,除非检测到密码已经使用已知方案进行了哈希处理,否则它始终会计算哈希值。 Schemes are identified by a prefix such as {SSHA1} or {MD5} . 方案由{SSHA1}{MD5}等前缀标识。

Since the password for your user is already hashed with MD5 and OpenDJ has a scheme that hashes with MD5, you should make sure that the user password has the same representation as what OpenDJ produces or expect. 由于您的用户的密码已经使用MD5进行了散列,并且OpenDJ具有使用MD5进行哈希处理的方案,因此您应确保用户密码与OpenDJ生成或期望的密码具有相同的表示形式。

The format is: 格式为:

userPassword: {MD5}Base64EncodingOftheMD5Hash userPassword:{MD5} Base64EncodingOftheMD5Hash

Once you have all user passwords with this format in LDIF, you can add or import them in OpenDJ, but make sure you set the password Policy to accept pre-encoded passwords ( allow-pre-encoded-passwords ) because it's not the default. 在LDIF中拥有此格式的所有用户密码后,您可以在OpenDJ中添加或导入它们,但请确保将密码策略设置为接受预编码密码( allow-pre-encoded-passwords ),因为它不是默认allow-pre-encoded-passwords

You can generate sample encoded values using OpenDJ encode-password tool: 您可以使用OpenDJ encode-password工具生成示例编码值:

$ encode-password -s MD5 -c password
Encoded Password:  "{MD5}X03MO1qnZdYdgyfeuILPmQ=="

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

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