【问题标题】:Spring Security + Ldap. Cannot debug弹簧安全 + Ldap。无法调试
【发布时间】:2014-02-15 23:33:46
【问题描述】:

我正在尝试学习 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 的图片

【问题讨论】:

    标签: java spring-security ldap apacheds


    【解决方案1】:

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

    我总是建议在尝试部署应用程序之前为这样的事情编写一个测试类 - 请参阅 FAQ 以获取示例 - 您可以在 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 或不一致的版本。

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 2020-06-22
      • 2014-07-21
      • 2016-10-06
      • 2012-06-15
      • 2023-01-03
      • 2018-09-08
      • 1970-01-01
      • 2013-04-12
      相关资源
      最近更新 更多