Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Security LDAP身份验证:未指定OU时发生异常_Java_Spring_Spring Security_Ldap - Fatal编程技术网

Java Spring Security LDAP身份验证:未指定OU时发生异常

Java Spring Security LDAP身份验证:未指定OU时发生异常,java,spring,spring-security,ldap,Java,Spring,Spring Security,Ldap,我正在尝试使用LDAP和spring安全性进行身份验证。通过以下方式进行尝试: <security:ldap-server url="ldap://mydomain.de:389/dc=mydomain,dc=de" manager-dn="***" manager-password="***" /> <security:authentication-manager> <security:ldap-authentication-provid

我正在尝试使用LDAP和spring安全性进行身份验证。通过以下方式进行尝试:

<security:ldap-server
    url="ldap://mydomain.de:389/dc=mydomain,dc=de" manager-dn="***"
    manager-password="***" />

<security:authentication-manager>
    <security:ldap-authentication-provider
        user-search-filter="(&amp;(&amp;(objectCategory=person)(objectClass=user))(sAMAccountName={0}))">
    </security:ldap-authentication-provider>
</security:authentication-manager>
但当我将LDAP服务器url更改为:

"ldap://mydomain.de:389/OU=Users,OU=DE,dc=mydomain,dc=de" manager-dn="***"
它起作用了。这对我来说不是最好的解决方案,因为OU之外也有用户。 为什么我必须添加OU才能使其工作?是否有更好的方法包含所有用户(在根路径中)?
感谢您的帮助

这是因为您的Active Directory服务在不同的服务器中有多个林。当您向下指向OU时,结果集位于单个服务器中。
当您指向域时,服务器会返回一些条目,但也会返回一个指向您应该继续搜索的其他服务器的引用。

好的,所以今天我终于找到了解决方案:

如上所述,您必须定义一个ContextSourcebean。我的xml现在如下所示:

    <bean id="contextSource"
            class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap://mydomain.de:389/dc=mydomain,dc=de" />
        <property name="userDn" value="***" />
        <property name="password" value="***" />

        <property name="baseEnvironmentProperties">
            <map>
                <entry key="java.naming.referral">
                    <value>follow</value>
                </entry>
            </map>
        </property>
   </bean>

    <security:authentication-manager>
            <security:ldap-authentication-provider
                user-search-filter="sAMAccountName={0}" server-ref="contextSource" />
    </security:authentication-manager>

跟随
ContextSourcebean替换ldap服务器标记。 主要区别在于java.naming.referral的“follow”值,这会导致spring遵循AD@Ludovic Poitou was返回的服务器引用


希望这能帮助任何有同样问题的人。

您是否尝试过在没有上下文的情况下:ldap://mydomain.de:389" ?
    <bean id="contextSource"
            class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap://mydomain.de:389/dc=mydomain,dc=de" />
        <property name="userDn" value="***" />
        <property name="password" value="***" />

        <property name="baseEnvironmentProperties">
            <map>
                <entry key="java.naming.referral">
                    <value>follow</value>
                </entry>
            </map>
        </property>
   </bean>

    <security:authentication-manager>
            <security:ldap-authentication-provider
                user-search-filter="sAMAccountName={0}" server-ref="contextSource" />
    </security:authentication-manager>