2010-09-09 78 views
2

我使用tomcat 6,spring mvc 3.0.0和spring security 3.0.0,並且由於我在數據庫中存儲的密碼是sha1哈希值,因此我無法使用摘要式身份驗證(section 9.2.1 of the documentation spells that out)。出於這個原因,我需要通過https進行身份驗證。要求通過https驗證彈簧安全性嗎?

由於潛在的處理開銷,我希望儘可能多地保持常規http流量。有沒有一種方法可以讓spring使用https進行未經認證的請求,然後在認證完成後使用http?我認爲這是通過某種ChannelProcessingFilter完成的,但我很難理解這些細節。

這裏是我的應用程序security.xml文件,因爲它目前爲:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

    <http use-expressions="true"> 
     <intercept-url pattern="/**" access="isAuthenticated()" /> 
     <http-basic /> 
    </http> 

    <authentication-manager> 
     <authentication-provider user-service-ref="myUserDetailsService"> 
      <password-encoder hash="sha"/> 
     </authentication-provider> 
    </authentication-manager> 

    <beans:bean id="myUserDetailsService" 
     class="path.to.myUserDetailsServiceImpl"> 
    </beans:bean> 

</beans:beans> 

感謝您的幫助。

回答

6

如果您在任何時候通過HTTP傳遞會話標識,那麼您違反了OWASP A9。如果攻擊者擁有會話ID,則不需要密碼。我不會在你的應用程序中實現這個功能,https的重量非常輕,我認爲你應該考慮節省資源的地方,這並不意味着你的客戶將被黑客入侵。

3

不確定如何使用Spring MVC做到這一點,但我確實使用Grails和Spring Security 3完成了這項工作......如果您有興趣,您可以看看我的博客文章here

因爲不會真正幫助你......我做了一個快速谷歌搜索,發現this後看起來正確的,並說來配置你的web.xml:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext-security.xml 
    </param-value> 
</context-param> 

    <filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

和你的applicationContext-security.xml文件作爲這樣的:

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
         http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd"> 

    <http> 
     <intercept-url pattern="/url1.htm" 
     access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https" /> 
     <intercept-url pattern="/url2.htm" 
     access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https" /> 
     <intercept-url pattern="/**" 
     access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="http" /> 

     <anonymous /> 
     <http-basic/> 
    </http> 

    <!-- This bean is optional; it isn't used by any other bean as it only listens and logs --> 
    <beans:bean id="loggerListener" class="org.springframework.security.event.authentication.LoggerListener"/> 

</beans:beans> 

也看看這個site更多的信息,以及如何配置SSL雄貓連接器。