java - Spring安全+LDAP。无法调试

标签 java spring-security ldap apacheds

我正在尝试学习 ldap + spring security。我已经使用 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>

Spring 安全:

<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图片 enter image description here

最佳答案

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

我总是建议在尝试部署应用程序之前编写一个类似的测试类 - 请参阅 FAQ例如 - 您可以在 IDE 中对其进行调试。

如果您确实想知道发送到目录的内容,您可以使用 tcpdump 等实用程序直接监控网络流量。像这样的东西:

sudo tcpdump -A -i lo0 tcp port 389

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

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

关于java - Spring安全+LDAP。无法调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21341729/

相关文章:

java - 使用 CompletableFuture 或 Future 对象获取 Callable 值

java - C# 中的 COBOL 到 Java 转换器

java - 使用 Spring Security 保护 Spring Cloud 功能

grails - LDAP:错误代码49-登录时无效的凭证

java - LDAP 的 JBoss 连接配置

java - 如何在java中格式化整数数组

java - 以一定角度移动实体?

java - 为什么我无法禁用 Spring Boot 自动生成的密码和用户?

java - Spring Security不通过Spring Session EnableRedisHttpSession重用身份验证数据

java - 如何通过基于 TLS 的 LDAP 对 Active Directory 进行身份验证?