2010-09-25 43 views
0

我的Spring MVC應用程序不允許任何登錄,我無法弄清楚爲什麼。爲什麼春季登錄表單不能顯示失敗登錄的任何錯誤信息?

我已經登錄到登錄控制器,但沒有輸出。

登錄頁面似乎自動重定向到錯誤頁面而無需通過登錄控制器。

任何想法如何調試此問題?

<http auto-config="false" access-decision-manager-ref="accessDecisionManager" use-expressions="true"> 
    <intercept-url pattern="/login/**" access="hasRole('ROLE_ANONYMOUS')" requires-channel="${application.secureChannel}" /> 
    <intercept-url pattern="/error/**" access="hasRole('ROLE_ANONYMOUS')" requires-channel="http" /> 
    <intercept-url pattern="/register/**" access="hasRole('ROLE_ANONYMOUS')" requires-channel="${application.secureChannel}" /> 
    <intercept-url pattern="/" access="hasRole('ROLE_ANONYMOUS')" requires-channel="http" /> 
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" requires-channel="http" /> 
    <form-login login-page="/login" login-processing-url="/login/submit" authentication-failure-url="/login/error" /> 
    <logout logout-url="/logout" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider user-service-ref="userDetailsService"> 
     <password-encoder hash="sha-256" base64="true"> 
      <salt-source user-property="salt" /> 
     </password-encoder> 
    </authentication-provider> 
</authentication-manager> 

<beans:bean id="userDetailsService" class="com.my.UserDetailsServiceImpl"> 
</beans:bean> 

<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"> 
    <beans:constructor-arg value="256" /> 
    <beans:property name="encodeHashAsBase64" value="true" /> 
</beans:bean> 

<beans:bean id="roleHierarchy" class="org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl"> 
    <beans:property name="hierarchy"> 
     <beans:value> 
      ROLE_ADMIN > ROLE_USER 
      ROLE_USER > ROLE_ANONYMOUS 
     </beans:value> 
    </beans:property> 
</beans:bean> 

<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased"> 
    <beans:property name="decisionVoters"> 
     <beans:list> 
      <beans:bean class="org.springframework.security.web.access.expression.WebExpressionVoter"> 
       <beans:property name="expressionHandler"> 
        <beans:bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"> 
         <beans:property name="roleHierarchy" ref="roleHierarchy" /> 
        </beans:bean> 
       </beans:property> 
      </beans:bean> 
     </beans:list> 
    </beans:property> 
</beans:bean> 
+0

嗯,這將在很大程度上取決於你如何在XML中配置的東西,你可以發佈的任何機會? – 2010-09-25 23:20:39

+0

是的。應該做到這一點。更新了問題。感謝您的提醒。 – Linc 2010-09-25 23:31:14

回答

1

我的Spring MVC應用程序不允許任何 登錄,我不知道爲什麼。

確保您在log4j.properties中添加了以下行以記錄與安全相關的異常。

log4j.logger.org.springframework.security = DEBUG 

如果您還沒有添加,那麼在此之後,您應該能夠在日誌文件中看到如下所示的內容(如下所示)。

Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials 

在要調試的情況下,把一個調試指針ExceptionTranslationFilter.java在下面的方法:

private void handleException(HttpServletRequest request, HttpServletResponse response, FilterChain chain, 
      RuntimeException exception) throws IOException, ServletException { 
     if (exception instanceof AuthenticationException) { 
      if (logger.isDebugEnabled()) { 
       logger.debug("Authentication exception occurred; redirecting to authentication entry point", exception); 
      } 

      sendStartAuthentication(request, response, chain, (AuthenticationException) exception); 
     } 

     .... 
    } 

我添加記錄到登錄 控制器,但什麼都沒有在那裏輸出 。

您的LoginController將不會被調用,直到成功驗證。

1

如果有,這是有用沒有春天與安全相關的日誌信息,下一步我會帶被設置斷點在org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpServletRequest, HttpServletResponse, FilterChain),並按照沿着小路。

1

如果沒有SpringSecurity日誌記錄,那麼你應該檢查日誌配置。我知道一個事實,如果你正確地配置日誌記錄,並將日誌級別設置爲DEBUG,你會得到豐富的日誌消息。

(如果你不能得到記錄,在所有的工作,直接輸出到System.err可能是一個選項...)

爲什麼一個春天登錄表單沒有透露登陸失敗的錯誤信息?

作爲一般規則,向最終用戶透露太多爲什麼他的登錄嘗試失敗對安全性不利。例如,如果您告訴用戶帳戶名稱錯誤或密碼錯誤,黑客可以分別攻擊這兩個憑據組件。