我正在使用 Jetty 的 LDAP 登录模块 连接到内部 LDAP 服务器。 LDAPLoginModule 配置 (
ldap-loginModule.conf
) 提供如下:
ldap {
org.eclipse.jetty.jaas.spi.LdapLoginModule required
debug="true"
contextFactory="com.sun.jndi.ldap.LdapCtxFactory"
hostname="<ldap hostname>"
port="389"
bindDn="cn=admin,dc=myorg,dc=com"
bindPassword="password"
authenticationMethod="simple"
forceBindingLogin="true"
userBaseDn="ou=users,dc=myorg,dc=com"
userRdnAttribute="cn"
userIdAttribute="cn"
userPasswordAttribute="userPassword"
userObjectClass="inetOrgPerson";
};
当我使用 JVM 参数将上面的代码与我的应用程序集成时,它工作得很好:
-Djava.security.auth.login.config=./ldap-loginModule.conf
。正如您所理解的,上述 LDAP 配置会搜索 userBaseDN
中的 all用户(ou=users,dc=myorg,dc=com)。
但是,我正在使用上述配置搜索具有特定
role
(cn=my-group,ou=roles,dc=rsorg,dc=com
) 的用户。?我正在寻找一个解决方案,可以在上面的 JETTY LDAP 配置中复制下面的 ldap 搜索:
ldapsearch -x -H ldap://<ldap hostname>:636 -b "dc=myorg,dc=com" -D "cn=admin,dc=myorg,dc=com" -w password "(&(objectClass=inetOrgPerson)(memberOf=cn=my-group,ou=roles,dc=rsorg,dc=com))"
下面是配置,我已经尝试过,但没有得到正确的结果:
ldap {
org.eclipse.jetty.jaas.spi.LdapLoginModule required
debug="true"
contextFactory="com.sun.jndi.ldap.LdapCtxFactory"
hostname="<ldap hostname>"
port="389"
bindDn="cn=admin,dc=myorg,dc=com"
bindPassword="password"
authenticationMethod="simple"
forceBindingLogin="true"
userBaseDn="ou=users,dc=myorg,dc=com"
userRdnAttribute="cn"
userIdAttribute="cn"
userPasswordAttribute="userPassword"
userObjectClass="inetOrgPerson"
## Additional role check
roleBaseDn="cn=my-group,ou=roles,dc=myorg,dc=com"
roleNameAttribute="cn"
roleMemberAttribute="memberOf"
roleObjectClass="groupOfUniqueNames";
};
我正在使用 OpenLDAP 来配置 LDAP,并且该应用程序是 JAVA 应用程序。 感谢您的帮助。
对你来说不幸的是,Jetty 的模块源代码有一个硬编码的 ldap 过滤器:
String filter = "(&(objectClass={0})({1}={2}))";
其中
{1}
将替换为值 userIdAttribute
和 {2}
尝试登录的用户的用户名。
您可以通过在
userIdAttribute
参数中“注入”(如 SQL 注入)您的搜索查询来玩一些技巧。显然,有关参数滥用的常见警告适用于此。
我无法测试它,但我会尝试将
userIdAttribute
设置为这个值:
userIdAttribute="memberOf=cn=my-group,ou=roles,dc=rsorg,dc=com)(cn"
这样在运行时搜索就变成了(
{2}
仍然是用户名):
(&(objectClass={0})(memberOf=cn=my-group,ou=roles,dc=rsorg,dc=com)(cn={2}))
解释这里