0

我正在尝试学习 ldap + spring 安全性。我已经使用 Apache DS 设置了本地开发人员。

我明白了它会编译和运行而不会出现错误,但是当我尝试登录时,它什么也没做,而且我没有任何错误消息可以通过。我什至无法判断 DS 是否收到了请求。

如果有人有关于调试这个的建议或者可以看到这个问题,那就太好了。

JSP:

<form action="/j_spring_security_check.action" method="POST">
    <span><label for="username">User Name:</label>
    <input id="username" name="j_username" type="text"/></span>
    <span><label for="password">Password:</label>
    <input id="password" name="j_password" type="password"/></span>
    <span><input type="submit" value="Log In"/></span>
</form>

应用上下文:

<bean id="contextSource"
          class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap://localhost:389/dc=example,dc=com"/>
        <property name="userDn" value="cn=system,dc=example,dc=com"/>
        <property name="password" value="password"/>
    </bean>

    <bean id="ldapAuthProvider"
          class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
        <constructor-arg>
            <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
                <constructor-arg ref="contextSource"/>
                <property name="userDnPatterns"><list><value>uid={0},ou=system</value></list></property>
            </bean>
        </constructor-arg>
        <constructor-arg>
            <bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
                <constructor-arg ref="contextSource"/>
                <constructor-arg value="ou=system"/>
                <property name="groupRoleAttribute" value="ou"/>
                <property name="defaultRole" value="ROLE_ADMIN"/>
            </bean>
        </constructor-arg>

    </bean>

弹簧安全:

<http auto-config="true" use-expressions="true">
        <intercept-url pattern="/noSecurityJSP/**" access="permitAll()"/>
        <intercept-url pattern="/login*" access="permitAll()"/>
        <intercept-url pattern="/resources/**" access="permitAll()"/>
        <intercept-url pattern="/**" access="isAuthenticated()"/>

        <form-login
                login-page="/login.htm"
                login-processing-url="/j_spring_security_check.action"
                authentication-failure-url="/splash_page.htm?error=true"
                default-target-url="/welcomePage.htm"
                always-use-default-target="true"/>
    </http>



    <authentication-manager>
        <authentication-provider ref='ldapAuthProvider'/>
    </authentication-manager>

Spring Maven 依赖项:

<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.2.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>3.0.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap-core</artifactId>
            <version>1.3.2.RELEASE</version>

LDAP 的图片 在此处输入图像描述

4

1 回答 1

3

您的问题似乎是“我该如何调试”。理想情况下,您应该提供一些关于“它什么都不做”的意思的更多信息,但是对于调试,Spring Security 的标准调试输出应该告诉您发生了什么,ApacheDS 还应该指出它是否接收到请求。两者都使用标准的 Java 日志记录机制。您可以使用Spring Security LDAP 示例中的 logback 配置文件作为示例(如果需要,您可以将其更改为 DEBUG 级别)。事实上,修改该示例以使用您的目录结构可能是一个好主意,首先确保您可以按原样运行它。

我总是建议在尝试部署应用程序之前为类似的东西编写一个测试类 - 请参阅常见问题解答以获取示例 - 你可以在你的 IDE 中调试它。

看起来确实是错误的一件事是您的 spring-security-ldap 版本与其他依赖项不同。您应该对所有 Spring Security 依赖项使用相同的 Maven 属性。并检查您的类路径(lib 目录)以确保它不包含任何具有不同版本的重复 jar。

如果您真的想知道发送到目录的内容,您可以使用类似tcpdump. 就像是:

sudo tcpdump -A -i lo0 tcp port 389

会将 TCP 流量记录到控制台的 389 端口。

您的构建配置似乎确实有问题的一件事是,您的spring-security-ldap依赖项版本与其他 spring-security jar 的版本不同。这些都应该是一样的。使用 maven 属性来防止这样的错误并检查您的类路径(lib 目录)以确保您没有任何重复的 jar 或不一致的版本。

于 2014-01-29T18:53:41.937 回答