使用openldap服务器进行java sasl身份验证

时间:2011-03-03 15:37:15

标签: java authentication openldap sasl unboundid-ldap-sdk

ldapwhoami -U portal -h yorktown -Y PLAIN -ZZ工作得很好时,有人能看出这个代码不起作用的原因吗?我正在做的事情是不是等同于什么?

LDAPConnection connection = new LDAPConnection();
connection.connect("yorktown.example.com", 389);
SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
SSLContext sslContext = sslUtil.createSSLContext();
ExtendedResult extendedResult = connection.processExtendedOperation(new StartTLSExtendedRequest(sslContext));
PLAINBindRequest bindRequest = new PLAINBindRequest("u:portal", "test");
BindResult bindResult = connection.bind(bindRequest);

此代码提供connection.bind调用抛出的以下异常:

play.exceptions.JavaExecutionException: SASL(-13): user not found: Password verification failed
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:285)
        at Invocation.HTTP Request(Play!)
Caused by: LDAPException(resultCode=49 (invalid credentials),
    errorMessage='SASL(-13): user not found: Password verification failed', 
    diagnosticMessage='SASL(-13): user not found: Password verification failed')
        at com.unboundid.ldap.sdk.LDAPConnection.bind(LDAPConnection.java:1710)

1 个答案:

答案 0 :(得分:0)

PLAINBindRequest的文档是错误的,或者OpenLDAP 2.4.23处理请求的方式有问题。服务器日志显示u:正在传递到服务器,从而产生uid=u:portal,dc=example,dc=com之类的DN。一旦我将其更改为new PLAINBindRequest("portal", "test"),就可以了。