gpt4 book ai didi

java - LDAP 模板身份验证使用正确的密码返回 false

转载 作者:行者123 更新时间:2023-12-02 03:00:25 29 4
gpt4 key购买 nike

我正在使用 LdapTemplate 来使用 LDAP 身份验证,我能够在文件系统中成功找到用户,但身份验证方法返回 false 并认为我的密码错误。

我已经对其进行了调试,它成功找到了匹配的对象,但密码不匹配。

dn: dc=obssjobs,dc=com
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: obssjobs

# Organizational Units
dn: ou=groups,dc=obssjobs,dc=com
objectclass: top
objectclass: organizationalUnit
ou: groups

dn: ou=people,dc=obssjobs,dc=com
objectclass: top
objectclass: organizationalUnit
ou: people

# Create People
dn: uid=john,ou=people,dc=obssjobs,dc=com
objectclass: top
objectclass: hrexpert
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: John Doe
sn: John
uid: john
password: secret

dn: uid=jihn,ou=people,dc=obssjobs,dc=com
objectclass: top
objectclass: hrexpert
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Jihn Die
sn: Jihn
uid: jihn
password: secret

dn: uid=jahn,ou=people,dc=obssjobs,dc=com
objectclass: top
objectclass: hrexpert
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Jahn Dae
sn: Jahn
uid: jahn
password: 123

认证方式

public boolean authenticate(String username, String password) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "hrexpert")).and(new EqualsFilter("cn", username));
return ldapTemplate.authenticate(DistinguishedName.EMPTY_PATH, filter.toString(), password);
}

这是我在 main 中的测试,日志为“false”

@PostConstruct
public void setup(){
boolean authenticated=hrExpertService.authenticate("Jahn Dae", "123");
log.info("authenticated: " + authenticated);
}

最佳答案

请尝试下面的代码。对我有用:

    import com.novell.ldap.LDAPConnection;  //Import this 

private LDAPConnection lc = null;
private LDAPSocketFactory ssf; // If using secure ldap


try {

if(usingSecureldap){
prepEnv(getSsl_keystore_url, getSsl_keystore_pass);

if(ssf==null){
ssf = new LDAPJSSESecureSocketFactory();
}

lc = new LDAPConnection(ssf);

}else{ // If not using secure ldap

lc = new LDAPConnection();
}



lc.connect( <Ldap_ip>, <Ldap_port> );
lc.bind( LDAPConnection.LDAP_V3, <username>+suffix, <password>.getBytes("UTF8") );

return Boolean.TRUE;
}
catch (LDAPException e) {return Boolean.FALSE;}


private void prepEnv(String keystorePath, String keystorePass) {
System.setProperty(TRUSTSTORE_PROP_KEY, keystorePath);
System.setProperty(PWD_TRUSTSTORE_PROP_KEY, keystorePass);
}

关于java - LDAP 模板身份验证使用正确的密码返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57055041/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com