簡體   English   中英

無法驗證Java - LDAP

[英]Unable to authenticate Java - LDAP

我的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

使用帶有十六進制編碼的MD5在門戶網站數據庫中對userPassword進行哈希處理。 還啟用了pre-encoded-password為true但沒有幫助。

上面的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);

    }

替換java程序中的userPassword總是會出現“無效的身份驗證異常”

隨附的是OpenDJ OPENDJ密碼策略的設置

我的要求是我們有一個門戶網站,其密碼存儲在MD5中的db中,並使用十六進制編碼將門戶網站集成到ldap,每次更改密碼,ldap使用散列值更新,但上述java程序根本不起作用。 需要認真幫助。

謝謝。

您需要以二進制格式存儲密碼哈希。 您可以使用“::”而不是“:”在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

在OpenDJ中,當您添加或導入密碼時,服務器將僅保留其密碼版本,為此,它使用密碼策略中為用戶配置的密碼存儲方案(或導入策略)。

但是,除非檢測到密碼已經使用已知方案進行了哈希處理,否則它始終會計算哈希值。 方案由{SSHA1}{MD5}等前綴標識。

由於您的用戶的密碼已經使用MD5進行了散列,並且OpenDJ具有使用MD5進行哈希處理的方案,因此您應確保用戶密碼與OpenDJ生成或期望的密碼具有相同的表示形式。

格式為:

userPassword:{MD5} Base64EncodingOftheMD5Hash

在LDIF中擁有此格式的所有用戶密碼后,您可以在OpenDJ中添加或導入它們,但請確保將密碼策略設置為接受預編碼密碼( allow-pre-encoded-passwords ),因為它不是默認allow-pre-encoded-passwords

您可以使用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