为什么SpringLDAP /普通Java AD查询中的accountExpires和userAccountControl过滤器不能按预期工作?

时间:2017-11-16 14:25:32

标签: java spring-mvc active-directory jndi spring-ldap

我在基于Spring的webapp中使用SpringLDAP API来查询Windows Server 2012上托管的ActiveDirectory。以下是我的环境详细信息: - Java 1.8.0_101apache-tomcat-8.0.36SpringMVC 4.3.1& SpringLDAP 2.3.1

以下AD过滤器查询在基于Windows(基于C ++ / C#)的查询工具(例如,Lepide AD查询工具)中以及在eclipse IDE中的LDAP浏览器插件中获取匹配的帐户但未获取在Java(基于JNDI / SpringLDAP API)代码中使用时,匹配记录/ AD帐户也在基于Java的应用程序 JXplorer : -

(&(objectclass=user)(objectCategory=person)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(accountExpires>=131554368000000000)(userPrincipalName=cgm@*))

我尝试获取一个处于ACTIVE状态的用户帐户,但由于日期和userPrincipalName值以字符串cgm@开头,该帐户尚未过期。

以下是spring-servlet.xml文件中的ldap配置: -

<util:map id="ldapBaseEnvProps">
        <entry key="java.naming.ldap.attributes.binary" value="objectGUID"/>
</util:map>
<ldap:context-source id="pooledLdapContextSrc" url="ldap://dc.myadserver.com:3268" base="DC=myadserver,DC=com" username="CN=adusername,OU=Mkt-Managers,DC=myadserver,DC=com" password="*****" base-env-props-ref="ldapBaseEnvProps">
    <ldap:pooling max-total="16" max-active="16" max-idle="8" min-idle="0" max-wait="90000" when-exhausted="BLOCK" test-on-borrow="true" test-while-idle="true"/>
</ldap:context-source>

Java / SpringLDAP API是否支持这样的AD过滤器?如果是,需要更改上述AD查询过滤器才能在基于Java的代码中工作(获取匹配的AD帐户)?

1 个答案:

答案 0 :(得分:1)

我建议在Java中使用Spring LDAP的查询构建器对象来帮助您构建该查询。您的问题似乎表明您已将该查询从C(windows)环境复制到Java环境中。

我首先在Spring LDAP中使用.where()函数构建查询,并在此处查看是否会导致相同的错误: https://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/query/LdapQueryBuilder.html

相关问题