2014-01-24 203 views
0

我想學習ldap + spring安全性。我已經用Apache DS設置了本地開發。Spring Security + Ldap。無法調試

我已經到了它將編譯和運行沒有錯誤的地步,但是當我嘗試登錄時,它並沒有做任何事情,我也沒有任何錯誤消息可以通過。我甚至無法分辨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> 

彈簧secuirty:

<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> 

春天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

回答

2

你的問題似乎是「如何調試這個」。理想情況下,你應該提供一些關於「它什麼都不做」的意思的更多信息,但是對於調試,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依賴項,與其他彈簧安全罐相比,您有不同的版本。這些應該都是一樣的。使用maven屬性來防止這樣的錯誤,並檢查你的類路徑(lib目錄),以確保你沒有任何重複的jar或不一致的版本。

相關問題