使用Jetty进行LDAP身份验证

时间:2014-01-16 11:18:22

标签: java authentication ldap jetty jaas

我正在尝试在Jetty上使用Jaas设置基于LDAP的身份验证。

我首先使用属性文件登录模块配置Jetty->Jass,然后在完成此操作后我将更改为基于Ldap的登录模块...但我有一个奇怪的问题:

我有这个配置

jettyLogin {
   org.eclipse.jetty.plus.jaas.spi.LdapLoginModule required
    debug="true"
    contextFactory="com.sun.jndi.ldap.LdapCtxFactory"
    hostname="localhost"
    port="1389"
    bindDn="uid=admin,ou=People,o=acme,dc=example,dc=com"
    bindPassword="admin"
    authenticationMethod="simple"
    forceBindingLogin="false"
    userBaseDn="ou=People,o=acme,dc=example,dc=com"
    userRdnAttribute="uid"
    userIdAttribute="uid"
    userPasswordAttribute="userPassword"
    userObjectClass="inetOrgPerson"
    roleBaseDn="ou=Roles,o=acme,dc=example,dc=com"
    roleNameAttribute="cn"
    roleMemberAttribute="member"
    roleObjectClass="groupOfNames";
   };

对于像这样的LDAP条目

dn: uid=jduke,ou=People,o=acme,dc=example,dc=com
objectclass: top
objectclass: inetOrgPerson
objectclass: person
uid: jduke
cn: Java
sn: Duke
userPassword: theduke
mail: jduke@acme.example.com

我看到的是LdapLoginModule被调用并搜索用户;找到用户但是当检索属性时,缺少userPassword属性(!!)...然后它保持为null并且身份验证失败。

我无法理解为什么没有检索userPassword属性。

1 个答案:

答案 0 :(得分:2)

登录模块不应尝试检索userPassword属性。 LDAP是一种身份验证协议,它有自己的方法来执行所谓的绑定。

如果正确配置,Jetty的JAAS模块将尝试使用提供的凭据执行绑定。如果你改变了

forceBindingLogin="false"

forceBindingLogin="true"

在您的配置中,它应该适合您。