【问题标题】:Require authentication through https with spring security?需要通过带有spring security的https进行身份验证?
【发布时间】:2010-09-09 01:50:20
【问题描述】:

我使用的是 tomcat 6、spring mvc 3.0.0 和 spring security 3.0.0,由于我存储在数据库中的密码是 sha1 散列的,所以我不能使用摘要身份验证 (section 9.2.1 of the documentation spells that out)。因此,我需要通过 https 进行身份验证。

由于潜在的处理开销,我希望尽可能多地将流量保留在常规 http 中。有没有办法让spring对未经身份验证的请求使用https,然后在身份验证完成后使用http?我认为这是通过某种 ChannelProcessingFilter 完成的,但我对细节感到困惑。

这是我目前的 application-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>

感谢您的帮助。

【问题讨论】:

    标签: security authentication tomcat encryption cryptography


    【解决方案1】:

    如果您在任何时候通过 HTTP 传递会话 ID,则您违反了 OWASP A9。如果攻击者拥有会话 ID,则攻击者不需要密码。我不会在您的应用程序中实现此功能,https 的重量很轻,我认为您应该考虑在不意味着您的客户将被黑客入侵的地方节省资源。

    【讨论】:

      【解决方案2】:

      不确定如何使用 Spring MVC 来实现,但我确实使用带有 Spring Security 3 的 Grails 来实现这一点...如果您有兴趣,可以查看我的博文 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 了解更多信息以及如何配置 tomcats SSL 连接器。

      【讨论】:

        猜你喜欢
        • 2012-03-06
        • 2013-02-23
        • 2013-06-12
        • 1970-01-01
        • 2019-12-26
        • 1970-01-01
        • 2014-02-01
        • 2016-09-13
        • 1970-01-01
        相关资源
        最近更新 更多