2010-09-09 80 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雄猫连接器。